Skip to content

Commit 394259b

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

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

mailauth/backends.py

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

3637
@classmethod
3738
def get_token(cls, user):

tests/test_backends.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ 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(self, db, caplog, user, settings, signer, signature):
16+
settings.LOGIN_URL_TIMEOUT = float("inf")
17+
backend = MailAuthBackend()
18+
backend.signer = signer
19+
user.is_active = False
20+
user.save(update_fields=['is_active'], force_update=True)
21+
with caplog.at_level(logging.WARNING):
22+
user = backend.authenticate(None, token=signature)
23+
24+
assert user is None
25+
assert caplog.records[-1].levelname == "WARNING"
26+
assert caplog.records[-1].message == (
27+
"User 'spiderman@avengers.com' is not allowed to authenticate."
28+
)
29+
1530
def test_authenticate__user_does_not_exist(
1631
self, db, caplog, settings, signer, signature
1732
):

0 commit comments

Comments
 (0)