registration: Show SMTP failure page correctly.

232eb8b7cf 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.
This commit is contained in:
Alex Vandiver 2023-10-06 15:58:18 +00:00 committed by Tim Abbott
parent 2536dce136
commit e45f74dafb
2 changed files with 15 additions and 12 deletions

View File

@ -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:
"""

View File

@ -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)