Skip to content

Commit e8a2f49

Browse files
authored
Merge pull request #191 from thejuan/master
Checking the status of response before assertion count
2 parents cebc37b + ba9fdfe commit e8a2f49

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
@@ -84,16 +84,16 @@ def is_valid(self, request_data, request_id=None, raise_exceptions=False):
8484
OneLogin_Saml2_ValidationError.MISSING_ID
8585
)
8686

87+
# Checks that the response has the SUCCESS status
88+
self.check_status()
89+
8790
# Checks that the response only has one assertion
8891
if not self.validate_num_assertions():
8992
raise OneLogin_Saml2_ValidationError(
9093
'SAML Response must contain 1 assertion',
9194
OneLogin_Saml2_ValidationError.WRONG_NUMBER_OF_ASSERTIONS
9295
)
9396

94-
# Checks that the response has the SUCCESS status
95-
self.check_status()
96-
9797
idp_data = self.__settings.get_idp_data()
9898
idp_entity_id = idp_data.get('entityId', '')
9999
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
@@ -1390,6 +1390,16 @@ def testIsValidWithoutInResponseTo(self):
13901390
'script_name': 'newonelogin/demo1/index.php?acs'
13911391
}))
13921392

1393+
def testStatusCheckBeforeAssertionCheck(self):
1394+
"""
1395+
Tests the status of a response is checked before the assertion count. As failed statuses will have no assertions
1396+
"""
1397+
settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())
1398+
xml = self.file_contents(join(self.data_path, 'responses', 'invalids', 'status_code_responder.xml.base64'))
1399+
response = OneLogin_Saml2_Response(settings, xml)
1400+
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'The status code of the Response was not Success, was Responder'):
1401+
response.is_valid(self.get_request_data(), raise_exceptions=True)
1402+
13931403

13941404
if __name__ == '__main__':
13951405
if is_running_under_teamcity():

0 commit comments

Comments
 (0)