|
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. |
@@ -977,7 +994,7 @@ def testIsInValidDuplicatedAttrs(self): |
977 | 994 | response = OneLogin_Saml2_Response(settings, xml) |
978 | 995 | with self.assertRaisesRegex(Exception, 'Found an Attribute element with duplicated Name'): |
979 | 996 | response.get_attributes() |
980 | | - |
| 997 | + |
981 | 998 | def testIsInValidDestination(self): |
982 | 999 | """ |
983 | 1000 | Tests the is_valid method of the OneLogin_Saml2_Response class |
@@ -1014,6 +1031,45 @@ def testIsInValidDestination(self): |
1014 | 1031 | self.assertFalse(response_5.is_valid(self.get_request_data())) |
1015 | 1032 | self.assertIn('A valid SubjectConfirmation was not found on this Response', response_5.get_error()) |
1016 | 1033 |
|
| 1034 | + settings.set_strict(True) |
| 1035 | + response_2 = OneLogin_Saml2_Response(settings, message) |
| 1036 | + self.assertFalse(response_2.is_valid(self.get_request_data())) |
| 1037 | + self.assertIn('The response was received at', response_2.get_error()) |
| 1038 | + |
| 1039 | + def testIsInValidCapitalizationOfDestinationElements(self): |
| 1040 | + """ |
| 1041 | + Tests the is_valid method of the OneLogin_Saml2_Response class |
| 1042 | + Case Invalid Response due to differences in capitalization of path |
| 1043 | + """ |
| 1044 | + |
| 1045 | + settings = OneLogin_Saml2_Settings(self.loadSettingsJSON()) |
| 1046 | + message = self.file_contents(join(self.data_path, 'responses', 'unsigned_response.xml.base64')) |
| 1047 | + |
| 1048 | + #Test path capitalized |
| 1049 | + settings.set_strict(True) |
| 1050 | + response = OneLogin_Saml2_Response(settings, message) |
| 1051 | + self.assertFalse(response.is_valid(self.get_request_data_path_capitalized())) |
| 1052 | + self.assertIn('The response was received at', response.get_error()) |
| 1053 | + |
| 1054 | + #Test both domain and path capitalized |
| 1055 | + response_2 = OneLogin_Saml2_Response(settings, message) |
| 1056 | + self.assertFalse(response_2.is_valid(self.get_request_data_both_capitalized())) |
| 1057 | + self.assertIn('The response was received at', response_2.get_error()) |
| 1058 | + |
| 1059 | + def testIsValidCapitalizationOfDestinationHost(self): |
| 1060 | + """ |
| 1061 | + Tests the is_valid method of the OneLogin_Saml2_Response class |
| 1062 | + Case Valid Response, even if host is differently capitalized (per RFC) |
| 1063 | + """ |
| 1064 | + settings = OneLogin_Saml2_Settings(self.loadSettingsJSON()) |
| 1065 | + message = self.file_contents(join(self.data_path, 'responses', 'unsigned_response.xml.base64')) |
| 1066 | + |
| 1067 | + #Test path capitalized |
| 1068 | + settings.set_strict(True) |
| 1069 | + response = OneLogin_Saml2_Response(settings, message) |
| 1070 | + self.assertFalse(response.is_valid(self.get_request_data_domain_capitalized())) |
| 1071 | + self.assertNotIn('The response was received at', response.get_error()) |
| 1072 | + |
1017 | 1073 | def testIsInValidAudience(self): |
1018 | 1074 | """ |
1019 | 1075 | Tests the is_valid method of the OneLogin_Saml2_Response class |
|
0 commit comments