Skip to content

Commit 2ee1bce

Browse files
author
Jerome Thiard
committed
Make the Issuer on the Response Optional
backport of SAML-Toolkits/python-saml@7e4d502
1 parent 90781d9 commit 2ee1bce

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/onelogin/saml2/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class OneLogin_Saml2_ValidationError(Exception):
9191
WRONG_DESTINATION = 24
9292
EMPTY_DESTINATION = 25
9393
WRONG_AUDIENCE = 26
94-
ISSUER_NOT_FOUND_IN_RESPONSE = 27
94+
ISSUER_MULTIPLE_IN_RESPONSE = 27
9595
ISSUER_NOT_FOUND_IN_ASSERTION = 28
9696
WRONG_ISSUER = 29
9797
SESSION_EXPIRED = 30

src/onelogin/saml2/response.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,14 @@ def get_issuers(self):
362362
issuers = set()
363363

364364
message_issuer_nodes = OneLogin_Saml2_XML.query(self.document, '/samlp:Response/saml:Issuer')
365-
if len(message_issuer_nodes) == 1:
366-
issuers.add(message_issuer_nodes[0].text)
367-
else:
368-
raise OneLogin_Saml2_ValidationError(
369-
'Issuer of the Response not found or multiple.',
370-
OneLogin_Saml2_ValidationError.ISSUER_NOT_FOUND_IN_RESPONSE
371-
)
365+
if len(message_issuer_nodes) > 0:
366+
if len(message_issuer_nodes) == 1:
367+
issuers.add(message_issuer_nodes[0].text)
368+
else:
369+
raise OneLogin_Saml2_ValidationError(
370+
'Issuer of the Response is multiple.',
371+
OneLogin_Saml2_ValidationError.ISSUER_MULTIPLE_IN_RESPONSE
372+
)
372373

373374
assertion_issuer_nodes = self.__query_assertion('/saml:Issuer')
374375
if len(assertion_issuer_nodes) == 1:

tests/src/OneLogin/saml2_tests/response_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ def testGetIssuers(self):
354354

355355
xml_4 = self.file_contents(join(self.data_path, 'responses', 'invalids', 'no_issuer_response.xml.base64'))
356356
response_4 = OneLogin_Saml2_Response(settings, xml_4)
357-
with self.assertRaisesRegexp(Exception, 'Issuer of the Response not found or multiple.'):
358-
response_4.get_issuers()
357+
response_4.get_issuers()
358+
self.assertEqual(['https://pitbulk.no-ip.org/simplesaml/saml2/idp/metadata.php'], response_4.get_issuers())
359359

360360
xml_5 = self.file_contents(join(self.data_path, 'responses', 'invalids', 'no_issuer_assertion.xml.base64'))
361361
response_5 = OneLogin_Saml2_Response(settings, xml_5)

0 commit comments

Comments
 (0)