auth: Log when a user tries to login with deactivated account.

Helps to see if users are often trying to login with deactived
accounts.
A use case: Trackdown whether any deactivated bot users are still
trying to access the API.

This implementation adds a new key `inactive_user_id`
to `return_data` in the function `is_user_active` which
check if a `user_profile` is active. This reduces the effort
of getting `user_id` just before logging.

Modified tests for line coverage.
This commit is contained in:
Dinesh
2020-05-20 02:06:51 +05:30
committed by Tim Abbott
parent 91c7ea2275
commit 288921d425
2 changed files with 12 additions and 5 deletions

View File

@@ -887,11 +887,14 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase):
# We expect to go through the "choose email" screen here,
# because there won't be an existing user account we can
# auto-select for the user.
result = self.social_auth_test(account_data_dict,
expect_choose_email_screen=True,
subdomain='zulip')
self.assertEqual(result.status_code, 302)
self.assertEqual(result.url, "/login/?is_deactivated=true")
with mock.patch('zproject.backends.logging.info') as m:
result = self.social_auth_test(account_data_dict,
expect_choose_email_screen=True,
subdomain='zulip')
self.assertEqual(result.status_code, 302)
self.assertEqual(result.url, "/login/?is_deactivated=true")
m.assert_called_with("Failed login attempt for deactivated account: %s@%s",
user_profile.id, 'zulip')
# TODO: verify whether we provide a clear error message
def test_social_auth_invalid_realm(self) -> None: