mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
108536490: Fix bug when user does not exist and tries to sign in
This commit is contained in:
@@ -20,12 +20,12 @@ def process_sign_in():
|
|||||||
form = LoginForm()
|
form = LoginForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
user = users_dao.get_user_by_email(form.email_address.data)
|
user = users_dao.get_user_by_email(form.email_address.data)
|
||||||
|
if user is None:
|
||||||
|
return jsonify(authorization=False), 401
|
||||||
if user.is_locked():
|
if user.is_locked():
|
||||||
return jsonify(locked_out=True), 401
|
return jsonify(locked_out=True), 401
|
||||||
if not user.is_active():
|
if not user.is_active():
|
||||||
return jsonify(active_user=False), 401
|
return jsonify(active_user=False), 401
|
||||||
if user is None:
|
|
||||||
return jsonify(authorization=False), 401
|
|
||||||
if checkpw(form.password.data, user.password):
|
if checkpw(form.password.data, user.password):
|
||||||
login_user(user)
|
login_user(user)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -79,3 +79,11 @@ def test_should_return_active_user_is_false_if_user_is_inactive(notifications_ad
|
|||||||
|
|
||||||
assert response.status_code == 401
|
assert response.status_code == 401
|
||||||
assert '"active_user": false' in response.get_data(as_text=True)
|
assert '"active_user": false' in response.get_data(as_text=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_return_401_when_user_does_not_exist(notifications_admin, notifications_admin_db):
|
||||||
|
response = notifications_admin.test_client().post('/sign-in',
|
||||||
|
data={'email_address': 'does_not_exist@gov.uk',
|
||||||
|
'password': 'doesNotExist!'})
|
||||||
|
|
||||||
|
assert response.status_code == 401
|
||||||
|
|||||||
Reference in New Issue
Block a user