0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-06-09 06:08:56 +02:00

Allow Synapse Admin API's Room Search to accept non-ASCII characters (#10859)

* add tests for checking if room search works with non-ascii char

* change encoding on parse_string to UTF-8

* lints

* properly encode search term

* lints

* add changelog file

* update changelog number

* set changelog entry filetype to .bugfix

* Revert "set changelog entry filetype to .bugfix"

This reverts commit be8e5a314251438ec4ec7dbc59ba32162c93e550.

* update changelog message and file type

* change parse_string default encoding back to ascii and update room search admin api calll to parse string

* refactor tests

* Update tests/rest/admin/test_room.py

Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>

Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
This commit is contained in:
Hillery Shay 2021-09-21 08:04:35 -07:00 committed by GitHub
parent ee557b5375
commit 5fca3c8ae6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

1
changelog.d/10859.bugfix Normal file
View file

@ -0,0 +1 @@
Fix a bug in Unicode support of the room search admin API. It is now possible to search for rooms with non-ASCII characters.

View file

@ -125,7 +125,7 @@ class ListRoomRestServlet(RestServlet):
errcode=Codes.INVALID_PARAM,
)
search_term = parse_string(request, "search_term")
search_term = parse_string(request, "search_term", encoding="utf-8")
if search_term == "":
raise SynapseError(
400,

View file

@ -941,6 +941,33 @@ class RoomTestCase(unittest.HomeserverTestCase):
_search_test(None, "bar")
_search_test(None, "", expected_http_code=400)
def test_search_term_non_ascii(self):
"""Test that searching for a room with non-ASCII characters works correctly"""
# Create test room
room_id = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)
room_name = "ж"
# Set the name for the room
self.helper.send_state(
room_id,
"m.room.name",
{"name": room_name},
tok=self.admin_user_tok,
)
# make the request and test that the response is what we wanted
search_term = urllib.parse.quote("ж", "utf-8")
url = "/_synapse/admin/v1/rooms?search_term=%s" % (search_term,)
channel = self.make_request(
"GET",
url.encode("ascii"),
access_token=self.admin_user_tok,
)
self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(room_id, channel.json_body.get("rooms")[0].get("room_id"))
self.assertEqual("ж", channel.json_body.get("rooms")[0].get("name"))
def test_single_room(self):
"""Test that a single room can be requested correctly"""
# Create two test rooms