From 1faebecb7a0efc043f4d1219429edbbcc004241c Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Thu, 9 Sep 2021 20:06:43 +0200 Subject: [PATCH] auth: Change the logger for authing to the wrong subdomain situations. It's better to use zulip.auth logger here instead of the root logger. Also the level is adjusted to INFO, since WARNING is excessive. --- zerver/forms.py | 4 +++- zerver/tests/test_signup.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/zerver/forms.py b/zerver/forms.py index 12691fc5ac..adae81ce60 100644 --- a/zerver/forms.py +++ b/zerver/forms.py @@ -413,6 +413,8 @@ class CreateUserForm(forms.Form): class OurAuthenticationForm(AuthenticationForm): + logger = logging.getLogger("zulip.auth.OurAuthenticationForm") + def clean(self) -> Dict[str, Any]: username = self.cleaned_data.get("username") password = self.cleaned_data.get("password") @@ -459,7 +461,7 @@ class OurAuthenticationForm(AuthenticationForm): raise ValidationError(error_message) if return_data.get("invalid_subdomain"): - logging.warning( + self.logger.info( "User attempted password login to wrong subdomain %s. Matching accounts: %s", subdomain, return_data.get("matching_user_ids_in_different_realms"), diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 14b47a45b4..a26d1dbb26 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -823,13 +823,13 @@ class LoginTest(ZulipTestCase): def test_login_wrong_subdomain(self) -> None: user_profile = self.mit_user("sipbtest") email = user_profile.delivery_email - with self.assertLogs(level="WARNING") as m: + with self.assertLogs("zulip.auth.OurAuthenticationForm", level="INFO") as m: result = self.login_with_return(email, "xxx") matching_accounts_dict = {"realm_id": user_profile.realm_id, "id": user_profile.id} self.assertEqual( m.output, [ - f"WARNING:root:User attempted password login to wrong subdomain zulip. Matching accounts: [{matching_accounts_dict}]" + f"INFO:zulip.auth.OurAuthenticationForm:User attempted password login to wrong subdomain zulip. Matching accounts: [{matching_accounts_dict}]" ], ) self.assertEqual(result.status_code, 200)