From e45f74dafbdc3cfea56e4d5c255c71bb727e6ab9 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Fri, 6 Oct 2023 15:58:18 +0000 Subject: [PATCH] registration: Show SMTP failure page correctly. 232eb8b7cf87 changed how these pages work, to render inline instead of serving from a URL, but did not update the SMTP use case; this made SMTP failures redirect to a 404. --- zerver/tests/test_signup.py | 22 ++++++++++++---------- zerver/views/registration.py | 5 +++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 56e0dd4117..115b6e5766 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -2011,10 +2011,6 @@ class RealmCreationTest(ZulipTestCase): class UserSignUpTest(ZulipTestCase): - def _assert_redirected_to(self, result: "TestHttpResponse", url: str) -> None: - self.assertEqual(result.status_code, 302) - self.assertEqual(result["LOCATION"], url) - def verify_signup( self, *, @@ -2074,7 +2070,7 @@ class UserSignUpTest(ZulipTestCase): def test_bad_email_configuration_for_accounts_home(self) -> None: """ - Make sure we redirect for EmailNotDeliveredError. + Make sure we show an error page for EmailNotDeliveredError. """ email = self.nonreg_email("newguy") @@ -2086,12 +2082,15 @@ class UserSignUpTest(ZulipTestCase): with smtp_mock, self.assertLogs(level="ERROR") as m: result = self.client_post("/accounts/home/", {"email": email}) - self._assert_redirected_to(result, "/config-error/smtp") - self.assertEqual(m.output, ["ERROR:root:Error in accounts_home"]) + self.assertEqual(result.status_code, 500) + self.assert_in_response( + "https://zulip.readthedocs.io/en/latest/subsystems/email.html", result + ) + self.assertTrue("ERROR:root:Error in accounts_home" in m.output[0]) def test_bad_email_configuration_for_create_realm(self) -> None: """ - Make sure we redirect for EmailNotDeliveredError. + Make sure we show an error page for EmailNotDeliveredError. """ email = self.nonreg_email("newguy") @@ -2105,8 +2104,11 @@ class UserSignUpTest(ZulipTestCase): email, realm_subdomain="custom-test", realm_name="Zulip test" ) - self._assert_redirected_to(result, "/config-error/smtp") - self.assertEqual(m.output, ["ERROR:root:Error in create_realm"]) + self.assertEqual(result.status_code, 500) + self.assert_in_response( + "https://zulip.readthedocs.io/en/latest/subsystems/email.html", result + ) + self.assertTrue("ERROR:root:Error in create_realm" in m.output[0]) def test_user_default_language_and_timezone(self) -> None: """ diff --git a/zerver/views/registration.py b/zerver/views/registration.py index 7dc154e6a4..2e00304ec1 100644 --- a/zerver/views/registration.py +++ b/zerver/views/registration.py @@ -94,6 +94,7 @@ from zerver.views.auth import ( redirect_and_log_into_subdomain, redirect_to_deactivation_notice, ) +from zerver.views.errors import config_error from zproject.backends import ( ExternalAuthResult, NoMatchingLDAPUserError, @@ -816,7 +817,7 @@ def create_realm(request: HttpRequest, creation_key: Optional[str] = None) -> Ht send_confirm_registration_email(email, activation_url, request=request) except EmailNotDeliveredError: logging.error("Error in create_realm") - return HttpResponseRedirect("/config-error/smtp") + return config_error(request, "smtp") if key_record is not None: key_record.delete() @@ -946,7 +947,7 @@ def accounts_home( send_confirm_registration_email(email, activation_url, request=request, realm=realm) except EmailNotDeliveredError: logging.error("Error in accounts_home") - return HttpResponseRedirect("/config-error/smtp") + return config_error(request, "smtp") signup_send_confirm_url = reverse("signup_send_confirm") query = urlencode({"email": email}) url = append_url_query_string(signup_send_confirm_url, query)