auth: Improve Confirmation link error handling in social auth codepath.

render_confirmation_key_error provides better error responses than
simply rendering the "link expired" template.
This commit is contained in:
Mateusz Mandera 2021-12-02 17:51:38 +01:00 committed by Tim Abbott
parent 7c5daac8b6
commit 4a030f616f
2 changed files with 4 additions and 3 deletions

View File

@ -1526,7 +1526,7 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase):
result = self.client_get(result.url) result = self.client_get(result.url)
self.assertEqual(result.status_code, 404) self.assertEqual(result.status_code, 404)
self.assert_in_response("The registration link has expired or is not valid.", result) self.assert_in_response("Whoops. The confirmation link is malformed.", result)
@override_settings(TERMS_OF_SERVICE=None) @override_settings(TERMS_OF_SERVICE=None)
def test_social_auth_registration_using_multiuse_invite(self) -> None: def test_social_auth_registration_using_multiuse_invite(self) -> None:

View File

@ -34,6 +34,7 @@ from confirmation.models import (
ConfirmationKeyException, ConfirmationKeyException,
create_confirmation_link, create_confirmation_link,
get_object_from_key, get_object_from_key,
render_confirmation_key_error,
) )
from version import API_FEATURE_LEVEL, ZULIP_MERGE_BASE, ZULIP_VERSION from version import API_FEATURE_LEVEL, ZULIP_MERGE_BASE, ZULIP_VERSION
from zerver.context_processors import get_realm_from_request, login_context, zulip_default_context from zerver.context_processors import get_realm_from_request, login_context, zulip_default_context
@ -187,8 +188,8 @@ def maybe_send_to_registration(
from_multiuse_invite = True from_multiuse_invite = True
try: try:
multiuse_obj = get_object_from_key(multiuse_object_key, [Confirmation.MULTIUSE_INVITE]) multiuse_obj = get_object_from_key(multiuse_object_key, [Confirmation.MULTIUSE_INVITE])
except ConfirmationKeyException: except ConfirmationKeyException as exception:
return render(request, "zerver/confirmation_link_expired_error.html", status=404) return render_confirmation_key_error(request, exception)
assert multiuse_obj is not None assert multiuse_obj is not None
realm = multiuse_obj.realm realm = multiuse_obj.realm