|
13 | 13 | from onelogin.saml2.constants import OneLogin_Saml2_Constants |
14 | 14 | from onelogin.saml2.settings import OneLogin_Saml2_Settings |
15 | 15 | from onelogin.saml2.utils import OneLogin_Saml2_Utils |
| 16 | +from onelogin.saml2.logout_request import OneLogin_Saml2_Logout_Request |
16 | 17 |
|
17 | 18 |
|
18 | 19 | class OneLogin_Saml2_Auth_Test(unittest.TestCase): |
@@ -95,9 +96,25 @@ def testGetSessionIndex(self): |
95 | 96 | auth2.process_response() |
96 | 97 | self.assertEqual('_6273d77b8cde0c333ec79d22a9fa0003b9fe2d75cb', auth2.get_session_index()) |
97 | 98 |
|
| 99 | + def testGetLastErrorReason(self): |
| 100 | + """ |
| 101 | + Tests the get_last_error_reason method of the OneLogin_Saml2_Auth class |
| 102 | + Case Invalid Response |
| 103 | + """ |
| 104 | + request_data = self.get_request() |
| 105 | + message = self.file_contents(join(self.data_path, 'responses', 'response1.xml.base64')) |
| 106 | + del request_data['get_data'] |
| 107 | + request_data['post_data'] = { |
| 108 | + 'SAMLResponse': message |
| 109 | + } |
| 110 | + auth = OneLogin_Saml2_Auth(request_data, old_settings=self.loadSettingsJSON()) |
| 111 | + auth.process_response() |
| 112 | + |
| 113 | + self.assertEqual(auth.get_last_error_reason(), 'Signature validation failed. SAML Response rejected') |
| 114 | + |
98 | 115 | def testProcessNoResponse(self): |
99 | 116 | """ |
100 | | - Tests the processResponse method of the OneLogin_Saml2_Auth class |
| 117 | + Tests the process_response method of the OneLogin_Saml2_Auth class |
101 | 118 | Case No Response, An exception is throw |
102 | 119 | """ |
103 | 120 | auth = OneLogin_Saml2_Auth(self.get_request(), old_settings=self.loadSettingsJSON()) |
@@ -645,6 +662,53 @@ def testLogoutNoSLO(self): |
645 | 662 | except Exception as e: |
646 | 663 | self.assertIn('The IdP does not support Single Log Out', e.message) |
647 | 664 |
|
| 665 | + def testLogoutNameIDandSessionIndex(self): |
| 666 | + """ |
| 667 | + Tests the logout method of the OneLogin_Saml2_Auth class |
| 668 | + Case nameID and sessionIndex as parameters. |
| 669 | + """ |
| 670 | + settings_info = self.loadSettingsJSON() |
| 671 | + request_data = self.get_request() |
| 672 | + auth = OneLogin_Saml2_Auth(request_data, old_settings=settings_info) |
| 673 | + |
| 674 | + name_id = 'name_id_example' |
| 675 | + session_index = 'session_index_example' |
| 676 | + target_url = auth.logout(name_id=name_id, session_index=session_index) |
| 677 | + parsed_query = parse_qs(urlparse(target_url)[4]) |
| 678 | + slo_url = settings_info['idp']['singleLogoutService']['url'] |
| 679 | + self.assertIn(slo_url, target_url) |
| 680 | + self.assertIn('SAMLRequest', parsed_query) |
| 681 | + |
| 682 | + logout_request = OneLogin_Saml2_Utils.decode_base64_and_inflate(parsed_query['SAMLRequest'][0]) |
| 683 | + name_id_from_request = OneLogin_Saml2_Logout_Request.get_nameid(logout_request) |
| 684 | + sessions_index_in_request = OneLogin_Saml2_Logout_Request.get_session_indexes(logout_request) |
| 685 | + self.assertIn(session_index, sessions_index_in_request) |
| 686 | + self.assertEqual(name_id, name_id_from_request) |
| 687 | + |
| 688 | + def testLogoutNameID(self): |
| 689 | + """ |
| 690 | + Tests the logout method of the OneLogin_Saml2_Auth class |
| 691 | + Case nameID loaded after process SAML Response |
| 692 | + """ |
| 693 | + request_data = self.get_request() |
| 694 | + message = self.file_contents(join(self.data_path, 'responses', 'valid_response.xml.base64')) |
| 695 | + del request_data['get_data'] |
| 696 | + request_data['post_data'] = { |
| 697 | + 'SAMLResponse': message |
| 698 | + } |
| 699 | + auth = OneLogin_Saml2_Auth(request_data, old_settings=self.loadSettingsJSON()) |
| 700 | + auth.process_response() |
| 701 | + |
| 702 | + name_id_from_response = auth.get_nameid() |
| 703 | + |
| 704 | + target_url = auth.logout() |
| 705 | + parsed_query = parse_qs(urlparse(target_url)[4]) |
| 706 | + self.assertIn('SAMLRequest', parsed_query) |
| 707 | + logout_request = OneLogin_Saml2_Utils.decode_base64_and_inflate(parsed_query['SAMLRequest'][0]) |
| 708 | + |
| 709 | + name_id_from_request = OneLogin_Saml2_Logout_Request.get_nameid(logout_request) |
| 710 | + self.assertEqual(name_id_from_response, name_id_from_request) |
| 711 | + |
648 | 712 | def testSetStrict(self): |
649 | 713 | """ |
650 | 714 | Tests the set_strict method of the OneLogin_Saml2_Auth |
|
0 commit comments