Skip to content

Commit

Permalink
Prevent deleted users from logging in
Browse files Browse the repository at this point in the history
  • Loading branch information
seanh committed May 22, 2024
1 parent 421094c commit a8f8bd3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion h/schemas/forms/accounts/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def validator(self, node, value):
)
raise err from exc

if user is None:
if user is None or user.deleted:
err = colander.Invalid(node)
err["username"] = _("User does not exist.")
raise err
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/h/schemas/forms/accounts/login_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ def test_invalid_with_inactive_user(self, pyramid_csrf_request, user_service):
assert "username" in errors
assert "activate your account" in errors["username"]

def test_invalid_with_deleted_user(
self, pyramid_csrf_request, user_service, factories
):
schema = LoginSchema().bind(request=pyramid_csrf_request)
user_service.fetch_for_login.return_value = factories.User.build(deleted=True)

with pytest.raises(colander.Invalid) as exc:
schema.deserialize({"username": "jeannie", "password": "cake"})

errors = exc.value.asdict()
assert "username" in errors
assert "does not exist" in errors["username"]

def test_invalid_with_unknown_user(self, pyramid_csrf_request, user_service):
schema = LoginSchema().bind(request=pyramid_csrf_request)
user_service.fetch_for_login.return_value = None
Expand Down

0 comments on commit a8f8bd3

Please sign in to comment.