Add a limit to the number of active 2fa codes that we create. At the moment that is set to 10.

This commit is contained in:
Rebecca Law
2017-02-15 16:18:05 +00:00
parent 9de88c50ba
commit 52342afe3f
5 changed files with 44 additions and 3 deletions

View File

@@ -14,8 +14,8 @@ from app.dao.users_dao import (
reset_failed_login_count,
get_user_by_email,
delete_codes_older_created_more_than_a_day_ago,
update_user_password
)
update_user_password,
count_user_verify_codes)
from app.models import User, VerifyCode
@@ -140,3 +140,8 @@ def test_update_user_password(notify_api, notify_db, notify_db_session, sample_u
assert not sample_user.check_password(password)
update_user_password(sample_user, password)
assert sample_user.check_password(password)
def test_count_user_verify_codes(sample_user):
[make_verify_code(sample_user) for i in range(5)]
assert count_user_verify_codes(sample_user) == 5

View File

@@ -249,6 +249,28 @@ def test_send_sms_code_returns_404_for_bad_input_data(client):
assert json.loads(resp.get_data(as_text=True))['message'] == 'No result found'
def test_send_sms_code_returns_204_when_too_many_codes_already_created(client, sample_user):
for i in range(10):
verify_code = VerifyCode(
code_type='sms',
_code=12345,
created_at=datetime.utcnow() - timedelta(minutes=10),
expiry_datetime=datetime.utcnow(),
user=sample_user
)
db.session.add(verify_code)
db.session.commit()
assert VerifyCode.query.count() == 10
data = json.dumps({})
auth_header = create_authorization_header()
resp = client.post(
url_for('user.send_user_sms_code', user_id=sample_user.id),
data=data,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 204
assert VerifyCode.query.count() == 10
def test_send_user_email_verification(client,
sample_user,
mocker,