def test_rewrite_name_id_persistent(self): light_response_data = LIGHT_RESPONSE_DICT.copy() light_response_data['status'] = Status(**light_response_data['status']) light_response_data['subject_name_id_format'] = NameIdFormat.PERSISTENT view = IdentityProviderResponseView() view.light_response = LightResponse(**light_response_data) view.auxiliary_data = {'name_id_format': NameIdFormat.PERSISTENT.value} view.rewrite_name_id() self.assertEqual(view.light_response.subject_name_id_format, NameIdFormat.PERSISTENT) self.assertEqual(view.light_response.subject, 'CZ/CZ/ff70c9dd-6a05-4068-aaa2-b57be4f328e9')
def test_rewrite_name_id_failure(self): light_response_data = FAILED_LIGHT_RESPONSE_DICT.copy() light_response_data['status'] = Status(**light_response_data['status']) light_response_data['subject_name_id_format'] = NameIdFormat.PERSISTENT view = IdentityProviderResponseView() view.light_response = LightResponse(**light_response_data) view.auxiliary_data = {'name_id_format': NameIdFormat.TRANSIENT.value} view.rewrite_name_id() self.assertEqual(view.light_response.subject_name_id_format, NameIdFormat.PERSISTENT) self.assertIsNone(view.light_response.subject)
def test_rewrite_name_id_unspecified_to_transient(self, uuid_mock): light_response_data = LIGHT_RESPONSE_DICT.copy() light_response_data['status'] = Status(**light_response_data['status']) light_response_data['subject_name_id_format'] = NameIdFormat.UNSPECIFIED view = IdentityProviderResponseView() view.light_response = LightResponse(**light_response_data) view.auxiliary_data = {'name_id_format': NameIdFormat.TRANSIENT.value} view.rewrite_name_id() self.assertEqual(view.light_response.subject_name_id_format, NameIdFormat.TRANSIENT) self.assertEqual(view.light_response.subject, '0uuid4')
def test_create_light_token(self, uuid_mock: MagicMock): view = IdentityProviderResponseView() view.request = self.factory.post(self.url) light_response_data = LIGHT_RESPONSE_DICT.copy() light_response_data['status'] = Status(**light_response_data['status']) view.light_response = LightResponse(**light_response_data) token, encoded_token = view.create_light_token('test-token-issuer', 'sha256', 'test-secret') self.assertEqual(token.id, 'T0uuid4') self.assertEqual(token.issuer, 'test-token-issuer') self.assertEqual(token.created, datetime(2017, 12, 11, 16, 12, 5)) self.assertEqual(token.encode('sha256', 'test-secret').decode('ascii'), encoded_token) self.assertEqual(uuid_mock.mock_calls, [call()])