|
28 | 28 | from saml2.authn_context import INTERNETPROTOCOLPASSWORD
|
29 | 29 | from saml2.client import Saml2Client
|
30 | 30 | from saml2.pack import parse_soap_enveloped_saml
|
31 |
| -from saml2.response import LogoutResponse |
| 31 | +from saml2.response import LogoutResponse, StatusInvalidNameidPolicy |
32 | 32 | from saml2.saml import NAMEID_FORMAT_PERSISTENT, EncryptedAssertion, Advice
|
33 | 33 | from saml2.saml import NAMEID_FORMAT_TRANSIENT
|
34 | 34 | from saml2.saml import NameID
|
@@ -2294,6 +2294,37 @@ def test_response_no_name_id(self):
|
2294 | 2294 | # A successful test is parsing the response.
|
2295 | 2295 | assert authn_response is not None
|
2296 | 2296 |
|
| 2297 | + def test_response_error_status(self): |
| 2298 | + """ Test that the SP client can parse an authentication response |
| 2299 | + from an IdP that contains an error status.""" |
| 2300 | + |
| 2301 | + conf = config.SPConfig() |
| 2302 | + conf.load_file("server_conf") |
| 2303 | + client = Saml2Client(conf) |
| 2304 | + |
| 2305 | + resp = self.server.create_error_response( |
| 2306 | + in_response_to="id1", |
| 2307 | + destination="http://lingon.catalogix.se:8087/", |
| 2308 | + info=(samlp.STATUS_INVALID_NAMEID_POLICY, None), |
| 2309 | + ) |
| 2310 | + |
| 2311 | + # Cast the response to a string and encode it to mock up the payload |
| 2312 | + # the SP client is expected to receive via HTTP POST binding. |
| 2313 | + if six.PY2: |
| 2314 | + resp_str = encode_fn(str(resp)) |
| 2315 | + else: |
| 2316 | + resp_str = encode_fn(bytes(str(resp), 'utf-8')) |
| 2317 | + |
| 2318 | + # We do not need the client to verify a signature for this test. |
| 2319 | + client.want_assertions_signed = False |
| 2320 | + client.want_response_signed = False |
| 2321 | + |
| 2322 | + # Parse the authentication error response |
| 2323 | + with raises(StatusInvalidNameidPolicy): |
| 2324 | + client.parse_authn_request_response( |
| 2325 | + resp_str, BINDING_HTTP_POST, |
| 2326 | + {"id1": "http://foo.example.com/service"}) |
| 2327 | + |
2297 | 2328 | def setup_verify_authn_response(self):
|
2298 | 2329 | idp = "urn:mace:example.com:saml:roland:idp"
|
2299 | 2330 | ava = {"givenName": ["Dave"], "sn": ["Concepción"],
|
|
0 commit comments