Skip to content

Commit 8dcb31b

Browse files
committed
Strengthen XSW tests
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
1 parent aaf6c54 commit 8dcb31b

File tree

6 files changed

+81
-14
lines changed

6 files changed

+81
-14
lines changed

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include LICENSE
33
include README.rst
44
include CHANGELOG.md
55

6-
include src/saml2/xml_template/template.xml
6+
include src/saml2/data/templates/*.xml
77

88
graft docs
99
prune docs/build

tests/saml2_response_xsw.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/test_xsw.py

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,72 @@
1414
from pathutils import full_path
1515

1616

17-
XML_RESPONSE_XSW = full_path("saml2_response_xsw.xml")
17+
SIGNED_XSW_ASSERTION_WRAPPER = full_path("xsw/signed-xsw-assertion-wrapper.xml")
18+
SIGNED_XSW_ASSERTION_EXTENSIONS = full_path("xsw/signed-xsw-assertion-extensions.xml")
19+
SIGNED_XSW_ASSERTION_ASSERTION = full_path("xsw/signed-xsw-assertion-assertion.xml")
1820

1921

20-
class TestAuthnResponse:
22+
23+
class TestXSW:
2124
def setup_class(self):
2225
self.conf = config_factory("sp", dotname("server_conf"))
23-
self.ar = authn_response(self.conf, "http://lingon.catalogix.se:8087/")
26+
self.ar = authn_response(self.conf, return_addrs="https://example.org/acs/post")
27+
28+
@patch('saml2.response.validate_on_or_after', return_value=True)
29+
def test_signed_xsw_assertion_wrapper_should_fail(self, mock_validate_on_or_after):
30+
self.ar.issue_instant_ok = Mock(return_value=True)
31+
32+
with open(SIGNED_XSW_ASSERTION_WRAPPER) as fp:
33+
xml_response = fp.read()
34+
35+
self.ar.outstanding_queries = {"id-abc": "http://localhost:8088/sso"}
36+
self.ar.timeslack = 10000
37+
self.ar.loads(xml_response, decode=False)
38+
39+
assert self.ar.came_from == 'http://localhost:8088/sso'
40+
assert self.ar.session_id() == "id-abc"
41+
assert self.ar.issuer() == 'urn:mace:example.com:saml:roland:idp'
42+
43+
with raises(SignatureError):
44+
self.ar.verify()
45+
46+
assert self.ar.ava is None
47+
assert self.ar.name_id is None
48+
49+
@patch('saml2.response.validate_on_or_after', return_value=True)
50+
def test_signed_xsw_assertion_extensions_should_fail(self, mock_validate_on_or_after):
51+
self.ar.issue_instant_ok = Mock(return_value=True)
52+
53+
with open(SIGNED_XSW_ASSERTION_EXTENSIONS) as fp:
54+
xml_response = fp.read()
55+
56+
self.ar.outstanding_queries = {"id-abc": "http://localhost:8088/sso"}
57+
self.ar.timeslack = 10000
58+
self.ar.loads(xml_response, decode=False)
59+
60+
assert self.ar.came_from == 'http://localhost:8088/sso'
61+
assert self.ar.session_id() == "id-abc"
62+
assert self.ar.issuer() == 'urn:mace:example.com:saml:roland:idp'
63+
64+
with raises(SignatureError):
65+
self.ar.verify()
66+
67+
assert self.ar.ava is None
68+
assert self.ar.name_id is None
2469

2570
@patch('saml2.response.validate_on_or_after', return_value=True)
26-
def test_verify_signed_xsw(self, mock_validate_on_or_after):
71+
def test_signed_xsw_assertion_assertion_should_fail(self, mock_validate_on_or_after):
2772
self.ar.issue_instant_ok = Mock(return_value=True)
2873

29-
with open(XML_RESPONSE_XSW) as fp:
74+
with open(SIGNED_XSW_ASSERTION_ASSERTION) as fp:
3075
xml_response = fp.read()
3176

32-
self.ar.outstanding_queries = {"id12": "http://localhost:8088/sso"}
77+
self.ar.outstanding_queries = {"id-abc": "http://localhost:8088/sso"}
3378
self.ar.timeslack = 10000
3479
self.ar.loads(xml_response, decode=False)
3580

3681
assert self.ar.came_from == 'http://localhost:8088/sso'
37-
assert self.ar.session_id() == "id12"
82+
assert self.ar.session_id() == "id-abc"
3883
assert self.ar.issuer() == 'urn:mace:example.com:saml:roland:idp'
3984

4085
with raises(SignatureError):
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0" ID="the-response" IssueInstant="2020-12-04T07:48:09.700Z" InResponseTo="id-abc" Destination="https://example.org/acs/post">
3+
<saml:Issuer>urn:mace:example.com:saml:roland:idp</saml:Issuer>
4+
<samlp:Status>
5+
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
6+
</samlp:Status>
7+
<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0" ID="the-attack-assertion" IssueInstant="2020-12-04T07:48:09.600Z"><saml:Issuer>urn:mace:example.com:saml:roland:idp</saml:Issuer><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#the-assertion"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>dOks15WkdjeZbZZE1IuDjmTCmgY=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>CCGBBssMsEikFV7mkPw1+/W5O8Q6y2I96LWTOFpa51GpaHbZ48jRVZf1vEp5hmfMa4p3/aFH8kXZuIyqvtlxs7U6j/NI4k9t9aF3TY0VNGJjlh2aC08pzNicV1J8MKtQi4PNmxCdbhVmvrWNcx2JhG4dPqfj5oyv0LpxK2zi2JI=</ds:SignatureValue><ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIICsDCCAhmgAwIBAgIJAJrzqSSwmDY9MA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwHhcNMDkxMDA2MTk0OTQxWhcNMDkxMTA1MTk0OTQxWjBFMQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDJg2cms7MqjniT8Fi/XkNHZNPbNVQyMUMXE9tXOdqwYCA1cc8vQdzkihscQMXy3iPw2cMggBu6gjMTOSOxECkuvX5ZCclKr8pXAJM5cY6gVOaVO2PdTZcvDBKGbiaNefiEw5hnoZomqZGp8wHNLAUkwtH9vjqqvxyS/vclc6k2ewIDAQABo4GnMIGkMB0GA1UdDgQWBBRePsKHKYJsiojE78ZWXccK9K4aJTB1BgNVHSMEbjBsgBRePsKHKYJsiojE78ZWXccK9K4aJaFJpEcwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZIIJAJrzqSSwmDY9MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAJSrKOEzHO7TL5cy6h3qh+3+JAk8HbGBW+cbX6KBCAw/mzU8flK25vnWwXS3dv2FF3Aod0/S7AWNfKib5U/SA9nJaz/mWeF9S0farz9AQFc8/NSzAzaVq7YbM4F6f6N2FRl7GikdXRCed45j6mrPzGzk3ECbupFnqyREH3+ZPSdk=</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature><saml:Subject><saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">attack-name-id</saml:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml:SubjectConfirmationData NotOnOrAfter="2020-12-04T07:58:09.600Z" Recipient="https://example.org/acs/post" InResponseTo="id-abc"/></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore="2020-12-04T07:48:09.600Z" NotOnOrAfter="2020-12-04T07:58:09.600Z"><saml:AudienceRestriction><saml:Audience>urn:mace:example.com:saml:roland:sp</saml:Audience></saml:AudienceRestriction></saml:Conditions><saml:AuthnStatement AuthnInstant="2020-12-04T07:48:09.600Z" SessionNotOnOrAfter="2020-12-04T07:58:09.600Z" SessionIndex="id-sessidx"><saml:AuthnContext><saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement><saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0" ID="the-assertion" IssueInstant="2020-12-04T07:48:09.600Z"><saml:Issuer>urn:mace:example.com:saml:roland:idp</saml:Issuer><saml:Subject><saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">name-id</saml:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml:SubjectConfirmationData NotOnOrAfter="2020-12-04T07:58:09.600Z" Recipient="https://example.org/acs/post" InResponseTo="id-abc"/></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore="2020-12-04T07:48:09.600Z" NotOnOrAfter="2020-12-04T07:58:09.600Z"><saml:AudienceRestriction><saml:Audience>urn:mace:example.com:saml:roland:sp</saml:Audience></saml:AudienceRestriction></saml:Conditions><saml:AuthnStatement AuthnInstant="2020-12-04T07:48:09.600Z" SessionNotOnOrAfter="2020-12-04T07:58:09.600Z" SessionIndex="id-sessidx"><saml:AuthnContext><saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement></saml:Assertion></saml:Assertion>
8+
</samlp:Response>

0 commit comments

Comments
 (0)