mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 05:59:44 -04:00
109526036: Persist the verify code to the db.
The codes are hashed and saved to the db. The code is marked as used once a valid code is submitted. The code is valid for 1 hour. The codes are no longer saved to the session.
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
from flask import json
|
||||
|
||||
from app.main.encryption import hashpw
|
||||
from tests.app.main.views import create_test_user
|
||||
from app.main.dao import verify_codes_dao
|
||||
from tests.app.main import create_test_user
|
||||
|
||||
|
||||
def test_should_render_two_factor_page(notifications_admin, notifications_admin_db):
|
||||
def test_should_render_two_factor_page(notifications_admin, notifications_admin_db, notify_db_session):
|
||||
response = notifications_admin.test_client().get('/two-factor')
|
||||
assert response.status_code == 200
|
||||
assert '''We've sent you a text message with a verification code.''' in response.get_data(as_text=True)
|
||||
|
||||
|
||||
def test_should_login_user_and_redirect_to_dashboard(notifications_admin, notifications_admin_db):
|
||||
def test_should_login_user_and_redirect_to_dashboard(notifications_admin, notifications_admin_db, notify_db_session):
|
||||
with notifications_admin.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
user = create_test_user()
|
||||
session['user_id'] = user.id
|
||||
session['sms_code'] = hashpw('12345')
|
||||
verify_codes_dao.add_code(user_id=user.id, code='12345', code_type='sms')
|
||||
response = client.post('/two-factor',
|
||||
data={'sms_code': '12345'})
|
||||
|
||||
@@ -23,35 +23,37 @@ def test_should_login_user_and_redirect_to_dashboard(notifications_admin, notifi
|
||||
assert response.location == 'http://localhost/dashboard'
|
||||
|
||||
|
||||
def test_should_return_400_with_sms_code_error_when_sms_code_is_wrong(notifications_admin, notifications_admin_db):
|
||||
def test_should_return_400_with_sms_code_error_when_sms_code_is_wrong(notifications_admin,
|
||||
notifications_admin_db,
|
||||
notify_db_session):
|
||||
with notifications_admin.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
user = create_test_user()
|
||||
session['user_id'] = user.id
|
||||
session['sms_code'] = hashpw('12345')
|
||||
verify_codes_dao.add_code(user_id=user.id, code='12345', code_type='sms')
|
||||
response = client.post('/two-factor',
|
||||
data={'sms_code': '23456'})
|
||||
assert response.status_code == 400
|
||||
assert {'sms_code': ['Code does not match']} == json.loads(response.get_data(as_text=True))
|
||||
|
||||
|
||||
def test_should_return_400_when_sms_code_is_empty(notifications_admin, notifications_admin_db):
|
||||
def test_should_return_400_when_sms_code_is_empty(notifications_admin, notifications_admin_db, notify_db_session):
|
||||
with notifications_admin.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
user = create_test_user()
|
||||
session['user_id'] = user.id
|
||||
session['sms_code'] = hashpw('12345')
|
||||
verify_codes_dao.add_code(user_id=user.id, code='12345', code_type='sms')
|
||||
response = client.post('/two-factor')
|
||||
assert response.status_code == 400
|
||||
assert {'sms_code': ['Please enter your code']} == json.loads(response.get_data(as_text=True))
|
||||
|
||||
|
||||
def test_should_return_400_when_sms_code_is_too_short(notifications_admin, notifications_admin_db):
|
||||
def test_should_return_400_when_sms_code_is_too_short(notifications_admin, notifications_admin_db, notify_db_session):
|
||||
with notifications_admin.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
user = create_test_user()
|
||||
session['user_id'] = user.id
|
||||
session['sms_code'] = hashpw('23467')
|
||||
verify_codes_dao.add_code(user_id=user.id, code='23467', code_type='sms')
|
||||
response = client.post('/two-factor', data={'sms_code': '2346'})
|
||||
assert response.status_code == 400
|
||||
data = json.loads(response.get_data(as_text=True))
|
||||
|
||||
Reference in New Issue
Block a user