mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
auth: Redirect password reset page to /accounts/go when required.
This commit is contained in:
@@ -426,6 +426,81 @@ class PasswordResetTest(ZulipTestCase):
|
|||||||
# make sure old password no longer works
|
# make sure old password no longer works
|
||||||
self.assert_login_failure(email, password=old_password)
|
self.assert_login_failure(email, password=old_password)
|
||||||
|
|
||||||
|
@patch("django.http.HttpRequest.get_host")
|
||||||
|
def test_password_reset_page_redirects_for_root_alias_when_root_domain_landing_page_is_enabled(
|
||||||
|
self, mock_get_host: MagicMock
|
||||||
|
) -> None:
|
||||||
|
mock_get_host.return_value = "alias.testserver"
|
||||||
|
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True, ROOT_SUBDOMAIN_ALIASES=["alias"]):
|
||||||
|
result = self.client_get("/accounts/password/reset/")
|
||||||
|
self.assertEqual(result.status_code, 302)
|
||||||
|
self.assertEqual(result.url, "/accounts/go/?next=%2Faccounts%2Fpassword%2Freset%2F")
|
||||||
|
|
||||||
|
mock_get_host.return_value = "www.testserver"
|
||||||
|
with self.settings(
|
||||||
|
ROOT_DOMAIN_LANDING_PAGE=True,
|
||||||
|
):
|
||||||
|
result = self.client_get("/accounts/password/reset/")
|
||||||
|
self.assertEqual(result.status_code, 302)
|
||||||
|
self.assertEqual(result.url, "/accounts/go/?next=%2Faccounts%2Fpassword%2Freset%2F")
|
||||||
|
|
||||||
|
@patch("django.http.HttpRequest.get_host")
|
||||||
|
def test_password_reset_page_redirects_for_root_domain_when_root_domain_landing_page_is_enabled(
|
||||||
|
self, mock_get_host: MagicMock
|
||||||
|
) -> None:
|
||||||
|
mock_get_host.return_value = "testserver"
|
||||||
|
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True):
|
||||||
|
result = self.client_get("/accounts/password/reset/")
|
||||||
|
self.assertEqual(result.status_code, 302)
|
||||||
|
self.assertEqual(result.url, "/accounts/go/?next=%2Faccounts%2Fpassword%2Freset%2F")
|
||||||
|
|
||||||
|
mock_get_host.return_value = "www.testserver.com"
|
||||||
|
with self.settings(
|
||||||
|
ROOT_DOMAIN_LANDING_PAGE=True,
|
||||||
|
EXTERNAL_HOST="www.testserver.com",
|
||||||
|
):
|
||||||
|
result = self.client_get("/accounts/password/reset/")
|
||||||
|
self.assertEqual(result.status_code, 302)
|
||||||
|
self.assertEqual(result.url, "/accounts/go/?next=%2Faccounts%2Fpassword%2Freset%2F")
|
||||||
|
|
||||||
|
@patch("django.http.HttpRequest.get_host")
|
||||||
|
def test_password_reset_page_works_for_root_alias_when_root_domain_landing_page_is_not_enabled(
|
||||||
|
self, mock_get_host: MagicMock
|
||||||
|
) -> None:
|
||||||
|
mock_get_host.return_value = "alias.testserver"
|
||||||
|
with self.settings(ROOT_SUBDOMAIN_ALIASES=["alias"]):
|
||||||
|
result = self.client_get("/accounts/password/reset/")
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
mock_get_host.return_value = "www.testserver"
|
||||||
|
result = self.client_get("/accounts/password/reset/")
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
@patch("django.http.HttpRequest.get_host")
|
||||||
|
def test_password_reset_page_works_for_root_domain_when_root_domain_landing_page_is_not_enabled(
|
||||||
|
self, mock_get_host: MagicMock
|
||||||
|
) -> None:
|
||||||
|
mock_get_host.return_value = "testserver"
|
||||||
|
result = self.client_get("/accounts/password/reset/")
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
mock_get_host.return_value = "www.testserver.com"
|
||||||
|
with self.settings(EXTERNAL_HOST="www.testserver.com", ROOT_SUBDOMAIN_ALIASES=[]):
|
||||||
|
result = self.client_get("/accounts/password/reset/")
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
@patch("django.http.HttpRequest.get_host")
|
||||||
|
def test_password_reset_page_works_always_for_subdomains(
|
||||||
|
self, mock_get_host: MagicMock
|
||||||
|
) -> None:
|
||||||
|
mock_get_host.return_value = "lear.testserver"
|
||||||
|
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True):
|
||||||
|
result = self.client_get("/accounts/password/reset/")
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
result = self.client_get("/accounts/password/reset/")
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
def test_password_reset_for_non_existent_user(self) -> None:
|
def test_password_reset_for_non_existent_user(self) -> None:
|
||||||
email = "nonexisting@mars.com"
|
email = "nonexisting@mars.com"
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ import secrets
|
|||||||
import urllib
|
import urllib
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Any, Dict, List, Mapping, Optional, cast
|
from typing import Any, Dict, List, Mapping, Optional, cast
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
import jwt
|
import jwt
|
||||||
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
||||||
@@ -959,6 +960,12 @@ def logout_then_login(request: HttpRequest, **kwargs: Any) -> HttpResponse:
|
|||||||
|
|
||||||
|
|
||||||
def password_reset(request: HttpRequest) -> HttpResponse:
|
def password_reset(request: HttpRequest) -> HttpResponse:
|
||||||
|
if is_subdomain_root_or_alias(request) and settings.ROOT_DOMAIN_LANDING_PAGE:
|
||||||
|
redirect_url = add_query_to_redirect_url(
|
||||||
|
reverse("realm_redirect"), urlencode({"next": reverse("password_reset")})
|
||||||
|
)
|
||||||
|
return HttpResponseRedirect(redirect_url)
|
||||||
|
|
||||||
response = DjangoPasswordResetView.as_view(
|
response = DjangoPasswordResetView.as_view(
|
||||||
template_name="zerver/reset.html",
|
template_name="zerver/reset.html",
|
||||||
form_class=ZulipPasswordResetForm,
|
form_class=ZulipPasswordResetForm,
|
||||||
|
Reference in New Issue
Block a user