From 1908e7b091a5ab72aeab70f07ba50082ea4f06b2 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 9 Feb 2018 15:01:20 +0000 Subject: [PATCH] Tell API what URL to use for email auth links So that we can keep people on the prototype URL when doing user research. Depends on: - [ ] https://github.com/alphagov/notifications-api/pull/1645 --- app/notify_client/user_api_client.py | 3 +++ tests/app/main/views/test_sign_in.py | 1 + tests/app/notify_client/test_user_client.py | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/app/notify_client/user_api_client.py b/app/notify_client/user_api_client.py index 272e19e11..57d9d4260 100644 --- a/app/notify_client/user_api_client.py +++ b/app/notify_client/user_api_client.py @@ -20,6 +20,7 @@ class UserApiClient(NotifyAdminAPIClient): self.service_id = app.config['ADMIN_CLIENT_USER_NAME'] self.api_key = app.config['ADMIN_CLIENT_SECRET'] self.max_failed_login_count = app.config["MAX_FAILED_LOGIN_COUNT"] + self.admin_url = app.config['ADMIN_BASE_URL'] def register_user(self, name, email_address, mobile_number, password, auth_type): data = { @@ -93,6 +94,8 @@ class UserApiClient(NotifyAdminAPIClient): data = {'to': to} if next_string: data['next'] = next_string + if code_type == 'email': + data['email_auth_link_host'] = self.admin_url endpoint = '/user/{0}/{1}-code'.format(user_id, code_type) self.post(endpoint, data=data) diff --git a/tests/app/main/views/test_sign_in.py b/tests/app/main/views/test_sign_in.py index 563d29751..9ede49e8f 100644 --- a/tests/app/main/views/test_sign_in.py +++ b/tests/app/main/views/test_sign_in.py @@ -117,6 +117,7 @@ def test_process_email_auth_sign_in_return_2fa_template( 'password': 'val1dPassw0rd!'}) assert response.status_code == 302 assert response.location == url_for('.two_factor_email_sent', _external=True) + mock_send_verify_code.assert_called_with(api_user_active_email_auth.id, 'email', None) mock_verify_password.assert_called_with(api_user_active_email_auth.id, 'val1dPassw0rd!') diff --git a/tests/app/notify_client/test_user_client.py b/tests/app/notify_client/test_user_client.py index 857f44faa..593e785bd 100644 --- a/tests/app/notify_client/test_user_client.py +++ b/tests/app/notify_client/test_user_client.py @@ -1,5 +1,6 @@ import pytest +from app import user_api_client from app.notify_client.user_api_client import UserApiClient @@ -52,3 +53,21 @@ def test_client_doesnt_activate_if_already_active(mocker, api_user_active): client.activate_user(api_user_active) assert not mock_post.called + + +def test_client_passes_admin_url_when_sending_email_auth( + app_, + mocker, + fake_uuid, +): + mock_post = mocker.patch('app.notify_client.user_api_client.UserApiClient.post') + + user_api_client.send_verify_code(fake_uuid, 'email', 'ignored@example.com') + + mock_post.assert_called_once_with( + '/user/{}/email-code'.format(fake_uuid), + data={ + 'to': 'ignored@example.com', + 'email_auth_link_host': 'http://localhost:6012', + } + )