mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 13:39:41 -04:00
Changed registration flow to first send email verification link that
when visited sends sms code for second step of account verification. At that second step user enters just sms code sent to users mobile number. Also moved dao calls that simply proxied calls to client to calling client directly. There is still a place where a user will be a sent a code for verification to their email namely if they update email address.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from flask import url_for
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
def test_should_return_verify_template(app_,
|
||||
api_user_active,
|
||||
@@ -12,26 +14,28 @@ def test_should_return_verify_template(app_,
|
||||
session['user_details'] = {'email_address': api_user_active.email_address, 'id': api_user_active.id}
|
||||
response = client.get(url_for('main.verify'))
|
||||
assert response.status_code == 200
|
||||
assert (
|
||||
"We’ve sent you confirmation codes by email and text message."
|
||||
) in response.get_data(as_text=True)
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.h1.text == 'Text verification'
|
||||
assert page.p.text == "We've sent you a text message with a verification code."
|
||||
|
||||
|
||||
def test_should_redirect_to_add_service_when_code_are_correct(app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_update_user,
|
||||
mock_check_verify_code):
|
||||
def test_should_redirect_to_add_service_when_sms_code_is_correct(app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_update_user,
|
||||
mock_check_verify_code):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
session['user_details'] = {'email_address': api_user_active.email_address, 'id': api_user_active.id}
|
||||
response = client.post(url_for('main.verify'),
|
||||
data={'sms_code': '12345',
|
||||
'email_code': '23456'})
|
||||
data={'sms_code': '12345'})
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.add_service', first='first', _external=True)
|
||||
|
||||
mock_check_verify_code.assert_called_once_with(api_user_active.id, '12345', 'sms')
|
||||
|
||||
|
||||
def test_should_activate_user_after_verify(app_,
|
||||
api_user_active,
|
||||
@@ -44,45 +48,20 @@ def test_should_activate_user_after_verify(app_,
|
||||
with client.session_transaction() as session:
|
||||
session['user_details'] = {'email_address': api_user_active.email_address, 'id': api_user_active.id}
|
||||
client.post(url_for('main.verify'),
|
||||
data={'sms_code': '12345',
|
||||
'email_code': '23456'})
|
||||
data={'sms_code': '12345'})
|
||||
assert mock_update_user.called
|
||||
|
||||
|
||||
def test_should_return_200_when_codes_are_wrong(app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_check_verify_code_code_not_found):
|
||||
def test_should_return_200_when_sms_code_is_wrong(app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_check_verify_code_code_not_found):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
session['user_details'] = {'email_address': api_user_active.email_address, 'id': api_user_active.id}
|
||||
response = client.post(url_for('main.verify'),
|
||||
data={'sms_code': '12345',
|
||||
'email_code': '23456'})
|
||||
data={'sms_code': '12345'})
|
||||
assert response.status_code == 200
|
||||
resp_data = response.get_data(as_text=True)
|
||||
assert resp_data.count('Code not found') == 2
|
||||
|
||||
|
||||
def test_should_only_check_codes_in_validation_if_both_are_present(app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_update_user,
|
||||
mock_check_verify_code):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
session['user_details'] = {'email_address': api_user_active.email_address, 'id': api_user_active.id}
|
||||
response = client.post(url_for('main.verify'), data={'sms_code': '12345'})
|
||||
assert response.status_code == 200
|
||||
assert not mock_check_verify_code.called
|
||||
|
||||
response = client.post(url_for('main.verify'), data={'email_code': '12345'})
|
||||
assert response.status_code == 200
|
||||
assert not mock_check_verify_code.called
|
||||
|
||||
response = client.post(url_for('main.verify'), data={'sms_code': '12345', 'email_code': '12345'})
|
||||
assert response.status_code == 302
|
||||
assert mock_check_verify_code.called
|
||||
assert mock_check_verify_code.call_count == 2
|
||||
assert resp_data.count('Code not found') == 1
|
||||
|
||||
Reference in New Issue
Block a user