Skip to content

Commit 66ab8da

Browse files
committed
Improve invalid audience error message
Make the error message for invalid audience more descriptive by including the request's audience and the expected value.
1 parent 52d2ac8 commit 66ab8da

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/onelogin/saml2/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def is_valid(self, request_data, request_id=None, raise_exceptions=False):
167167
# Checks audience
168168
valid_audiences = self.get_audiences()
169169
if valid_audiences and sp_entity_id not in valid_audiences:
170-
raise OneLogin_Saml2_ValidationError("%s is not a valid audience for this Response" % sp_entity_id, OneLogin_Saml2_ValidationError.WRONG_AUDIENCE)
170+
raise OneLogin_Saml2_ValidationError('Response audience "%s" does not contain SP entityId "%s"' % (", ".join(valid_audiences), sp_entity_id), OneLogin_Saml2_ValidationError.WRONG_AUDIENCE)
171171

172172
# Checks the issuers
173173
issuers = self.get_issuers()

tests/src/OneLogin/saml2_tests/response_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ def testIsInValidAudience(self):
11431143
response_2 = OneLogin_Saml2_Response(settings, message)
11441144

11451145
self.assertFalse(response_2.is_valid(request_data))
1146-
self.assertIn("is not a valid audience for this Response", response_2.get_error())
1146+
self.assertIn('Response audience "http://invalid.audience.com" does not contain SP entityId "http://stuff.com/endpoints/metadata.php"', response_2.get_error())
11471147

11481148
def testIsInValidAuthenticationContext(self):
11491149
"""

0 commit comments

Comments
 (0)