summary refs log tree commit diff
diff options
context:
space:
mode:
authorAdam Jędrzejewski <59581316+adamjedrzejewski@users.noreply.github.com>2024-01-04 10:36:57 +0100
committerGitHub <noreply@github.com>2024-01-04 09:36:57 +0000
commitc7d0d02be7bf61e58388676e9e31b44004cbf257 (patch)
treeb1688310e7a17e34058e127b63e8a261550f5f2e
parentUpdate the contributing guide after reliecensing (#16772) (diff)
downloadsynapse-c7d0d02be7bf61e58388676e9e31b44004cbf257.tar.xz
Search non ASCII display names using Admin API (#16767)
Closes #16370

Signed-off-by: Adam Jedrzejewski <adamjedrzejewski@icloud.com>
-rw-r--r--changelog.d/16767.bugfix2
-rw-r--r--synapse/rest/admin/users.py2
-rw-r--r--tests/rest/admin/test_user.py23
3 files changed, 26 insertions, 1 deletions
diff --git a/changelog.d/16767.bugfix b/changelog.d/16767.bugfix
new file mode 100644
index 0000000000..b1fa1285ef
--- /dev/null
+++ b/changelog.d/16767.bugfix
@@ -0,0 +1,2 @@
+Fixed a bug that prevented users from being queried by display name if it contains non-ASCII characters.
+
diff --git a/synapse/rest/admin/users.py b/synapse/rest/admin/users.py
index a31a268ccc..ee73f0233d 100644
--- a/synapse/rest/admin/users.py
+++ b/synapse/rest/admin/users.py
@@ -107,7 +107,7 @@ class UsersRestServletV2(RestServlet):
             )
 
         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:
diff --git a/tests/rest/admin/test_user.py b/tests/rest/admin/test_user.py
index 04604bfc04..61cbac2332 100644
--- a/tests/rest/admin/test_user.py
+++ b/tests/rest/admin/test_user.py
@@ -1638,8 +1638,17 @@ class UserRestTestCase(unittest.HomeserverTestCase):
             )
         )
 
+        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:
         """
@@ -1790,6 +1799,20 @@ class UserRestTestCase(unittest.HomeserverTestCase):
         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.