Skip to content

Commit 55b3f49

Browse files
committed
Added get_in_response_to method to Response and LogoutResponse classes
1 parent 08fdfdf commit 55b3f49

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/onelogin/saml2/logout_response.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def is_valid(self, request_data, request_id=None, raise_exceptions=False):
9595
security = self.__settings.get_security_data()
9696

9797
# Check if the InResponseTo of the Logout Response matches the ID of the Logout Request (requestId) if provided
98-
in_response_to = self.document.get('InResponseTo', None)
98+
in_response_to = self.get_in_response_to()
9999
if request_id is not None and in_response_to and in_response_to != request_id:
100100
raise OneLogin_Saml2_ValidationError(
101101
'The InResponseTo of the Logout Response: %s, does not match the ID of the Logout request sent by the SP: %s' % (in_response_to, request_id),
@@ -175,6 +175,9 @@ def build(self, in_response_to):
175175

176176
self.__logout_response = logout_response
177177

178+
def get_in_response_to(self):
179+
return self.document.get('InResponseTo')
180+
178181
def get_response(self, deflate=True):
179182
"""
180183
Returns a Logout Response object.

src/onelogin/saml2/response.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def is_valid(self, request_data, request_id=None, raise_exceptions=False):
122122
current_url = OneLogin_Saml2_Utils.get_self_url_no_query(request_data)
123123

124124
# Check if the InResponseTo of the Response matchs the ID of the AuthNRequest (requestId) if provided
125-
in_response_to = self.document.get('InResponseTo', None)
125+
in_response_to = self.get_in_response_to()
126126
if in_response_to is not None and request_id is not None:
127127
if in_response_to != request_id:
128128
raise OneLogin_Saml2_ValidationError(
@@ -387,6 +387,14 @@ def get_authn_contexts(self):
387387
authn_context_nodes = self.__query_assertion('/saml:AuthnStatement/saml:AuthnContext/saml:AuthnContextClassRef')
388388
return [OneLogin_Saml2_XML.element_text(node) for node in authn_context_nodes]
389389

390+
def get_in_response_to(self):
391+
"""
392+
Gets the ID of the request which this response is in response to
393+
:returns: ID of AuthNRequest this Response is in response to or None if it is not present
394+
:rtype: str
395+
"""
396+
return self.document.get('InResponseTo')
397+
390398
def get_issuers(self):
391399
"""
392400
Gets the issuers (from message and from assertion)

tests/src/OneLogin/saml2_tests/response_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def testGetXMLDocument(self):
7575

7676
xml = self.file_contents(join(self.data_path, 'responses', 'signed_message_response.xml.base64'))
7777
response = OneLogin_Saml2_Response(settings, xml)
78-
prety_xml = self.file_contents(join(self.data_path, 'responses', 'pretty_signed_message_response.xml'))
79-
self.assertEqual(etree.tostring(response.get_xml_document(), encoding='unicode', pretty_print=True), prety_xml)
78+
pretty_xml = self.file_contents(join(self.data_path, 'responses', 'pretty_signed_message_response.xml'))
79+
self.assertEqual(etree.tostring(response.get_xml_document(), encoding='unicode', pretty_print=True), pretty_xml)
8080

8181
xml_2 = self.file_contents(join(self.data_path, 'responses', 'valid_encrypted_assertion.xml.base64'))
8282
response_2 = OneLogin_Saml2_Response(settings, xml_2)

0 commit comments

Comments
 (0)