Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Allow . and ~ chars in registration tokens #10887

Merged
merged 3 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 0 deletions changelog.d/10887.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow `.` and `~` characters when creating registration tokens as per the [change to MSC3231](https://github.com/matrix-org/matrix-doc/pull/3231/commits/79939f955b34113404b5d363a981f790aa7ec0e7).
clokep marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion synapse/rest/admin/registration_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastore()
self.clock = hs.get_clock()
# A string of all the characters allowed to be in a registration_token
self.allowed_chars = string.ascii_letters + string.digits + "-_"
self.allowed_chars = string.ascii_letters + string.digits + "._~-"
self.allowed_chars_set = set(self.allowed_chars)

async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
Expand Down
8 changes: 5 additions & 3 deletions tests/rest/admin/test_registration_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ def test_create_using_defaults(self):

def test_create_specifying_fields(self):
"""Create a token specifying the value of all fields."""
# As many of the allowed characters as possible with length <= 64
token = "adefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._~-"
data = {
"token": "abcd",
"token": token,
"uses_allowed": 1,
"expiry_time": self.clock.time_msec() + 1000000,
}
Expand All @@ -109,7 +111,7 @@ def test_create_specifying_fields(self):
)

self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
self.assertEqual(channel.json_body["token"], "abcd")
self.assertEqual(channel.json_body["token"], token)
self.assertEqual(channel.json_body["uses_allowed"], 1)
self.assertEqual(channel.json_body["expiry_time"], data["expiry_time"])
self.assertEqual(channel.json_body["pending"], 0)
Expand Down Expand Up @@ -193,7 +195,7 @@ def test_create_unable_to_generate_token(self):
"""Check right error is raised when server can't generate unique token."""
# Create all possible single character tokens
tokens = []
for c in string.ascii_letters + string.digits + "-_":
for c in string.ascii_letters + string.digits + "._~-":
tokens.append(
{
"token": c,
Expand Down