|
14 | 14 | from pathutils import full_path
|
15 | 15 |
|
16 | 16 |
|
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") |
18 | 20 |
|
19 | 21 |
|
20 |
| -class TestAuthnResponse: |
| 22 | + |
| 23 | +class TestXSW: |
21 | 24 | def setup_class(self):
|
22 | 25 | 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 |
24 | 69 |
|
25 | 70 | @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): |
27 | 72 | self.ar.issue_instant_ok = Mock(return_value=True)
|
28 | 73 |
|
29 |
| - with open(XML_RESPONSE_XSW) as fp: |
| 74 | + with open(SIGNED_XSW_ASSERTION_ASSERTION) as fp: |
30 | 75 | xml_response = fp.read()
|
31 | 76 |
|
32 |
| - self.ar.outstanding_queries = {"id12": "http://localhost:8088/sso"} |
| 77 | + self.ar.outstanding_queries = {"id-abc": "http://localhost:8088/sso"} |
33 | 78 | self.ar.timeslack = 10000
|
34 | 79 | self.ar.loads(xml_response, decode=False)
|
35 | 80 |
|
36 | 81 | assert self.ar.came_from == 'http://localhost:8088/sso'
|
37 |
| - assert self.ar.session_id() == "id12" |
| 82 | + assert self.ar.session_id() == "id-abc" |
38 | 83 | assert self.ar.issuer() == 'urn:mace:example.com:saml:roland:idp'
|
39 | 84 |
|
40 | 85 | with raises(SignatureError):
|
|
0 commit comments