-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix email verification redirection (#16761)
Previously, the response status of `HTMLResource` was hardcoded as `200`. However, for proper redirection after the user verifies their email, we require the status to be `302`. This PR addresses that issue by using `code` as response status.
- Loading branch information
Showing
4 changed files
with
43 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix email verification redirection. Contributed by Fadhlan Ridhwanallah. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,16 +328,49 @@ def test_password_reset_bad_email_inhibit_error(self) -> None: | |
|
||
self.assertIsNotNone(session_id) | ||
|
||
def test_password_reset_redirection(self) -> None: | ||
"""Test basic password reset flow""" | ||
old_password = "monkey" | ||
|
||
user_id = self.register_user("kermit", old_password) | ||
self.login("kermit", old_password) | ||
|
||
email = "[email protected]" | ||
|
||
# Add a threepid | ||
self.get_success( | ||
self.store.user_add_threepid( | ||
user_id=user_id, | ||
medium="email", | ||
address=email, | ||
validated_at=0, | ||
added_at=0, | ||
) | ||
) | ||
|
||
client_secret = "foobar" | ||
next_link = "http://example.com" | ||
self._request_token(email, client_secret, "127.0.0.1", next_link) | ||
|
||
self.assertEqual(len(self.email_attempts), 1) | ||
link = self._get_link_from_email() | ||
|
||
self._validate_token(link, next_link) | ||
|
||
def _request_token( | ||
self, | ||
email: str, | ||
client_secret: str, | ||
ip: str = "127.0.0.1", | ||
next_link: Optional[str] = None, | ||
) -> str: | ||
body = {"client_secret": client_secret, "email": email, "send_attempt": 1} | ||
if next_link is not None: | ||
body["next_link"] = next_link | ||
channel = self.make_request( | ||
"POST", | ||
b"account/password/email/requestToken", | ||
{"client_secret": client_secret, "email": email, "send_attempt": 1}, | ||
body, | ||
client_ip=ip, | ||
) | ||
|
||
|
@@ -350,7 +383,7 @@ def _request_token( | |
|
||
return channel.json_body["sid"] | ||
|
||
def _validate_token(self, link: str) -> None: | ||
def _validate_token(self, link: str, next_link: Optional[str] = None) -> None: | ||
# Remove the host | ||
path = link.replace("https://example.com", "") | ||
|
||
|
@@ -378,7 +411,11 @@ def _validate_token(self, link: str) -> None: | |
shorthand=False, | ||
content_is_form=True, | ||
) | ||
self.assertEqual(HTTPStatus.OK, channel.code, channel.result) | ||
self.assertEqual( | ||
HTTPStatus.OK if next_link is None else HTTPStatus.FOUND, | ||
channel.code, | ||
channel.result, | ||
) | ||
|
||
def _get_link_from_email(self) -> str: | ||
assert self.email_attempts, "No emails have been sent" | ||
|