Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search non ASCII display names using Admin API #16767

Merged
merged 4 commits into from Jan 4, 2024
Merged
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
2 changes: 2 additions & 0 deletions changelog.d/16767.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a bug that prevented users from being queried by display name if it contains non-ASCII characters.

2 changes: 1 addition & 1 deletion synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
)

user_id = parse_string(request, "user_id")
name = parse_string(request, "name")
name = parse_string(request, "name", encoding="utf-8")

guests = parse_boolean(request, "guests", default=True)
if self._msc3861_enabled and guests:
Expand Down
23 changes: 23 additions & 0 deletions tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,8 +1638,17 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
)
)

self.non_ascii_displayname = "ąćęłńóśżźäöüß中国日本"
self.non_ascii_user = self.register_user(
"nonascii", "nonascii", displayname=self.non_ascii_displayname
)

self.url_prefix = "/_synapse/admin/v2/users/%s"
self.url_other_user = self.url_prefix % self.other_user
self.url_non_ascii_user = (
"/_synapse/admin/v2/users?name=%s"
% urllib.parse.quote(self.non_ascii_displayname)
)

def test_requester_is_no_admin(self) -> None:
"""
Expand Down Expand Up @@ -1790,6 +1799,20 @@ def test_get_user(self) -> None:
self.assertEqual("User", channel.json_body["displayname"])
self._check_fields(channel.json_body)

def test_get_user_nonascii_displayname(self) -> None:
"""
Test get user by non-ascii display name
"""
channel = self.make_request(
"GET",
self.url_non_ascii_user,
access_token=self.admin_user_tok,
)

users = {user["name"]: user for user in channel.json_body["users"]}
self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertIn(self.non_ascii_user, users, channel.json_body["users"])

def test_create_server_admin(self) -> None:
"""
Check that a new admin user is created successfully.
Expand Down
Loading