Allow `.` and `~` chars in registration tokens (#10887)
Per updates to MSC3231 in order to use the same grammar as other identifiers.
This commit is contained in:
parent
a7304adc7d
commit
90d9fc7505
|
@ -0,0 +1 @@
|
||||||
|
Allow the `.` and `~` characters when creating registration tokens as per the change to [MSC3231](https://github.com/matrix-org/matrix-doc/pull/3231).
|
|
@ -113,7 +113,7 @@ class NewRegistrationTokenRestServlet(RestServlet):
|
||||||
self.store = hs.get_datastore()
|
self.store = hs.get_datastore()
|
||||||
self.clock = hs.get_clock()
|
self.clock = hs.get_clock()
|
||||||
# A string of all the characters allowed to be in a registration_token
|
# 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)
|
self.allowed_chars_set = set(self.allowed_chars)
|
||||||
|
|
||||||
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
|
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
|
||||||
|
|
|
@ -95,8 +95,10 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_create_specifying_fields(self):
|
def test_create_specifying_fields(self):
|
||||||
"""Create a token specifying the value of all fields."""
|
"""Create a token specifying the value of all fields."""
|
||||||
|
# As many of the allowed characters as possible with length <= 64
|
||||||
|
token = "adefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._~-"
|
||||||
data = {
|
data = {
|
||||||
"token": "abcd",
|
"token": token,
|
||||||
"uses_allowed": 1,
|
"uses_allowed": 1,
|
||||||
"expiry_time": self.clock.time_msec() + 1000000,
|
"expiry_time": self.clock.time_msec() + 1000000,
|
||||||
}
|
}
|
||||||
|
@ -109,7 +111,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
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["uses_allowed"], 1)
|
||||||
self.assertEqual(channel.json_body["expiry_time"], data["expiry_time"])
|
self.assertEqual(channel.json_body["expiry_time"], data["expiry_time"])
|
||||||
self.assertEqual(channel.json_body["pending"], 0)
|
self.assertEqual(channel.json_body["pending"], 0)
|
||||||
|
@ -193,7 +195,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
||||||
"""Check right error is raised when server can't generate unique token."""
|
"""Check right error is raised when server can't generate unique token."""
|
||||||
# Create all possible single character tokens
|
# Create all possible single character tokens
|
||||||
tokens = []
|
tokens = []
|
||||||
for c in string.ascii_letters + string.digits + "-_":
|
for c in string.ascii_letters + string.digits + "._~-":
|
||||||
tokens.append(
|
tokens.append(
|
||||||
{
|
{
|
||||||
"token": c,
|
"token": c,
|
||||||
|
|
Loading…
Reference in New Issue