def test_get_user_command__bad_response(mocker): """ Given: - An Okta IAM client object - A user-profile argument that contains an email of a non-existing user in Okta When: - Calling function get_user_command - A bad response (500) is returned from Okta's API Then: - Ensure the resulted User Profile object holds information about the bad response. """ import demistomock as demisto client = mock_client() args = {'user-profile': {'email': '*****@*****.**'}} bad_response = Response() bad_response.status_code = 500 bad_response._content = b'{"errorCode": "mock_error_code", ' \ b'"errorSummary": "mock_error_summary", ' \ b'"errorCauses": [{"errorSummary": "reason_1"}, ' \ b'{"errorSummary": "reason_2"}]}' mocker.patch.object(demisto, 'error') mocker.patch.object(Session, 'request', return_value=bad_response) user_profile = get_user_command(client, args, 'mapper_in') outputs = get_outputs_from_user_profile(user_profile) assert outputs.get('action') == IAMActions.GET_USER assert outputs.get('success') is False assert outputs.get('errorCode') == 'mock_error_code' assert outputs.get( 'errorMessage' ) == 'mock_error_summary. Reason:\n1. reason_1\n2. reason_2\n'
def test_get_user_command__existing_user(mocker): """ Given: - An Okta IAM client object - A user-profile argument that contains an email of a user When: - The user exists in Okta - Calling function get_user_command Then: - Ensure the resulted User Profile object holds the correct user details """ client = mock_client() args = {'user-profile': {'email': '*****@*****.**'}} mocker.patch.object(client, 'get_user', return_value=OKTA_USER_OUTPUT) mocker.patch.object(IAMUserProfile, 'update_with_app_data', return_value={}) user_profile = get_user_command(client, args, 'mapper_in') outputs = get_outputs_from_user_profile(user_profile) assert outputs.get('action') == IAMActions.GET_USER assert outputs.get('success') is True assert outputs.get('active') is True assert outputs.get('id') == 'mock_id' assert outputs.get('username') == '*****@*****.**' assert outputs.get('details', {}).get('profile', {}).get('firstName') == 'mock_first_name' assert outputs.get('details', {}).get('profile', {}).get('lastName') == 'mock_last_name'
def test_get_user_command__non_existing_user(mocker): """ Given: - An Okta IAM client object - A user-profile argument that contains an email a user When: - The user does not exist in Okta - Calling function get_user_command Then: - Ensure the resulted User Profile object holds information about an unsuccessful result. """ client = mock_client() args = {'user-profile': {'email': '*****@*****.**'}} mocker.patch.object(client, 'get_user', return_value=None) user_profile = get_user_command(client, args, 'mapper_in') outputs = get_outputs_from_user_profile(user_profile) assert outputs.get('action') == IAMActions.GET_USER assert outputs.get('success') is False assert outputs.get('errorCode') == IAMErrors.USER_DOES_NOT_EXIST[0] assert outputs.get('errorMessage') == IAMErrors.USER_DOES_NOT_EXIST[1]