mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 16:24:08 -04:00
rename two_factor to two_factor_sms
it's a bit confusing now that there are three endpoints. the other two are already renamed two_factor_email and two_factor_webauthn
This commit is contained in:
@@ -43,7 +43,7 @@ def check_and_resend_verification_code():
|
|||||||
if user.state == 'pending':
|
if user.state == 'pending':
|
||||||
return redirect(url_for('main.verify', next=redirect_url))
|
return redirect(url_for('main.verify', next=redirect_url))
|
||||||
else:
|
else:
|
||||||
return redirect(url_for('main.two_factor', next=redirect_url))
|
return redirect(url_for('main.two_factor_sms', next=redirect_url))
|
||||||
|
|
||||||
|
|
||||||
@main.route('/email-not-received', methods=['GET'])
|
@main.route('/email-not-received', methods=['GET'])
|
||||||
|
|||||||
@@ -49,6 +49,6 @@ def new_password(token):
|
|||||||
else:
|
else:
|
||||||
# send user a 2fa sms code
|
# send user a 2fa sms code
|
||||||
user.send_verify_code()
|
user.send_verify_code()
|
||||||
return redirect(url_for('main.two_factor', next=request.args.get('next')))
|
return redirect(url_for('main.two_factor_sms', next=request.args.get('next')))
|
||||||
else:
|
else:
|
||||||
return render_template('views/new-password.html', token=token, form=form, user=user)
|
return render_template('views/new-password.html', token=token, form=form, user=user)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ def sign_in():
|
|||||||
invited_user.accept_invite()
|
invited_user.accept_invite()
|
||||||
if user and user.sign_in():
|
if user and user.sign_in():
|
||||||
if user.sms_auth:
|
if user.sms_auth:
|
||||||
return redirect(url_for('.two_factor', next=redirect_url))
|
return redirect(url_for('.two_factor_sms', next=redirect_url))
|
||||||
if user.email_auth:
|
if user.email_auth:
|
||||||
return redirect(url_for('.two_factor_email_sent', next=redirect_url))
|
return redirect(url_for('.two_factor_email_sent', next=redirect_url))
|
||||||
if user.webauthn_auth:
|
if user.webauthn_auth:
|
||||||
|
|||||||
@@ -60,9 +60,10 @@ def two_factor_email(token):
|
|||||||
return log_in_user(user_id)
|
return log_in_user(user_id)
|
||||||
|
|
||||||
|
|
||||||
|
@main.route('/two-factor-sms', methods=['GET', 'POST'])
|
||||||
@main.route('/two-factor', methods=['GET', 'POST'])
|
@main.route('/two-factor', methods=['GET', 'POST'])
|
||||||
@redirect_to_sign_in
|
@redirect_to_sign_in
|
||||||
def two_factor():
|
def two_factor_sms():
|
||||||
user_id = session['user_details']['id']
|
user_id = session['user_details']['id']
|
||||||
user = User.from_id(user_id)
|
user = User.from_id(user_id)
|
||||||
|
|
||||||
@@ -79,7 +80,7 @@ def two_factor():
|
|||||||
user_api_client.send_verify_code(user.id, 'email', None, redirect_url)
|
user_api_client.send_verify_code(user.id, 'email', None, redirect_url)
|
||||||
return redirect(url_for('.revalidate_email_sent', next=redirect_url))
|
return redirect(url_for('.revalidate_email_sent', next=redirect_url))
|
||||||
|
|
||||||
return render_template('views/two-factor.html', form=form, redirect_url=redirect_url)
|
return render_template('views/two-factor-sms.html', form=form, redirect_url=redirect_url)
|
||||||
|
|
||||||
|
|
||||||
@main.route('/two-factor-webauthn', methods=['GET'])
|
@main.route('/two-factor-webauthn', methods=['GET'])
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ def verify():
|
|||||||
finally:
|
finally:
|
||||||
session.pop('user_details', None)
|
session.pop('user_details', None)
|
||||||
|
|
||||||
return render_template('views/two-factor.html', form=form)
|
return render_template('views/two-factor-sms.html', form=form)
|
||||||
|
|
||||||
|
|
||||||
@main.route('/verify-email/<token>')
|
@main.route('/verify-email/<token>')
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class HeaderNavigation(Navigation):
|
|||||||
'sign-in': {
|
'sign-in': {
|
||||||
'revalidate_email_sent',
|
'revalidate_email_sent',
|
||||||
'sign_in',
|
'sign_in',
|
||||||
'two_factor',
|
'two_factor_sms',
|
||||||
'two_factor_email',
|
'two_factor_email',
|
||||||
'two_factor_email_sent',
|
'two_factor_email_sent',
|
||||||
'two_factor_email_interstitial',
|
'two_factor_email_interstitial',
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ def test_check_and_redirect_to_two_factor_if_user_active(
|
|||||||
'email': api_user_active['email_address']}
|
'email': api_user_active['email_address']}
|
||||||
response = client.get(url_for('main.check_and_resend_verification_code', next=redirect_url))
|
response = client.get(url_for('main.check_and_resend_verification_code', next=redirect_url))
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('main.two_factor', _external=True, next=redirect_url)
|
assert response.location == url_for('main.two_factor_sms', _external=True, next=redirect_url)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('redirect_url', [
|
@pytest.mark.parametrize('redirect_url', [
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ def test_should_redirect_to_two_factor_when_password_reset_is_successful(
|
|||||||
response = client.post(url_for_endpoint_with_token('.new_password', token=token, next=redirect_url),
|
response = client.post(url_for_endpoint_with_token('.new_password', token=token, next=redirect_url),
|
||||||
data={'new_password': 'a-new_password'})
|
data={'new_password': 'a-new_password'})
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('.two_factor', _external=True, next=redirect_url)
|
assert response.location == url_for('.two_factor_sms', _external=True, next=redirect_url)
|
||||||
mock_get_user_by_email_request_password_reset.assert_called_once_with(user['email_address'])
|
mock_get_user_by_email_request_password_reset.assert_called_once_with(user['email_address'])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,9 @@ def test_process_sms_auth_sign_in_return_2fa_template(
|
|||||||
'email_address': email_address,
|
'email_address': email_address,
|
||||||
'password': password})
|
'password': password})
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('.two_factor', next=redirect_url, _external=True)
|
# TODO: remove this assert once we start defaulting to returning two_factor_sms first
|
||||||
|
assert '/two-factor-sms' not in response.location
|
||||||
|
assert response.location == url_for('.two_factor_sms', next=redirect_url, _external=True)
|
||||||
mock_verify_password.assert_called_with(api_user_active['id'], password)
|
mock_verify_password.assert_called_with(api_user_active['id'], password)
|
||||||
mock_get_user_by_email.assert_called_with('valid@example.gov.uk')
|
mock_get_user_by_email.assert_called_with('valid@example.gov.uk')
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ def test_should_render_two_factor_page(
|
|||||||
'id': api_user_active['id'],
|
'id': api_user_active['id'],
|
||||||
'email': api_user_active['email_address']}
|
'email': api_user_active['email_address']}
|
||||||
mocker.patch('app.user_api_client.get_user', return_value=api_user_active)
|
mocker.patch('app.user_api_client.get_user', return_value=api_user_active)
|
||||||
response = client.get(url_for('main.two_factor', next=redirect_url))
|
response = client.get(url_for('main.two_factor_sms', next=redirect_url))
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
assert page.select_one('main p').text.strip() == (
|
assert page.select_one('main p').text.strip() == (
|
||||||
@@ -86,7 +86,7 @@ def test_should_login_user_and_should_redirect_to_next_url(
|
|||||||
'email': api_user_active['email_address']}
|
'email': api_user_active['email_address']}
|
||||||
api_user_active['email_access_validated_at'] = '2020-01-23T11:35:21.726132Z'
|
api_user_active['email_access_validated_at'] = '2020-01-23T11:35:21.726132Z'
|
||||||
|
|
||||||
response = client.post(url_for('main.two_factor', next='/services/{}'.format(SERVICE_ONE_ID)),
|
response = client.post(url_for('main.two_factor_sms', next='/services/{}'.format(SERVICE_ONE_ID)),
|
||||||
data={'sms_code': '12345'})
|
data={'sms_code': '12345'})
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for(
|
assert response.location == url_for(
|
||||||
@@ -112,7 +112,7 @@ def test_should_send_email_and_redirect_to_info_page_if_user_needs_to_revalidate
|
|||||||
session['user_details'] = {
|
session['user_details'] = {
|
||||||
'id': api_user_active['id'],
|
'id': api_user_active['id'],
|
||||||
'email': api_user_active['email_address']}
|
'email': api_user_active['email_address']}
|
||||||
response = client.post(url_for('main.two_factor', next=f'/services/{SERVICE_ONE_ID}'),
|
response = client.post(url_for('main.two_factor_sms', next=f'/services/{SERVICE_ONE_ID}'),
|
||||||
data={'sms_code': '12345'})
|
data={'sms_code': '12345'})
|
||||||
|
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
@@ -140,7 +140,7 @@ def test_should_login_user_and_not_redirect_to_external_url(
|
|||||||
'email': api_user_active['email_address']}
|
'email': api_user_active['email_address']}
|
||||||
api_user_active['email_access_validated_at'] = '2020-01-23T11:35:21.726132Z'
|
api_user_active['email_access_validated_at'] = '2020-01-23T11:35:21.726132Z'
|
||||||
|
|
||||||
response = client.post(url_for('main.two_factor', next='http://www.google.com'),
|
response = client.post(url_for('main.two_factor_sms', next='http://www.google.com'),
|
||||||
data={'sms_code': '12345'})
|
data={'sms_code': '12345'})
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('main.show_accounts_or_dashboard', _external=True)
|
assert response.location == url_for('main.show_accounts_or_dashboard', _external=True)
|
||||||
@@ -166,7 +166,7 @@ def test_should_login_user_and_redirect_to_show_accounts(
|
|||||||
api_user_active['email_access_validated_at'] = '2020-01-23T11:35:21.726132Z'
|
api_user_active['email_access_validated_at'] = '2020-01-23T11:35:21.726132Z'
|
||||||
api_user_active['platform_admin'] = platform_admin
|
api_user_active['platform_admin'] = platform_admin
|
||||||
|
|
||||||
response = client.post(url_for('main.two_factor'),
|
response = client.post(url_for('main.two_factor_sms'),
|
||||||
data={'sms_code': '12345'})
|
data={'sms_code': '12345'})
|
||||||
|
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
@@ -186,7 +186,7 @@ def test_should_return_200_with_sms_code_error_when_sms_code_is_wrong(
|
|||||||
'email': api_user_active['email_address']}
|
'email': api_user_active['email_address']}
|
||||||
mocker.patch('app.user_api_client.get_user', return_value=api_user_active)
|
mocker.patch('app.user_api_client.get_user', return_value=api_user_active)
|
||||||
|
|
||||||
response = client.post(url_for('main.two_factor'),
|
response = client.post(url_for('main.two_factor_sms'),
|
||||||
data={'sms_code': '23456'})
|
data={'sms_code': '23456'})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert 'Code not found' in response.get_data(as_text=True)
|
assert 'Code not found' in response.get_data(as_text=True)
|
||||||
@@ -208,7 +208,7 @@ def test_should_login_user_when_multiple_valid_codes_exist(
|
|||||||
'email': api_user_active['email_address']}
|
'email': api_user_active['email_address']}
|
||||||
api_user_active['email_access_validated_at'] = '2020-01-23T11:35:21.726132Z'
|
api_user_active['email_access_validated_at'] = '2020-01-23T11:35:21.726132Z'
|
||||||
|
|
||||||
response = client.post(url_for('main.two_factor'),
|
response = client.post(url_for('main.two_factor_sms'),
|
||||||
data={'sms_code': '23456'})
|
data={'sms_code': '23456'})
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ def test_two_factor_should_set_password_when_new_password_exists_in_session(
|
|||||||
'password': 'changedpassword'}
|
'password': 'changedpassword'}
|
||||||
api_user_active['email_access_validated_at'] = '2020-01-23T11:35:21.726132Z'
|
api_user_active['email_access_validated_at'] = '2020-01-23T11:35:21.726132Z'
|
||||||
|
|
||||||
response = client.post(url_for('main.two_factor'),
|
response = client.post(url_for('main.two_factor_sms'),
|
||||||
data={'sms_code': '12345'})
|
data={'sms_code': '12345'})
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('main.show_accounts_or_dashboard', _external=True)
|
assert response.location == url_for('main.show_accounts_or_dashboard', _external=True)
|
||||||
@@ -252,7 +252,7 @@ def test_two_factor_returns_error_when_user_is_locked(
|
|||||||
'id': api_user_locked['id'],
|
'id': api_user_locked['id'],
|
||||||
'email': api_user_locked['email_address'],
|
'email': api_user_locked['email_address'],
|
||||||
}
|
}
|
||||||
response = client.post(url_for('main.two_factor'),
|
response = client.post(url_for('main.two_factor_sms'),
|
||||||
data={'sms_code': '12345'})
|
data={'sms_code': '12345'})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert 'Code not found' in response.get_data(as_text=True)
|
assert 'Code not found' in response.get_data(as_text=True)
|
||||||
@@ -262,13 +262,13 @@ def test_two_factor_post_should_redirect_to_sign_in_if_user_not_in_session(
|
|||||||
client_request,
|
client_request,
|
||||||
):
|
):
|
||||||
client_request.post(
|
client_request.post(
|
||||||
'main.two_factor',
|
'main.two_factor_sms',
|
||||||
_data={'sms_code': '12345'},
|
_data={'sms_code': '12345'},
|
||||||
_expected_redirect=url_for('main.sign_in', _external=True)
|
_expected_redirect=url_for('main.sign_in', _external=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('endpoint', ['main.two_factor_webauthn', 'main.two_factor'])
|
@pytest.mark.parametrize('endpoint', ['main.two_factor_webauthn', 'main.two_factor_sms'])
|
||||||
def test_two_factor_get_should_redirect_to_sign_in_if_user_not_in_session(
|
def test_two_factor_get_should_redirect_to_sign_in_if_user_not_in_session(
|
||||||
client_request,
|
client_request,
|
||||||
endpoint,
|
endpoint,
|
||||||
@@ -296,7 +296,7 @@ def test_two_factor_should_activate_pending_user(
|
|||||||
'id': api_user_pending['id'],
|
'id': api_user_pending['id'],
|
||||||
'email_address': api_user_pending['email_address']
|
'email_address': api_user_pending['email_address']
|
||||||
}
|
}
|
||||||
client.post(url_for('main.two_factor'), data={'sms_code': '12345'})
|
client.post(url_for('main.two_factor_sms'), data={'sms_code': '12345'})
|
||||||
|
|
||||||
assert mock_activate_user.called
|
assert mock_activate_user.called
|
||||||
|
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ EXCLUDED_ENDPOINTS = tuple(map(Navigation.get_endpoint_with_blueprint, {
|
|||||||
'trial_mode',
|
'trial_mode',
|
||||||
'trial_mode_new',
|
'trial_mode_new',
|
||||||
'trial_services',
|
'trial_services',
|
||||||
'two_factor',
|
'two_factor_sms',
|
||||||
'two_factor_email',
|
'two_factor_email',
|
||||||
'two_factor_email_interstitial',
|
'two_factor_email_interstitial',
|
||||||
'two_factor_email_sent',
|
'two_factor_email_sent',
|
||||||
|
|||||||
Reference in New Issue
Block a user