Skip to content

Commit b0f3ff8

Browse files
committed
Emit warning log if inactive user trys to authenticate
1 parent 1c23380 commit b0f3ff8

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

mailauth/backends.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ def authenticate(self, request, token=None):
3232
else:
3333
if self.user_can_authenticate(user):
3434
return user
35+
logger.warning(
36+
"User '%s' is not allowed to authenticate.",
37+
user,
38+
exc_info=True,
39+
)
3540

3641
@classmethod
3742
def get_token(cls, user):

tests/test_backends.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ def test_authenticate(self, db, user, settings, signer, signature):
1212
assert user is not None
1313
assert user.is_authenticated
1414

15+
def test_authenticate__user_is_not_active(
16+
self, db, caplog, user, settings, signer, signature
17+
):
18+
settings.LOGIN_URL_TIMEOUT = float("inf")
19+
backend = MailAuthBackend()
20+
backend.signer = signer
21+
user.is_active = False
22+
user.save(update_fields=['is_active'], force_update=True)
23+
with caplog.at_level(logging.WARNING):
24+
user = backend.authenticate(None, token=signature)
25+
26+
assert user is None
27+
assert caplog.records[-1].levelname == "WARNING"
28+
assert caplog.records[-1].message == (
29+
"User 'spiderman@avengers.com' is not allowed to authenticate."
30+
)
31+
1532
def test_authenticate__user_does_not_exist(
1633
self, db, caplog, settings, signer, signature
1734
):

0 commit comments

Comments
 (0)