Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

oidc: Don't raise AssertionError if no name is provided.

Mateusz Manderad5a784a1cae3
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py
index ae849527550..9c3c6417990 100644
--- a/zerver/tests/test_auth_backends.py
+++ b/zerver/tests/test_auth_backends.py
@@ -3336,13 +3336,21 @@ class GenericOpenIdConnectTest(SocialAuthBase):
}
)
- def get_account_data_dict(self, email: str, name: str) -> Dict[str, Any]:
+ def get_account_data_dict(self, email: str, name: Optional[str]) -> Dict[str, Any]:
+ if name is not None:
+ name_parts = name.split(" ")
+ given_name = name_parts[0]
+ family_name = name_parts[1]
+ else:
+ given_name = None
+ family_name = None
+
return dict(
email=email,
name=name,
nickname="somenickname",
- given_name=name.split(" ")[0],
- family_name=name.split(" ")[1],
+ given_name=given_name,
+ family_name=family_name,
)
@override_settings(TERMS_OF_SERVICE_VERSION=None)
@@ -3377,6 +3385,28 @@ class GenericOpenIdConnectTest(SocialAuthBase):
expect_confirm_registration_page=False,
)
+ def test_auth_registration_with_no_name_provided(self) -> None:
+ """
+ The OIDC IdP may not send the name information. The
+ signup flow should proceed normally, without pre-filling the name in the
+ registration form.
+ """
+ email = "[email protected]"
+ subdomain = "zulip"
+ realm = get_realm("zulip")
+ account_data_dict = self.get_account_data_dict(email=email, name=None)
+ result = self.social_auth_test(account_data_dict, subdomain=subdomain, is_signup=True)
+ self.stage_two_of_registration(
+ result,
+ realm,
+ subdomain,
+ email,
+ "",
+ "Full Name",
+ skip_registration_form=False,
+ expect_full_name_prepopulated=False,
+ )
+
def test_social_auth_no_key(self) -> None:
"""
Requires overriding because client key/secret are configured
diff --git a/zproject/backends.py b/zproject/backends.py
index 9748895d014..3f62b02b554 100644
--- a/zproject/backends.py
+++ b/zproject/backends.py
@@ -1557,14 +1557,17 @@ def social_associate_user_helper(
full_name = kwargs["details"].get("fullname")
first_name = kwargs["details"].get("first_name")
last_name = kwargs["details"].get("last_name")
+
if all(name is None for name in [full_name, first_name, last_name]) and backend.name not in [
"apple",
"saml",
+ "oidc",
]:
# (1) Apple authentication provides the user's name only the very first time a user tries to log in.
# So if the user aborts login or otherwise is doing this the second time,
# we won't have any name data.
- # (2) Some IdPs may not send any name value if the user doesn't have them set in the IdP's directory.
+ # (2) Some SAML or OIDC IdPs may not send any name value if the user doesn't
+ # have them set in the IdP's directory.
#
# The name will just default to the empty string in the code below.