def enroll(self, user_id, phone_number=None, factor_type='sms', provider='OKTA'): assert user_id assert (phone_number and factor_type == 'sms') or \ (not phone_number and factor_type != 'sms') assert factor_type assert provider self._logger.info('Enrolling Okta user %s in %s factor', user_id, factor_type) data = self.create_factor_object(provider=provider, factor_type=factor_type, phone_number=phone_number) route = '/api/v1/users/{}/factors'.format(user_id) if factor_type == 'sms': route += '?updatePhone=true' # noinspection PyArgumentList response, status_code = self._api_client.post(route, data=serialize(data)) result = _validate(response, status_code) if 'totp' in factor_type: result = (*result, {}) if result[0]: # result[0] is success result[-1]['shared_secret'] = _get_shared_secret_from_response( response) result[-1]['qr_code'] = _get_qr_code_from_response(response) return result
def test_serialize(self): object_dict = {'firstName': 'Test', 'lastName': 'Test last'} json_str1 = '"firstName": "Test"' json_str2 = '"lastName": "Test last"' serialized_str = serialize(object_dict) self.assertIn(json_str1, serialized_str) self.assertIn(json_str2, serialized_str)
def enroll(self, user_id, phone_number=None, factor_type='sms', provider='OKTA'): assert user_id assert (phone_number and factor_type == 'sms') or (not phone_number and factor_type != 'sms') assert factor_type assert provider data = self.create_factor_object(provider=provider, factor_type=factor_type, phone_number=phone_number) route = '/api/v1/users/{}/factors'.format(user_id) if factor_type == 'sms': route += '?updatePhone=true' # noinspection PyArgumentList response, status_code = self._api_client.post(route, data=serialize(data)) result = _validate(response, status_code) if 'totp' in factor_type: result = (*result, {}) if result[0]: # result[0] is success result[-1]['shared_secret'] = _get_shared_secret_from_response(response) result[-1]['qr_code'] = _get_qr_code_from_response(response) return result
def test_serialize_object(self): """Ensure that the serializer throws an error for an unserializable object""" test_obj = self.TestObject(prop1='x', prop2=1234) with self.assertRaises(TypeError): serialize(test_obj)
def test_serialize_none(self): """Ensure that None gets serialized to 'null'""" self.assertEqual(serialize(None), 'null')
def test_serialize_string(self): """Ensure that quotes are properly escaped""" string = 'This is a "string" with \'quotes.\'' json_string = '"{}"'.format(string.replace('"', '\\"')) self.assertEqual(serialize(string), json_string)
def v(factor_id): route = '/api/v1/users/{}/factors/{}/verify'.format(user_id, factor_id) # noinspection PyArgumentList return _validate(*self._api_client.post(route, data=serialize({'passCode': passcode})))
def v(factor_id): route = '/api/v1/users/{}/factors/{}/lifecycle/activate?sendEmail=false'.format(user_id, factor_id) # noinspection PyArgumentList return _validate(*self._api_client.post(route, data=serialize({'passCode': passcode})))
def v(factor_id): route = '/api/v1/users/{}/factors/{}/verify'.format( user_id, factor_id) # noinspection PyArgumentList return _validate(*self._api_client.post( route, data=serialize({'passCode': passcode})))
def v(factor_id): route = '/api/v1/users/{}/factors/{}/lifecycle/activate?sendEmail=false'.format( user_id, factor_id) # noinspection PyArgumentList return _validate(*self._api_client.post( route, data=serialize({'passCode': passcode})))