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.

auth: Fix 500 on signup with a long external auth method name.

Mateusz Manderad2b2ae092eae
diff --git a/zerver/migrations/0813_alter_preregistrationuser_external_auth_id_and_more.py b/zerver/migrations/0813_alter_preregistrationuser_external_auth_id_and_more.py
new file mode 100644
index 00000000000..a12afe99b31
--- /dev/null
+++ b/zerver/migrations/0813_alter_preregistrationuser_external_auth_id_and_more.py
@@ -0,0 +1,22 @@
+# Generated by Django 5.2.18 on 2026-10-23 16:48
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("zerver", "0812_delete_inaccessible_user_topics"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="preregistrationuser",
+ name="external_auth_id",
+ field=models.TextField(default=None, null=True),
+ ),
+ migrations.AlterField(
+ model_name="preregistrationuser",
+ name="external_auth_method_name",
+ field=models.TextField(default=None, null=True),
+ ),
+ ]
diff --git a/zerver/models/prereg_users.py b/zerver/models/prereg_users.py
index f65ad91e97d..87988c5952a 100644
--- a/zerver/models/prereg_users.py
+++ b/zerver/models/prereg_users.py
@@ -124,11 +124,11 @@ class PreregistrationUser(models.Model):
# email was not found.
is_realm_importer = models.BooleanField(default=False)
- # Used in the SAML authentication flow to pass the external auth ID
+ # Used in certain authentication flows to pass the external auth ID
# from the authentication step to user creation, so that an ExternalAuthID
# record can be created for the new user.
- external_auth_method_name = models.CharField(max_length=100, null=True, default=None)
- external_auth_id = models.CharField(max_length=255, null=True, default=None)
+ external_auth_method_name = models.TextField(db_index=False, null=True, default=None)
+ external_auth_id = models.TextField(db_index=False, null=True, default=None)
class Meta:
indexes = [
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py
index c8dec4c62ec..2e682dac340 100644
--- a/zerver/tests/test_auth_backends.py
+++ b/zerver/tests/test_auth_backends.py
@@ -5704,9 +5704,14 @@ class GenericOpenIdConnectTest(SocialAuthBaseWithSyncAttrTest):
idps_config_dict = copy.deepcopy(settings.SOCIAL_AUTH_OIDC_ENABLED_IDPS)
idps_config_dict["testoidc"]["enable_external_auth_id_auth"] = True
sub_value = "newuser_sub"
+ # The method name includes the issuer URL, which can be long.
+ issuer = (
+ "https://sso.engineering.example-university.edu/realms/department-of-computer-science"
+ )
account_data_dict = self.get_account_data_dict(email=email, name=name)
account_data_dict["sub"] = sub_value
+ account_data_dict["iss"] = issuer
with self.settings(SOCIAL_AUTH_OIDC_ENABLED_IDPS=idps_config_dict):
result = self.social_auth_test(
account_data_dict,
@@ -5728,7 +5733,7 @@ class GenericOpenIdConnectTest(SocialAuthBaseWithSyncAttrTest):
self.assert_length(external_auth_ids, 1)
self.assertEqual(
external_auth_ids[0].external_auth_method_name,
- f"oidc:<testoidc>:<{self.BASE_OIDC_URL}>",
+ f"oidc:<testoidc>:<{issuer}>",
)
self.assertEqual(external_auth_ids[0].external_auth_id, sub_value)