diff --git a/tests/saml2_response.xml b/tests/saml2_response.xml new file mode 100644 index 0000000..1d38bd5 --- /dev/null +++ b/tests/saml2_response.xml @@ -0,0 +1,104 @@ + + + https://openidp.feide.no + + + + + https://openidp.feide.no + + + + + + + + + + + WUaqPW4nZ8uPyv+sf8qXsaKhHmk= + + + CRq1VvptjNHenZ5aWkyD6GqQX+XLgNiqElJnyLbMUgiwrFZ5J8IEGtC8h2YiwID15ScxVt6tjQc8R3gXkP967PIlemmhYQ4US7V3oPczu4MECamj+07wAg7BCp05UVU3RI3pvi/2dQGRRX4tlXgkzUMzx8+cBeyZaI/BXKjhKEY= + + + MIICizCCAfQCCQCY8tKaMc0BMjANBgkqhkiG9w0BAQUFADCBiTELMAkGA1UEBhMCTk8xEjAQBgNVBAgTCVRyb25kaGVpbTEQMA4GA1UEChMHVU5JTkVUVDEOMAwGA1UECxMFRmVpZGUxGTAXBgNVBAMTEG9wZW5pZHAuZmVpZGUubm8xKTAnBgkqhkiG9w0BCQEWGmFuZHJlYXMuc29sYmVyZ0B1bmluZXR0Lm5vMB4XDTA4MDUwODA5MjI0OFoXDTM1MDkyMzA5MjI0OFowgYkxCzAJBgNVBAYTAk5PMRIwEAYDVQQIEwlUcm9uZGhlaW0xEDAOBgNVBAoTB1VOSU5FVFQxDjAMBgNVBAsTBUZlaWRlMRkwFwYDVQQDExBvcGVuaWRwLmZlaWRlLm5vMSkwJwYJKoZIhvcNAQkBFhphbmRyZWFzLnNvbGJlcmdAdW5pbmV0dC5ubzCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAt8jLoqI1VTlxAZ2axiDIThWcAOXdu8KkVUWaN/SooO9O0QQ7KRUjSGKN9JK65AFRDXQkWPAu4HlnO4noYlFSLnYyDxI66LCr71x4lgFJjqLeAvB/GqBqFfIZ3YK/NrhnUqFwZu63nLrZjcUZxNaPjOOSRSDaXpv1kb5k3jOiSGECAwEAATANBgkqhkiG9w0BAQUFAAOBgQBQYj4cAafWaYfjBU2zi1ElwStIaJ5nyp/s/8B8SAPK2T79McMyccP3wSW13LHkmM1jwKe3ACFXBvqGQN0IbcH49hu0FKhYFM/GPDJcIHFBsiyMBXChpye9vBaTNEBCtU3KjjyG0hRT2mAQ9h+bkPmOvlEo/aH0xR68Z9hw4PF13w== + + + + + _242f88493449e639aab95dd9b92b1d04234ab84fd8 + + + + + + + urn:mace:feide.no:services:no.feide.foodle + + + + + urn:oasis:names:tc:SAML:2.0:ac:classes:Password + + + + + Andreas Solberg + + + Solberg + + + andreas + + + employee + + + urn:mace:feide.no:entitlement:test + + + erlang + + + andreas@rnd.feide.no + + + andreas@uninett.no + + + +4741107700 + + + Feide RnD + + + Guests + + + + diff --git a/tests/saml_response.xml b/tests/saml_response.xml new file mode 100644 index 0000000..a3fc5c8 --- /dev/null +++ b/tests/saml_response.xml @@ -0,0 +1,93 @@ + + + http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php + + + + + http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php + + + + + + + + + + + YvszukkIXQKLz+1Tj7ggGR/C8DY= + + + + TcZMidcV0FL+47zQSNO67k1vJyuYSyqalcFb596G6k4kYvU/5RN4plYjkUTeraKtAWoD+ZKGay/hTorg4MGFtIr6fuq5/dtAJ+kk6dUH7nuRHfj7CxXsM9w4e75HSJAHfT8XHb5CrUSo+rr9syGLprXt6GoSTQBZHjDweeqjOHc= + + + + + MIICgTCCAeoCCQCbOlrWDdX7FTANBgkqhkiG9w0BAQUFADCBhDE +LMAkGA1UEBhMCTk8xGDAWBgNVBAgTD0FuZHJlYXMgU29sYmVyZzEMMAoGA1UEBxMDRm9vMRAwDgYDVQQKEwdVTklORVRUMRgwFgYDVQQDEw9mZWlk +ZS5lcmxhbmcubm8xITAfBgkqhkiG9w0BCQEWEmFuZHJlYXNAdW5pbmV0dC5ubzAeFw0wNzA2MTUxMjAxMzVaFw0wNzA4MTQxMjAxMzVaMIGEMQswC +QYDVQQGEwJOTzEYMBYGA1UECBMPQW5kcmVhcyBTb2xiZXJnMQwwCgYDVQQHEwNGb28xEDAOBgNVBAoTB1VOSU5FVFQxGDAWBgNVBAMTD2ZlaWRlLm +VybGFuZy5ubzEhMB8GCSqGSIb3DQEJARYSYW5kcmVhc0B1bmluZXR0Lm5vMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDivbhR7P516x/S3Bq +KxupQe0LONoliupiBOesCO3SHbDrl3+q9IbfnfmE04rNuMcPsIxB161TdDpIesLCn7c8aPHISKOtPlAeTZSnb8QAu7aRjZq3+PbrP5uW3TcfCGPtK +TytHOge/OlJbo078dVhXQ14d1EDwXJW1rRXuUt4C8QIDAQABMA0GCSqGSIb3DQEBBQUAA4GBACDVfp86HObqY+e8BUoWQ9+VMQx1ASDohBjwOsg2W +ykUqRXF+dLfcUH9dWR63CtZIKFDbStNomPnQz7nbK+onygwBspVEbnHuUihZq3ZUdmumQqCw4Uvs/1Uvq3orOo/WJVhTyvLgFVK2QarQ4/67OZfHd +7R+POBXhophSMv1ZOo + + + + + + + _cddc88563d433f556d4cc70c3162deabddea3b5019 + + + + + + + + xenosmilus.umdc.umu.se + + + + + urn:oasis:names:tc:SAML:2.0:ac:classes:Password + + + + + + student + + + + + member + + + student + + + + + \ No newline at end of file diff --git a/tests/test_client.py b/tests/test_client.py new file mode 100644 index 0000000..16eef53 --- /dev/null +++ b/tests/test_client.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python + +from saml2.client import Saml2Client +from saml2 import samlp + +XML_RESPONSE_FILE = "saml_response.xml" +XML_RESPONSE_FILE2 = "saml2_response.xml" +#XML_RESPONSE_FILE3 = "sun_saml2_response.xml" + +def for_me(condition, me ): + for restriction in condition.audience_restriction: + audience = restriction.audience + if audience.text.strip() == me: + return True + +def ava(attribute_statement): + result = {} + for attribute in attribute_statement.attribute: + # Check name_format ?? + name = attribute.name.strip() + result[name] = [] + for value in attribute.attribute_value: + result[name].append(value.text.strip()) + return result + +def test_verify_1(): + xml_response = open(XML_RESPONSE_FILE).read() + client = Saml2Client({}) + (ava, came_from) = \ + client.verify(xml_response, "xenosmilus.umdc.umu.se",decode=False) + assert ava == {'__userid': '_cddc88563d433f556d4cc70c3162deabddea3b5019', + 'eduPersonAffiliation': ['member', 'student'], + 'uid': ['student']} + +def test_parse_1(): + xml_response = open(XML_RESPONSE_FILE).read() + response = samlp.response_from_string(xml_response) + client = Saml2Client({}) + (ava, name_id, real_uri) = \ + client.do_response(response, "xenosmilus.umdc.umu.se") + assert ava == {'eduPersonAffiliation': ['member', 'student'], 'uid': ['student']} + assert name_id == "_cddc88563d433f556d4cc70c3162deabddea3b5019" + +def test_parse_2(): + xml_response = open(XML_RESPONSE_FILE2).read() + response = samlp.response_from_string(xml_response) + client = Saml2Client({}) + (ava, name_id, real_uri) = \ + client.do_response(response, "xenosmilus.umdc.umu.se") + assert ava == {'uid': ['andreas'], + 'mobile': ['+4741107700'], + 'edupersonnickname': ['erlang'], + 'o': ['Feide RnD'], + 'edupersonentitlement': ['urn:mace:feide.no:entitlement:test'], + 'edupersonaffiliation': ['employee'], + 'eduPersonPrincipalName': ['andreas@rnd.feide.no'], + 'sn': ['Solberg'], + 'mail': ['andreas@uninett.no'], + 'ou': ['Guests'], + 'cn': ['Andreas Solberg']} + assert name_id == "_242f88493449e639aab95dd9b92b1d04234ab84fd8" + +# def test_parse_3(): +# xml_response = open(XML_RESPONSE_FILE3).read() +# response = samlp.response_from_string(xml_response) +# client = Saml2Client({}) +# (ava, name_id, real_uri) = \ +# client.do_response(response, "xenosmilus.umdc.umu.se") +# print 40*"=" +# print ava +# print 40*"," +# print name_id +# assert False \ No newline at end of file