Skip to content

Commit 8422212

Browse files
committed
Checking the status of response before assertion count
1 parent 192a3fd commit 8422212

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/onelogin/saml2/response.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ def is_valid(self, request_data, request_id=None, raise_exceptions=False):
7979
OneLogin_Saml2_ValidationError.MISSING_ID
8080
)
8181

82+
# Checks that the response has the SUCCESS status
83+
self.check_status()
84+
8285
# Checks that the response only has one assertion
8386
if not self.validate_num_assertions():
8487
raise OneLogin_Saml2_ValidationError(
8588
'SAML Response must contain 1 assertion',
8689
OneLogin_Saml2_ValidationError.WRONG_NUMBER_OF_ASSERTIONS
8790
)
8891

89-
# Checks that the response has the SUCCESS status
90-
self.check_status()
91-
9292
idp_data = self.__settings.get_idp_data()
9393
idp_entity_id = idp_data['entityId']
9494
sp_data = self.__settings.get_sp_data()

tests/src/OneLogin/saml2_tests/response_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,3 +1402,13 @@ def testIsValidRaisesExceptionWhenRaisesArgumentIsTrue(self):
14021402

14031403
with self.assertRaises(Exception):
14041404
response.is_valid(self.get_request_data(), raise_exceptions=True)
1405+
1406+
def testStatusCheckBeforeAssertionCheck(self):
1407+
"""
1408+
Tests the status of a response is checked before the assertion count. As failed statuses will have no assertions
1409+
"""
1410+
settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())
1411+
xml = self.file_contents(join(self.data_path, 'responses', 'invalids', 'status_code_responder.xml.base64'))
1412+
response = OneLogin_Saml2_Response(settings, xml)
1413+
with self.assertRaisesRegexp(Exception, 'The status code of the Response was not Success, was Responder'):
1414+
response.is_valid(self.get_request_data(), raise_exceptions=True)

0 commit comments

Comments
 (0)