Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
auth: Treat emails case-insensitively in ExternalAuthResult.
Mateusz Mandera15752067dc19
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.pyindex d5475fe4eb7..6041b0b9a68 100644--- a/zerver/tests/test_auth_backends.py+++ b/zerver/tests/test_auth_backends.py@@ -3660,6 +3660,14 @@ class TestZulipRemoteUserBackend(DesktopFlowTestingLib, ZulipTestCase):self.assertEqual(result.status_code, 302)self.assert_logged_in_user_id(user_profile.id)+ def test_login_case_insensitive(self) -> None:+ user_profile = self.example_user('hamlet')+ email_upper = user_profile.delivery_email.upper()+ with self.settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipRemoteUserBackend',)):+ result = self.client_get('/accounts/login/sso/', REMOTE_USER=email_upper)+ self.assertEqual(result.status_code, 302)+ self.assert_logged_in_user_id(user_profile.id)+def test_login_failure(self) -> None:email = self.example_email("hamlet")result = self.client_get('/accounts/login/sso/', REMOTE_USER=email)diff --git a/zproject/backends.py b/zproject/backends.pyindex a95b347e793..cad8d397a03 100644--- a/zproject/backends.py+++ b/zproject/backends.py@@ -985,7 +985,7 @@ class ExternalAuthResult:if self.user_profile is not None:# Ensure data inconsistent with the user_profile wasn't passed in inside the data_dict argument.assert 'full_name' not in data_dict or data_dict['full_name'] == self.user_profile.full_name- assert 'email' not in data_dict or data_dict['email'] == self.user_profile.delivery_email+ assert 'email' not in data_dict or data_dict['email'].lower() == self.user_profile.delivery_email.lower()# Update these data_dict fields to ensure consistency with self.user_profile. This is mostly# defensive code, but is useful in these scenarios:# 1. user_profile argument was passed in, and no full_name or email_data in the data_dict arg.