Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion changelog.d/19913.misc

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/19916.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add note to 3PID email token request unit tests that the endpoint being tested can have an expected, artificial delay of up to 1s.
16 changes: 7 additions & 9 deletions tests/rest/client/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ def test_password_reset_bad_email_inhibit_error(self) -> None:
email = "test@example.com"

client_secret = "foobar"
session_id = self._request_token(
email,
client_secret,
# The endpoint intentionally adds up to 1000ms of jitter to avoid
# leaking whether the email address is bound to an account.
timeout_ms=3000,
)

# Note: The endpoint intentionally adds up to 1000ms of jitter to avoid
# leaking whether the email address is bound to an account.
#
# This should be handled by `await_result` underneath, which has a
# 1000ms timeout.
Comment on lines +329 to +333

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move this next to the relevant make_request inside _request_token(...)

session_id = self._request_token(email, client_secret)

self.assertIsNotNone(session_id)

Expand Down Expand Up @@ -370,7 +370,6 @@ def _request_token(
client_secret: str,
ip: str = "127.0.0.1",
next_link: str | None = None,
timeout_ms: int = 1000,
) -> str:
body = {"client_secret": client_secret, "email": email, "send_attempt": 1}
if next_link is not None:
Expand All @@ -380,7 +379,6 @@ def _request_token(
b"account/password/email/requestToken",
body,
client_ip=ip,
timeout_ms=timeout_ms,
)

if channel.code != 200:
Expand Down
8 changes: 5 additions & 3 deletions tests/rest/client/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,13 +749,15 @@ def test_request_token_existing_email_inhibit_error(self) -> None:
)
)

# Note: The endpoint intentionally adds up to 1000ms of jitter to avoid
# leaking whether the email address is bound to an account.
#
# This should be handled by `await_result` underneath, which has a
# 1000ms timeout.
channel = self.make_request(
"POST",
b"register/email/requestToken",
{"client_secret": "foobar", "email": email, "send_attempt": 1},
# The endpoint intentionally adds up to 1000ms of jitter to avoid
# leaking whether the email address is already bound to an account.
timeout_ms=3000,
)
Comment on lines +752 to 761

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current comment works.

I could also see this explicit version being good:

Suggested change
# Note: The endpoint intentionally adds up to 1000ms of jitter to avoid
# leaking whether the email address is bound to an account.
#
# This should be handled by `await_result` underneath, which has a
# 1000ms timeout.
channel = self.make_request(
"POST",
b"register/email/requestToken",
{"client_secret": "foobar", "email": email, "send_attempt": 1},
# The endpoint intentionally adds up to 1000ms of jitter to avoid
# leaking whether the email address is already bound to an account.
timeout_ms=3000,
)
channel = self.make_request(
"POST",
b"register/email/requestToken",
{"client_secret": "foobar", "email": email, "send_attempt": 1},
await_result=False,
)
# Note: The endpoint intentionally adds up to 1000ms of jitter to avoid
# leaking whether the email address is bound to an account.
channel.await_result(timeout_ms=1000)

self.assertEqual(200, channel.code, channel.result)

Expand Down
5 changes: 1 addition & 4 deletions tests/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ def make_request(
await_result: bool = True,
custom_headers: Iterable[CustomHeaderType] | None = None,
client_ip: str = "127.0.0.1",
timeout_ms: int = 1000,
) -> FakeChannel:
"""
Make a web request using the given method, path and content, and render it
Expand Down Expand Up @@ -488,8 +487,6 @@ def make_request(
custom_headers: (name, value) pairs to add as request headers
client_ip: The IP to use as the requesting IP. Useful for testing
ratelimiting.
timeout_ms: if `await_result` is `True`, the amount of time to wait on
the request before timing out. Ignored otherwise.

Returns:
channel
Expand Down Expand Up @@ -574,7 +571,7 @@ def make_request(
req.requestReceived(method, path, b"1.1")

if await_result:
channel.await_result(timeout_ms=timeout_ms)
channel.await_result()

return channel

Expand Down
4 changes: 0 additions & 4 deletions tests/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ def make_request(
await_result: bool = True,
custom_headers: Iterable[CustomHeaderType] | None = None,
client_ip: str = "127.0.0.1",
timeout_ms: int = 1000,
) -> FakeChannel:
"""
Create a SynapseRequest at the path using the method and containing the
Expand Down Expand Up @@ -600,8 +599,6 @@ def make_request(

client_ip: The IP to use as the requesting IP. Useful for testing
ratelimiting.
timeout_ms: if `await_result` is `True`, the amount of time to wait on
the request before timing out. Ignored otherwise.

Returns:
The FakeChannel object which stores the result of the request.
Expand All @@ -621,7 +618,6 @@ def make_request(
await_result,
custom_headers,
client_ip,
timeout_ms,
)

def setup_test_homeserver(
Expand Down
Loading