|
18 | 18 | from onelogin.saml2.settings import OneLogin_Saml2_Settings |
19 | 19 | from onelogin.saml2.utils import OneLogin_Saml2_Utils |
20 | 20 |
|
21 | | - |
22 | 21 | class OneLogin_Saml2_Response_Test(unittest.TestCase): |
23 | 22 | data_path = join(dirname(dirname(dirname(dirname(__file__)))), 'data') |
24 | 23 | settings_path = join(dirname(dirname(dirname(dirname(__file__)))), 'settings') |
@@ -50,6 +49,24 @@ def get_request_data(self): |
50 | 49 | 'script_name': 'index.html' |
51 | 50 | } |
52 | 51 |
|
| 52 | + def get_request_data_domain_capitalized(self): |
| 53 | + return { |
| 54 | + 'http_host': 'StuFF.Com', |
| 55 | + 'script_name': 'endpoints/endpoints/acs.php' |
| 56 | + } |
| 57 | + |
| 58 | + def get_request_data_path_capitalized(self): |
| 59 | + return { |
| 60 | + 'http_host': 'stuff.com', |
| 61 | + 'script_name': 'Endpoints/endPoints/acs.php' |
| 62 | + } |
| 63 | + |
| 64 | + def get_request_data_both_capitalized(self): |
| 65 | + return { |
| 66 | + 'http_host': 'StuFF.Com', |
| 67 | + 'script_name': 'Endpoints/endPoints/aCs.php' |
| 68 | + } |
| 69 | + |
53 | 70 | def testConstruct(self): |
54 | 71 | """ |
55 | 72 | Tests the OneLogin_Saml2_Response Constructor. |
@@ -1001,7 +1018,7 @@ def testIsInValidDuplicatedAttrs(self): |
1001 | 1018 | response = OneLogin_Saml2_Response(settings, xml) |
1002 | 1019 | with self.assertRaisesRegex(Exception, 'Found an Attribute element with duplicated Name'): |
1003 | 1020 | response.get_attributes() |
1004 | | - |
| 1021 | + |
1005 | 1022 | def testIsInValidDestination(self): |
1006 | 1023 | """ |
1007 | 1024 | Tests the is_valid method of the OneLogin_Saml2_Response class |
@@ -1038,6 +1055,47 @@ def testIsInValidDestination(self): |
1038 | 1055 | self.assertFalse(response_5.is_valid(self.get_request_data())) |
1039 | 1056 | self.assertIn('A valid SubjectConfirmation was not found on this Response', response_5.get_error()) |
1040 | 1057 |
|
| 1058 | + settings.set_strict(True) |
| 1059 | + response_2 = OneLogin_Saml2_Response(settings, message) |
| 1060 | + self.assertFalse(response_2.is_valid(self.get_request_data())) |
| 1061 | + self.assertIn('The response was received at', response_2.get_error()) |
| 1062 | + |
| 1063 | + def testIsInValidDestinationCapitalizationOfElements(self): |
| 1064 | + """ |
| 1065 | + Tests the is_valid method of the OneLogin_Saml2_Response class |
| 1066 | + Case Invalid Response due to differences in capitalization of path |
| 1067 | + """ |
| 1068 | + |
| 1069 | + settings = OneLogin_Saml2_Settings(self.loadSettingsJSON()) |
| 1070 | + message = self.file_contents(join(self.data_path, 'responses', 'unsigned_response.xml.base64')) |
| 1071 | + |
| 1072 | + #Test path capitalized |
| 1073 | + settings.set_strict(True) |
| 1074 | + response = OneLogin_Saml2_Response(settings, message) |
| 1075 | + self.assertFalse(response.is_valid(self.get_request_data_path_capitalized())) |
| 1076 | + self.assertIn('The response was received at', response.get_error()) |
| 1077 | + |
| 1078 | + #Test both domain and path capitalized |
| 1079 | + response_2 = OneLogin_Saml2_Response(settings, message) |
| 1080 | + self.assertFalse(response_2.is_valid(self.get_request_data_both_capitalized())) |
| 1081 | + self.assertIn('The response was received at', response_2.get_error()) |
| 1082 | + |
| 1083 | + def testIsValidDestinationCapitalizationOfHost(self): |
| 1084 | + """ |
| 1085 | + Tests the is_valid method of the OneLogin_Saml2_Response class |
| 1086 | + Case Valid Response, even if host is differently capitalized (per RFC) |
| 1087 | + """ |
| 1088 | + settings = OneLogin_Saml2_Settings(self.loadSettingsJSON()) |
| 1089 | + message = self.file_contents(join(self.data_path, 'responses', 'unsigned_response.xml.base64')) |
| 1090 | + #Test domain capitalized |
| 1091 | + settings.set_strict(True) |
| 1092 | + response = OneLogin_Saml2_Response(settings, message) |
| 1093 | + self.assertFalse(response.is_valid(self.get_request_data_domain_capitalized())) |
| 1094 | + self.assertNotIn('The response was received at', response.get_error()) |
| 1095 | + |
| 1096 | + #Assert we got past the destination check, which appears later |
| 1097 | + self.assertIn('A valid SubjectConfirmation was not found', response.get_error()) |
| 1098 | + |
1041 | 1099 | def testIsInValidAudience(self): |
1042 | 1100 | """ |
1043 | 1101 | Tests the is_valid method of the OneLogin_Saml2_Response class |
|
0 commit comments