Skip to content

Commit 8d9ea1a

Browse files
author
Tessa Bloomer
committed
Fixed tests
1 parent 92fae88 commit 8d9ea1a

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

src/onelogin/saml2/logout_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def is_valid(self, request_data, request_id=None, raise_exceptions=False):
118118

119119
# Check destination
120120
destination = self.document.get('Destination', None)
121-
if destination and OneLogin_Saml2_Utils.normalize_url(current_url) not in OneLogin_Saml2_Utils.normalize_url(destination):
121+
if destination and OneLogin_Saml2_Utils.normalize_url(url=current_url) not in OneLogin_Saml2_Utils.normalize_url(url=destination):
122122
raise OneLogin_Saml2_ValidationError(
123123
'The LogoutResponse was received at %s instead of %s' % (current_url, destination),
124124
OneLogin_Saml2_ValidationError.WRONG_DESTINATION

src/onelogin/saml2/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def is_valid(self, request_data, request_id=None, raise_exceptions=False):
192192
# Checks destination
193193
destination = self.document.get('Destination', None)
194194
if destination:
195-
if not OneLogin_Saml2_Utils.normalize_url(destination).startswith(OneLogin_Saml2_Utils.normalize_url(current_url)):
195+
if not OneLogin_Saml2_Utils.normalize_url(url=destination).startswith(OneLogin_Saml2_Utils.normalize_url(url=current_url)):
196196
# TODO: Review if following lines are required, since we can control the
197197
# request_data
198198
# current_url_routed = OneLogin_Saml2_Utils.get_self_routed_url_no_query(request_data)

src/onelogin/saml2/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from functools import wraps
2121
from uuid import uuid4
2222
from xml.dom.minidom import Element
23-
23+
from urllib.parse import urlsplit, urlunsplit
2424
import zlib
2525
import xmlsec
2626

@@ -1063,8 +1063,8 @@ def validate_binary_sign(signed_query, signature, cert=None, algorithm=OneLogin_
10631063
print(e)
10641064
return False
10651065

1066-
@staticmethod
1067-
def normalize_url(self, url):
1066+
@staticmethod
1067+
def normalize_url(url):
10681068
"""
10691069
Returns normalized URL for comparison.
10701070
This method converts the netloc to lowercase, as it should be case-insensitive (per RFC 4343, RFC 7617)

tests/src/OneLogin/saml2_tests/response_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,12 +1063,12 @@ def testIsValidDestinationCapitalizationOfHost(self):
10631063
"""
10641064
settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())
10651065
message = self.file_contents(join(self.data_path, 'responses', 'unsigned_response.xml.base64'))
1066-
10671066
#Test domain capitalized
10681067
settings.set_strict(True)
10691068
response = OneLogin_Saml2_Response(settings, message)
10701069
self.assertFalse(response.is_valid(self.get_request_data_domain_capitalized()))
10711070
self.assertNotIn('The response was received at', response.get_error())
1071+
10721072
#Assert we got past the destination check, which appears later
10731073
self.assertIn('A valid SubjectConfirmation was not found', response.get_error())
10741074

tests/src/OneLogin/saml2_tests/utils_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,3 +917,15 @@ def testValidateSign(self):
917917
# Signature Wrapping attack
918918
wrapping_attack1 = b64decode(self.file_contents(join(self.data_path, 'responses', 'invalids', 'signature_wrapping_attack.xml.base64')))
919919
self.assertFalse(OneLogin_Saml2_Utils.validate_sign(wrapping_attack1, cert))
920+
921+
def testNormalizeUrl(self):
922+
base_url = 'https://blah.com/path'
923+
capital_scheme = 'hTTps://blah.com/path'
924+
capital_domain = 'https://blAH.Com/path'
925+
capital_path = 'https://blah.com/PAth'
926+
capital_all = 'HTTPS://BLAH.COM/PATH'
927+
928+
self.assertIn(base_url, OneLogin_Saml2_Utils.normalize_url(capital_scheme))
929+
self.assertIn(base_url, OneLogin_Saml2_Utils.normalize_url(capital_domain))
930+
self.assertNotIn(base_url, OneLogin_Saml2_Utils.normalize_url(capital_path))
931+
self.assertNotIn(base_url, OneLogin_Saml2_Utils.normalize_url(capital_all))

0 commit comments

Comments
 (0)