mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-16 19:30:51 -04:00
Record and persist failed login count on api.
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
from sqlalchemy.exc import DataError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
import pytest
|
||||
from app.dao.users_dao import (
|
||||
save_model_user, get_model_users, delete_model_user)
|
||||
save_model_user,
|
||||
get_model_users,
|
||||
delete_model_user,
|
||||
increment_failed_login_count
|
||||
)
|
||||
|
||||
from tests.app.conftest import sample_user as create_sample_user
|
||||
from app.models import User
|
||||
|
||||
@@ -60,3 +67,10 @@ def test_delete_users(notify_api, notify_db, notify_db_session, sample_user):
|
||||
assert User.query.count() == 1
|
||||
delete_model_user(sample_user)
|
||||
assert User.query.count() == 0
|
||||
|
||||
|
||||
def test_increment_failed_login_should_increment_failed_logins(notify_api, notify_db, notify_db_session, sample_user):
|
||||
assert User.query.count() == 1
|
||||
assert sample_user.failed_login_count == 0
|
||||
increment_failed_login_count(sample_user)
|
||||
assert sample_user.failed_login_count == 1
|
||||
|
||||
@@ -182,6 +182,9 @@ def test_user_verify_password_invalid_password(notify_api,
|
||||
path=url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
|
||||
assert sample_user.failed_login_count == 0
|
||||
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
data=data,
|
||||
@@ -189,6 +192,7 @@ def test_user_verify_password_invalid_password(notify_api,
|
||||
assert resp.status_code == 400
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert 'Incorrect password' in json_resp['message']['password']
|
||||
assert sample_user.failed_login_count == 1
|
||||
|
||||
|
||||
def test_user_verify_password_missing_password(notify_api,
|
||||
|
||||
Reference in New Issue
Block a user