Skip to content

Commit 12a01b6

Browse files
Merge pull request #574 from rectalogic/error-status
Raise status exception when parsing an error status response
2 parents 6b24eb2 + 6a179ff commit 12a01b6

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/saml2/entity.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,6 @@ def _parse_response(self, xmlstr, response_cls, service, binding,
12071207
else:
12081208
response.require_signature = require_signature
12091209
response = response.verify(keys)
1210-
except Exception as err:
1211-
logger.error("Exception verifying assertion: %s" % err)
12121210
else:
12131211
assertions_are_signed = True
12141212
finally:

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
31+
from saml2.response import LogoutResponse, StatusInvalidNameidPolicy
3232
from saml2.saml import NAMEID_FORMAT_PERSISTENT, EncryptedAssertion, Advice
3333
from saml2.saml import NAMEID_FORMAT_TRANSIENT
3434
from saml2.saml import NameID
@@ -2294,6 +2294,37 @@ def test_response_no_name_id(self):
22942294
# A successful test is parsing the response.
22952295
assert authn_response is not None
22962296

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+
22972328
def setup_verify_authn_response(self):
22982329
idp = "urn:mace:example.com:saml:roland:idp"
22992330
ava = {"givenName": ["Dave"], "sn": ["Concepción"],

0 commit comments

Comments
 (0)