Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
registration: Don't ask externally-verified users for LDAP password.
Mateusz Manderae51cc28c6645
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.pyindex 4f31fe8100b..7a1b2babeed 100644--- a/zerver/tests/test_auth_backends.py+++ b/zerver/tests/test_auth_backends.py@@ -1461,7 +1461,7 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase, ABC):self.assert_in_response("Enter your account details to complete registration.", result)# Verify that the user is asked for name but not password- self.assert_not_in_success_response(["id_password"], result)+ self.assert_not_in_success_response(["id_password", "ldap-password"], result)self.assert_in_success_response(["id_full_name"], result)if expect_full_name_prepopulated:# Verify the name field gets correctly pre-populated:@@ -1968,6 +1968,54 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase, ABC):skip_registration_form=True,)+ @override_settings(TERMS_OF_SERVICE_VERSION="1.0")+ def test_social_auth_with_ldap_auth_registration_user_in_ldap_with_form(self) -> None:+ """+ Like test_social_auth_with_ldap_auth_registration_user_in_ldap, but with+ a Terms of Service version set, so that+ the registration form is displayed instead of being skipped. The form+ should not prompt the user for their LDAP password, since their+ identity was already verified by the social backend and any password+ entered would be ignored.+ """+ self.init_default_ldap_database()+ email = "[email protected]"+ name = "Social Fullname"+ # The name of this user in the LDAP directory, which is expected+ # to take precedence over the name provided by the social backend.+ ldap_name = "New LDAP fullname"+ realm = get_realm("zulip")+ subdomain = "zulip"+ ldap_user_attr_map = {"full_name": "cn"}++ backend_path = f"zproject.backends.{self.BACKEND_CLASS.__name__}"+ with self.settings(+ POPULATE_PROFILE_VIA_LDAP=True,+ LDAP_EMAIL_ATTR="mail",+ AUTH_LDAP_USER_ATTR_MAP=ldap_user_attr_map,+ AUTHENTICATION_BACKENDS=(+ backend_path,+ "zproject.backends.ZulipLDAPAuthBackend",+ "zproject.backends.ZulipDummyBackend",+ ),+ ):+ account_data_dict = self.get_account_data_dict(email=email, name=name)+ result = self.social_auth_test(+ account_data_dict,+ expect_choose_email_screen=True,+ subdomain=subdomain,+ is_signup=True,+ )+ self.stage_two_of_registration(+ result,+ realm,+ subdomain,+ email,+ name,+ ldap_name,+ skip_registration_form=False,+ )+def test_social_auth_complete(self) -> None:def mock_process_error(backend: BaseOAuth2, data: Mapping[str, object]) -> None:raise AuthFailed(backend, "Not found")diff --git a/zerver/views/registration.py b/zerver/views/registration.pyindex 11f3c92ee30..1ce92c9d843 100644--- a/zerver/views/registration.py+++ b/zerver/views/registration.py@@ -584,7 +584,13 @@ def registration_helper(# requires that LDAP accounts enter their LDAP# password to register, or ZulipLDAPUserPopulator,# which just populates UserProfile fields (no auth).- require_ldap_password = isinstance(backend, ZulipLDAPAuthBackend)+ #+ # If the user is signing up via an external auth method,+ # their identity has already been verified and password_required+ # is set to False.+ require_ldap_password = (+ isinstance(backend, ZulipLDAPAuthBackend) and password_required+ )breakinitial_data = {}