Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
auth: Pass `None` as `default_subdomain` to verify the host.
Aman Agrawalf4dd3aa066b3
diff --git a/zerver/lib/subdomains.py b/zerver/lib/subdomains.pyindex 57aaad48437..5de74366491 100644--- a/zerver/lib/subdomains.py+++ b/zerver/lib/subdomains.py@@ -34,7 +34,7 @@ def get_subdomain_from_hostname(m = re.search(rf"\.{settings.EXTERNAL_HOST}(:\d+)?$", host)if m:subdomain = host[: m.start()]- if subdomain in settings.ROOT_SUBDOMAIN_ALIASES:+ if default_subdomain is not None and subdomain in settings.ROOT_SUBDOMAIN_ALIASES:return default_subdomainreturn subdomaindiff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 2bdc030dfb5..a79818804d6 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -184,16 +184,16 @@ class DeactivationNoticeTestCase(ZulipTestCase):self.assertIn("This organization has been deactivated.", result.content.decode())self.assertNotIn("and all organization data has been deleted", result.content.decode())- def test_deactivation_notice_when_deactivated_and_deactivated_redirect_is_set(self) -> None:+ def test_deactivation_notice_when_deactivated_and_deactivated_redirect_is_set_to_different_domain(+ self,+ ) -> None:realm = get_realm("zulip")realm.deactivated = True- realm.deactivated_redirect = "http://example.zulipchat.com"+ realm.deactivated_redirect = f"http://example.not_{settings.EXTERNAL_HOST}.com:9991"realm.save(update_fields=["deactivated", "deactivated_redirect"])result = self.client_get("/login/", follow=True)- self.assert_in_success_response(- ['href="http://example.zulipchat.com/" id="deactivated-org-auto-redirect"'], result- )+ self.assert_in_success_response([f'href="{realm.deactivated_redirect}"'], result)def test_deactivation_notice_when_realm_subdomain_is_changed(self) -> None:realm = get_realm("zulip")@@ -201,7 +201,9 @@ class DeactivationNoticeTestCase(ZulipTestCase):result = self.client_get("/login/", follow=True)self.assert_in_success_response(- ['href="http://new-subdomain-name.testserver/" id="deactivated-org-auto-redirect"'],+ [+ f'href="http://new-subdomain-name.{settings.EXTERNAL_HOST}/" id="deactivated-org-auto-redirect"'+ ],result,)diff --git a/zerver/views/auth.py b/zerver/views/auth.pyindex deaaf4cc9f7..18d64a82448 100644--- a/zerver/views/auth.py+++ b/zerver/views/auth.py@@ -827,7 +827,7 @@ def show_deactivation_notice(request: HttpRequest, next: str = "/") -> HttpResposplit = urlsplit(realm.deactivated_redirect)host = f"{split.scheme}://{split.netloc}"# If the redirect is in the same domain, do an automatic redirect.- if get_subdomain_from_hostname(host) is not None:+ if get_subdomain_from_hostname(host, None) is not None:redirect_to = get_safe_redirect_to(next, realm.deactivated_redirect)context["auto_redirect_to"] = redirect_toreturn render(request, "zerver/deactivated.html", context=context)