From 485d740fe89e9e253ad77cc2ac6021059f026341 Mon Sep 17 00:00:00 2001 From: palash Date: Tue, 14 Jul 2020 22:48:28 +0530 Subject: [PATCH] apple auth: Change logger to zulip.auth.apple from root logger. Replace default root logger with zulip.auth.apple for apple auth in file zproject/backends.py and update the test cases accordingly in file zerver/tests/test_auth_backends.py --- zerver/tests/test_auth_backends.py | 15 +++++++++------ zproject/backends.py | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index 3966c7d182..f0d6269935 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -2310,24 +2310,24 @@ class AppleAuthBackendNativeFlowTest(AppleAuthMixin, SocialAuthBase): result = self.client_get(url, **headers) self.assertEqual(result.status_code, 302) - with self.assertLogs(level='INFO') as info_log: + with self.assertLogs(self.logger_string, level='INFO') as info_log: # Start Apple auth with mobile_flow_otp param. It should get saved into the session # on SOCIAL_AUTH_SUBDOMAIN. initiate_auth(mobile_flow_otp) self.assertEqual(self.client.session['mobile_flow_otp'], mobile_flow_otp) self.assertEqual(info_log.output, [ - 'INFO:root:/complete/apple/: Authentication failed: Token validation failed' + self.logger_output("/complete/apple/: Authentication failed: Token validation failed", "info") ]) - with self.assertLogs(level='INFO') as info_log: + with self.assertLogs(self.logger_string, level='INFO') as info_log: # Make a request without mobile_flow_otp param and verify the field doesn't persist # in the session from the previous request. initiate_auth() self.assertEqual(self.client.session.get('mobile_flow_otp'), None) self.assertEqual(info_log.output, [ - 'INFO:root:/complete/apple/: Authentication failed: Token validation failed' + self.logger_output("/complete/apple/: Authentication failed: Token validation failed", "info") ]) def test_id_token_with_invalid_aud_sent(self) -> None: @@ -2337,9 +2337,12 @@ class AppleAuthBackendNativeFlowTest(AppleAuthMixin, SocialAuthBase): id_token=self.generate_id_token(account_data_dict, audience='com.different.app'), ) - with self.apple_jwk_url_mock(), self.assertLogs(level='INFO') as m: + with self.apple_jwk_url_mock(), self.assertLogs(self.logger_string, level='INFO') as m: result = self.client_get(url, **headers) - self.assertEqual(m.output, ["INFO:root:/complete/apple/: {}".format("Authentication failed: Token validation failed")]) + + self.assertEqual(m.output, [ + self.logger_output("/complete/apple/: Authentication failed: Token validation failed", "info") + ]) return result def test_social_auth_desktop_success(self) -> None: diff --git a/zproject/backends.py b/zproject/backends.py index 8ee19e16a7..e87926e719 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -1673,7 +1673,7 @@ class AppleAuthBackend(SocialAuthMixin, AppleIdAuth): # though AuthFailed would have been more correct. # # We have an open PR to python-social-auth to clean this up. - logging.info("/complete/apple/: %s", str(e)) + self.logger.info("/complete/apple/: %s", str(e)) return None @external_auth_method