Merge branch 'issue-86'

This commit is contained in:
Benjamin Dauvergne 2010-06-29 09:15:00 +00:00
parent d9d4e6ae38
commit 6f617027e9
4 changed files with 158 additions and 1 deletions

View File

@ -401,15 +401,32 @@ class AttributeAuthorityTestCase(unittest.TestCase):
assert aq.response.assertion[0].attributeStatement[0].attribute[0]
assert aq.response.assertion[0].attributeStatement[0].attribute[0].attributeValue[0]
class LogoutTestCase(unittest.TestCase):
def test01(self):
'''Test parsing of a logout request with more than one session index'''
content = '''<samlp:LogoutRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="xxxx" Version="2.0" IssueInstant="2010-06-14T22:00:00">
<samlp:Issuer>me</samlp:Issuer>
<samlp:SessionIndex>id1</samlp:SessionIndex>
<samlp:SessionIndex>id2</samlp:SessionIndex>
<samlp:SessionIndex>id3</samlp:SessionIndex>
</samlp:LogoutRequest>'''
node = lasso.Samlp2LogoutRequest.newFromXmlNode(content)
assert isinstance(node, lasso.Samlp2LogoutRequest)
print node.sessionIndex
assert node.sessionIndex == 'id3'
assert node.sessionIndexes == ('id1', 'id2', 'id3')
serverSuite = unittest.makeSuite(ServerTestCase, 'test')
loginSuite = unittest.makeSuite(LoginTestCase, 'test')
logoutSuite = unittest.makeSuite(LogoutTestCase, 'test')
defederationSuite = unittest.makeSuite(DefederationTestCase, 'test')
identitySuite = unittest.makeSuite(IdentityTestCase, 'test')
attributeSuite = unittest.makeSuite(AttributeAuthorityTestCase, 'test')
logoutSuite = unittest.makeSuite(LogoutTestCase, 'test')
allTests = unittest.TestSuite((serverSuite, loginSuite, logoutSuite, defederationSuite,
identitySuite, attributeSuite))
identitySuite, attributeSuite, logoutSuite))
if __name__ == '__main__':
sys.exit(not unittest.TextTestRunner(verbosity = 2).run(allTests).wasSuccessful())

View File

@ -3402,6 +3402,8 @@ LASSO_SAMLP2_NAME_ID_MAPPING_REQUEST_GET_CLASS
<TITLE>LassoSamlp2LogoutRequest</TITLE>
LassoSamlp2LogoutRequest
lasso_samlp2_logout_request_new
lasso_samlp2_logout_request_get_session_indexes
lasso_samlp2_logout_request_set_session_indexes
<SUBSECTION Standard>
LASSO_SAMLP2_LOGOUT_REQUEST
LASSO_IS_SAMLP2_LOGOUT_REQUEST

View File

