Skip to content

Commit 2dce359

Browse files
committed
Handle non standard response error status codes
1 parent 65b136e commit 2dce359

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/saml2/response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ def status_ok(self):
360360
if status.status_code.value != samlp.STATUS_SUCCESS:
361361
logger.info("Not successful operation: %s", status)
362362
if status.status_code.status_code:
363-
excep = STATUSCODE2EXCEPTION[
364-
status.status_code.status_code.value]
363+
excep = STATUSCODE2EXCEPTION.get(
364+
status.status_code.status_code.value, StatusError)
365365
else:
366366
excep = StatusError
367367
if status.status_message:

tests/test_51_client.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from saml2.authn_context import INTERNETPROTOCOLPASSWORD
2929
from saml2.client import Saml2Client
3030
from saml2.pack import parse_soap_enveloped_saml
31-
from saml2.response import LogoutResponse, StatusInvalidNameidPolicy
31+
from saml2.response import LogoutResponse, StatusInvalidNameidPolicy, StatusError
3232
from saml2.saml import NAMEID_FORMAT_PERSISTENT, EncryptedAssertion, Advice
3333
from saml2.saml import NAMEID_FORMAT_TRANSIENT
3434
from saml2.saml import NameID
@@ -2325,6 +2325,37 @@ def test_response_error_status(self):
23252325
resp_str, BINDING_HTTP_POST,
23262326
{"id1": "http://foo.example.com/service"})
23272327

2328+
def test_response_error_status_non_standard_status_code(self):
2329+
""" Test that the SP client can parse an authentication response
2330+
from an IdP that contains an error status."""
2331+
2332+
conf = config.SPConfig()
2333+
conf.load_file("server_conf")
2334+
client = Saml2Client(conf)
2335+
2336+
resp = self.server.create_error_response(
2337+
in_response_to="id1",
2338+
destination="http://lingon.catalogix.se:8087/",
2339+
info=('http://example.com/status/1.0/cancel', None),
2340+
)
2341+
2342+
# Cast the response to a string and encode it to mock up the payload
2343+
# the SP client is expected to receive via HTTP POST binding.
2344+
if six.PY2:
2345+
resp_str = encode_fn(str(resp))
2346+
else:
2347+
resp_str = encode_fn(bytes(str(resp), 'utf-8'))
2348+
2349+
# We do not need the client to verify a signature for this test.
2350+
client.want_assertions_signed = False
2351+
client.want_response_signed = False
2352+
2353+
# Parse the authentication error response
2354+
with raises(StatusError):
2355+
client.parse_authn_request_response(
2356+
resp_str, BINDING_HTTP_POST,
2357+
{"id1": "http://foo.example.com/service"})
2358+
23282359
def setup_verify_authn_response(self):
23292360
idp = "urn:mace:example.com:saml:roland:idp"
23302361
ava = {"givenName": ["Dave"], "sn": ["Concepción"],

0 commit comments

Comments
 (0)