Skip to content

Commit

Permalink
SAML-Toolkits#190 Checking the status of response before assertion count
Browse files Browse the repository at this point in the history
Failed Responses don't have assertions and the error hides that the
status is not success
  • Loading branch information
thejuan committed Apr 21, 2017
1 parent cebc37b commit 2b5091c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/onelogin/saml2/response.py
Expand Up @@ -84,16 +84,16 @@ def is_valid(self, request_data, request_id=None, raise_exceptions=False):
OneLogin_Saml2_ValidationError.MISSING_ID
)

# Checks that the response has the SUCCESS status
self.check_status()

# Checks that the response only has one assertion
if not self.validate_num_assertions():
raise OneLogin_Saml2_ValidationError(
'SAML Response must contain 1 assertion',
OneLogin_Saml2_ValidationError.WRONG_NUMBER_OF_ASSERTIONS
)

# Checks that the response has the SUCCESS status
self.check_status()

idp_data = self.__settings.get_idp_data()
idp_entity_id = idp_data.get('entityId', '')
sp_data = self.__settings.get_sp_data()
Expand Down
11 changes: 11 additions & 0 deletions tests/src/OneLogin/saml2_tests/response_test.py
Expand Up @@ -1391,6 +1391,17 @@ def testIsValidWithoutInResponseTo(self):
}))


def testStatusCheckBeforeAssertionCheck(self):
"""
Tests the status of a response is checked before the assertion count. As failed statuses will have no assertions
"""
settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())
xml_2 = self.file_contents(join(self.data_path, 'responses', 'invalids', 'status_code_responder.xml.base64'))
response_2 = OneLogin_Saml2_Response(settings, xml_2)
with self.assertRaisesRegexp(OneLogin_Saml2_ValidationError, 'The status code of the Response was not Success, was Responder'):
response_2.is_valid(self.get_request_data(), raise_exceptions=True)


if __name__ == '__main__':
if is_running_under_teamcity():
runner = TeamcityTestRunner()
Expand Down

0 comments on commit 2b5091c

Please sign in to comment.