@ -23,7 +23,10 @@
*/
#include "../private.h"
#include "../../utils.h"
#include "samlp2_logout_request.h"
#include <libxml/tree.h>
#include <xmlsec/xmltree.h>
/**
* SECTION:samlp2_logout_request
@ -52,6 +55,12 @@
* </figure>
*/
typedef struct _LassoSamlp2LogoutRequestPrivate LassoSamlp2LogoutRequestPrivate;
struct _LassoSamlp2LogoutRequestPrivate {
GList *SessionIndex;
};
/*****************************************************************************/
/* private methods */
/*****************************************************************************/
@ -76,11 +85,76 @@ static struct XmlSnippet schema_snippets[] = {
static LassoNodeClass *parent_class = NULL;
#define SESSION_INDEX "SessionIndex"
#define GET_PRIVATE(x) G_TYPE_INSTANCE_GET_PRIVATE(x, \
LASSO_TYPE_SAMLP2_LOGOUT_REQUEST, LassoSamlp2LogoutRequestPrivate)
/*****************************************************************************/
/* instance and class init functions */
/*****************************************************************************/
static xmlNode*
get_xmlNode(LassoNode *node, gboolean lasso_dump)
{
xmlNode *xmlnode;
GList *other_session_index, *it;
char *keep_session_index;
other_session_index = lasso_samlp2_logout_request_get_session_indexes((LassoSamlp2LogoutRequest*)node);
/* save SessionIndex simple field, and nullify it */
keep_session_index = ((LassoSamlp2LogoutRequest*)node)->SessionIndex;
((LassoSamlp2LogoutRequest*)node)->SessionIndex = NULL;
xmlnode = parent_class->get_xmlNode(node, lasso_dump);
lasso_foreach(it, other_session_index) {
xmlNode *child = xmlSecAddChild(xmlnode, BAD_CAST SESSION_INDEX,
BAD_CAST LASSO_SAML2_PROTOCOL_HREF);
#if (XMLSEC_MAJOR > 1) || (XMLSEC_MAJOR == 1 && XMLSEC_MINOR > 2) || (XMLSEC_MAJOR == 1 && XMLSEC_MINOR == 2 && XMLSEC_SUBMINOR > 12)
xmlSecNodeEncodeAndSetContent(child, BAD_CAST it->data);
#else
xmlChar *content;
content = xmlEncodeSpecialChars(child->doc, BAD_CAST it->data);
xmlNodeSetContent(child, content);
xmlFree(content);
#endif
}
((LassoSamlp2LogoutRequest*)node)->SessionIndex = keep_session_index;
return xmlnode;
}
static int
init_from_xml(LassoNode *node, xmlNode *xmlnode)
{
int rc = 0;
xmlNode *child = NULL;
LassoSamlp2LogoutRequestPrivate *pv = NULL;
rc = parent_class->init_from_xml(node, xmlnode);
if (rc == 0) {
GList *last;
pv = GET_PRIVATE(node);
child = xmlSecFindChild(xmlnode, BAD_CAST SESSION_INDEX,
BAD_CAST LASSO_SAML2_PROTOCOL_HREF);
while (child && xmlSecCheckNodeName(child, BAD_CAST SESSION_INDEX,
BAD_CAST LASSO_SAML2_PROTOCOL_HREF)) {
xmlChar *content = xmlNodeGetContent(child);
lasso_list_add_string(pv->SessionIndex, (char*) content);
lasso_release_xml_string(content);
child = xmlSecGetNextElementNode(child->next);
}
/* remove the last one, since it is also stored in node->SessionIndex */
last = g_list_last(pv->SessionIndex);
if (last) {
lasso_release_string(last->data);
pv->SessionIndex = g_list_delete_link(pv->SessionIndex, last);
}
}
return rc;
}
static void
class_init(LassoSamlp2LogoutRequestClass *klass)
{
@ -88,9 +162,12 @@ class_init(LassoSamlp2LogoutRequestClass *klass)
parent_class = g_type_class_peek_parent(klass);
nclass->node_data = g_new0(LassoNodeClassData, 1);
klass->parent.parent.init_from_xml = init_from_xml;
klass->parent.parent.get_xmlNode = get_xmlNode;
lasso_node_class_set_nodename(nclass, "LogoutRequest");
lasso_node_class_set_ns(nclass, LASSO_SAML2_PROTOCOL_HREF, LASSO_SAML2_PROTOCOL_PREFIX);
lasso_node_class_add_snippets(nclass, schema_snippets);
g_type_class_add_private(G_OBJECT_CLASS(klass), sizeof(LassoSamlp2LogoutRequestPrivate));
}
GType
@ -118,6 +195,61 @@ lasso_samlp2_logout_request_get_type()
return this_type;
}
/**
* lasso_samlp2_logout_request_get_session_indexes:
* @logout_request: a #LogoutRequest object
*
* If the logout request contains more than one SessionIndex element, this method must be used to
* retrieve due to historical circonstances. It will a return a list of the content of the
* SessionIndex elements.
*
* Return value:(element-type utf8)(transfer full): a #GList of sessions index.
*/
GList*
lasso_samlp2_logout_request_get_session_indexes(LassoSamlp2LogoutRequest *logout_request)
{
GList *ret = NULL;
LassoSamlp2LogoutRequestPrivate *pv = NULL;
g_return_val_if_fail(LASSO_IS_SAMLP2_LOGOUT_REQUEST(logout_request), NULL);
/* Return concatenation of old field + new private field */
pv = GET_PRIVATE(logout_request);
lasso_assign_list_of_strings(ret, pv->SessionIndex);
if (logout_request->SessionIndex) {
ret = g_list_append(ret, g_strdup(logout_request->SessionIndex));
}
return ret;
}
/**
* lasso_samlp2_logout_request_set_session_indexes:
* @logout_request: a #LogoutRequest object
* @session_index:(element-type utf8): a list of session index
*
* If you want to set more than one SessionIndex on a LogoutRequest, use this method. Beware that
* the public field named SessionIndex corresponds to the last element in this list. This is an
* symptom of the way elements are parsed by Lasso.
*
*/
void
lasso_samlp2_logout_request_set_session_indexes(LassoSamlp2LogoutRequest *logout_request,
GList *session_index)
{
LassoSamlp2LogoutRequestPrivate *pv;
g_return_if_fail(LASSO_IS_SAMLP2_LOGOUT_REQUEST(logout_request));
/* assign rest of the list to the new private field */
pv = GET_PRIVATE(logout_request);
lasso_assign_list_of_strings(pv->SessionIndex, session_index);
/* extract last element and assign it to old field */
if (pv->SessionIndex && pv->SessionIndex->next) {
GList *last = g_list_last(pv->SessionIndex);
lasso_assign_new_string(logout_request->SessionIndex, (char*) last->data);
pv->SessionIndex = g_list_remove_link(pv->SessionIndex, last);
}
}
/**
* lasso_samlp2_logout_request_new:
*

View File

@ -78,9 +78,15 @@ struct _LassoSamlp2LogoutRequestClass {
};
LASSO_EXPORT GType lasso_samlp2_logout_request_get_type(void);
LASSO_EXPORT LassoNode* lasso_samlp2_logout_request_new(void);
LASSO_EXPORT GList* lasso_samlp2_logout_request_get_session_indexes(
LassoSamlp2LogoutRequest *logout_request);
LASSO_EXPORT void lasso_samlp2_logout_request_set_session_indexes(
LassoSamlp2LogoutRequest *logout_request,
GList *session_index);
#ifdef __cplusplus
}