Skip to content

Commit 5eed220

Browse files
author
Roland Hedberg
committed
Updated tests to working with separate signature verifications of response and assertions.
1 parent 7e52def commit 5eed220

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

tests/saml_false_signed.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<ns0:Response xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol" Destination="http://xenosmilus.umdc.umu.se:8087/login" ID="_5271694c3be6883137377fb076355c4bc97f28b3c1" InResponseTo="bahigehogffohiphlfmplepdpcohkhhmheppcdie" IssueInstant="2009-10-25T18:12:39Z" Version="2.0">
3-
<ns1:Issuer xmlns:ns1="urn:oasis:names:tc:SAML:2.0:assertion">http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php</ns1:Issuer>
2+
<ns0:Response xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol" Destination="http://lingon.catalogix.se:8087/" ID="_5271694c3be6883137377fb076355c4bc97f28b3c1" InResponseTo="bahigehogffohiphlfmplepdpcohkhhmheppcdie" IssueInstant="2014-05-04T09:59:39Z" Version="2.0">
3+
<ns1:Issuer xmlns:ns1="urn:oasis:names:tc:SAML:2.0:assertion">urn:mace:example.com:saml:roland:idp</ns1:Issuer>
44
<ns0:Status>
55
<ns0:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
66
</ns0:Status>
7-
<ns1:Assertion xmlns:ns1="urn:oasis:names:tc:SAML:2.0:assertion" ID="pfx9e022535-4b38-cc7f-41ec-9a01bcd2936d" IssueInstant="2009-10-25T18:12:39Z" Version="2.0">
8-
<ns1:Issuer>http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php</ns1:Issuer>
7+
<ns1:Assertion xmlns:ns1="urn:oasis:names:tc:SAML:2.0:assertion" ID="pfx9e022535-4b38-cc7f-41ec-9a01bcd2936d" IssueInstant="2014-05-04T09:59:39Z" Version="2.0">
8+
<ns1:Issuer>urn:mace:example.com:saml:roland:idp</ns1:Issuer>
99
<ns2:Signature xmlns:ns2="http://www.w3.org/2000/09/xmldsig#">
1010
<ns2:SignedInfo>
1111
<ns2:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
@@ -49,15 +49,15 @@ OmuMZY0K6ERY4fNVnGEAoUZeieehC6/ljmfk14xCAlE=</ns2:SignatureValue>
4949
_cddc88563d433f556d4cc70c3162deabddea3b5019
5050
</ns1:NameID>
5151
<ns1:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
52-
<ns1:SubjectConfirmationData InResponseTo="bahigehogffohiphlfmplepdpcohkhhmheppcdie" NotOnOrAfter="2009-10-25T18:17:39Z" Recipient="http://xenosmilus.umdc.umu.se:8087/login"/>
52+
<ns1:SubjectConfirmationData InResponseTo="bahigehogffohiphlfmplepdpcohkhhmheppcdie" NotOnOrAfter="2014-05-04T09:59:39Z" Recipient="http://xenosmilus.umdc.umu.se:8087/login"/>
5353
</ns1:SubjectConfirmation>
5454
</ns1:Subject>
55-
<ns1:Conditions NotBefore="2009-10-25T18:12:09Z" NotOnOrAfter="2009-10-26T02:12:39Z">
55+
<ns1:Conditions NotBefore="2014-05-04T09:59:39Z" NotOnOrAfter="2024-05-04T09:59:39Z">
5656
<ns1:AudienceRestriction>
57-
<ns1:Audience>xenosmilus.umdc.umu.se</ns1:Audience>
57+
<ns1:Audience>urn:mace:example.com:saml:roland:sp</ns1:Audience>
5858
</ns1:AudienceRestriction>
5959
</ns1:Conditions>
60-
<ns1:AuthnStatement AuthnInstant="2009-10-25T18:12:39Z" SessionIndex="_788db107b9bb1b6ab94f00deebbfe3d92c999b3041">
60+
<ns1:AuthnStatement AuthnInstant="2014-05-04T09:59:39Z" SessionIndex="_788db107b9bb1b6ab94f00deebbfe3d92c999b3041">
6161
<ns1:AuthnContext>
6262
<ns1:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</ns1:AuthnContextClassRef>
6363
</ns1:AuthnContext>

tests/test_40_sigver.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
SIGNED = full_path("saml_signed.xml")
2121
UNSIGNED = full_path("saml_unsigned.xml")
22-
FALSE_SIGNED = full_path("saml_false_signed.xml")
2322
SIMPLE_SAML_PHP_RESPONSE = full_path("simplesamlphp_authnresponse.xml")
2423

2524
PUB_KEY = full_path("test.pem")
@@ -143,11 +142,6 @@ def test_non_verify_1(self):
143142
response = self.sec.correctly_signed_response(xml_response)
144143
assert response
145144

146-
def test_non_verify_2(self):
147-
xml_response = open(FALSE_SIGNED).read()
148-
raises(sigver.SignatureError, self.sec.correctly_signed_response,
149-
xml_response)
150-
151145
def test_sign_assertion(self):
152146
ass = self._assertion
153147
print ass
@@ -478,7 +472,6 @@ def test_xbox():
478472

479473

480474
if __name__ == "__main__":
481-
#t = TestSecurity()
482-
#t.setup_class()
483-
#t.test_sign_then_encrypt_assertion()
484-
test_xbox()
475+
t = TestSecurity()
476+
t.setup_class()
477+
t.test_non_verify_2()

tests/test_41_response.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
from saml2.response import response_factory
99
from saml2.response import StatusResponse
1010
from saml2.response import AuthnResponse
11-
from saml2.sigver import security_context
11+
from saml2.sigver import security_context, SignatureError
1212
from saml2.sigver import MissingKey
1313

1414
from pytest import raises
1515

16-
XML_RESPONSE_FILE = "saml_signed.xml"
17-
XML_RESPONSE_FILE2 = "saml2_response.xml"
16+
FALSE_ASSERT_SIGNED = "saml_false_signed.xml"
1817

1918

2019
def _eq(l1, l2):
@@ -91,8 +90,26 @@ def test_2(self):
9190
assert isinstance(resp, StatusResponse)
9291
assert isinstance(resp, AuthnResponse)
9392

93+
def test_false_sign(self):
94+
xml_response = open(FALSE_ASSERT_SIGNED).read()
95+
resp = response_factory(
96+
xml_response, self.conf,
97+
return_addrs=["http://lingon.catalogix.se:8087/"],
98+
outstanding_queries={
99+
"bahigehogffohiphlfmplepdpcohkhhmheppcdie":
100+
"http://localhost:8088/sso"},
101+
timeslack=10000, decode=False)
102+
103+
assert isinstance(resp, StatusResponse)
104+
assert isinstance(resp, AuthnResponse)
105+
try:
106+
resp.verify()
107+
except SignatureError:
108+
pass
109+
else:
110+
assert False
94111

95112
if __name__ == "__main__":
96113
t = TestResponse()
97114
t.setup_class()
98-
t.test_1()
115+
t.test_false_sign()

tests/test_44_authnresp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,7 @@ def test_verify_w_authn(self):
125125
session_info = self.ar.session_info()
126126
assert session_info["authn_info"] == authn_info
127127

128+
if __name__ == "__main__":
129+
t = TestAuthnResponse()
130+
t.setup_class()
131+
t.test_verify_1()

0 commit comments

Comments
 (0)