mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-14 10:15:35 -04:00
Fix handling of public rooms filter with a network tuple. (#14053)
Fixes two related bugs: * The handling of `[null]` for a `room_types` filter was incorrect. * The ordering of arguments when providing both a network tuple and room type field was incorrect.
This commit is contained in:
parent
dcced5a8d7
commit
0b037d6c91
3 changed files with 58 additions and 27 deletions
|
@ -2213,14 +2213,17 @@ class PublicRoomsRoomTypeFilterTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
def make_public_rooms_request(
|
||||
self, room_types: Union[List[Union[str, None]], None]
|
||||
self,
|
||||
room_types: Optional[List[Union[str, None]]],
|
||||
instance_id: Optional[str] = None,
|
||||
) -> Tuple[List[Dict[str, Any]], int]:
|
||||
channel = self.make_request(
|
||||
"POST",
|
||||
self.url,
|
||||
{"filter": {PublicRoomsFilterFields.ROOM_TYPES: room_types}},
|
||||
self.token,
|
||||
)
|
||||
body: JsonDict = {"filter": {PublicRoomsFilterFields.ROOM_TYPES: room_types}}
|
||||
if instance_id:
|
||||
body["third_party_instance_id"] = "test|test"
|
||||
|
||||
channel = self.make_request("POST", self.url, body, self.token)
|
||||
self.assertEqual(channel.code, 200)
|
||||
|
||||
chunk = channel.json_body["chunk"]
|
||||
count = channel.json_body["total_room_count_estimate"]
|
||||
|
||||
|
@ -2230,31 +2233,49 @@ class PublicRoomsRoomTypeFilterTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_returns_both_rooms_and_spaces_if_no_filter(self) -> None:
|
||||
chunk, count = self.make_public_rooms_request(None)
|
||||
|
||||
self.assertEqual(count, 2)
|
||||
|
||||
# Also check if there's no filter property at all in the body.
|
||||
channel = self.make_request("POST", self.url, {}, self.token)
|
||||
self.assertEqual(channel.code, 200)
|
||||
self.assertEqual(len(channel.json_body["chunk"]), 2)
|
||||
self.assertEqual(channel.json_body["total_room_count_estimate"], 2)
|
||||
|
||||
chunk, count = self.make_public_rooms_request(None, "test|test")
|
||||
self.assertEqual(count, 0)
|
||||
|
||||
def test_returns_only_rooms_based_on_filter(self) -> None:
|
||||
chunk, count = self.make_public_rooms_request([None])
|
||||
|
||||
self.assertEqual(count, 1)
|
||||
self.assertEqual(chunk[0].get("room_type", None), None)
|
||||
|
||||
chunk, count = self.make_public_rooms_request([None], "test|test")
|
||||
self.assertEqual(count, 0)
|
||||
|
||||
def test_returns_only_space_based_on_filter(self) -> None:
|
||||
chunk, count = self.make_public_rooms_request(["m.space"])
|
||||
|
||||
self.assertEqual(count, 1)
|
||||
self.assertEqual(chunk[0].get("room_type", None), "m.space")
|
||||
|
||||
chunk, count = self.make_public_rooms_request(["m.space"], "test|test")
|
||||
self.assertEqual(count, 0)
|
||||
|
||||
def test_returns_both_rooms_and_space_based_on_filter(self) -> None:
|
||||
chunk, count = self.make_public_rooms_request(["m.space", None])
|
||||
|
||||
self.assertEqual(count, 2)
|
||||
|
||||
chunk, count = self.make_public_rooms_request(["m.space", None], "test|test")
|
||||
self.assertEqual(count, 0)
|
||||
|
||||
def test_returns_both_rooms_and_spaces_if_array_is_empty(self) -> None:
|
||||
chunk, count = self.make_public_rooms_request([])
|
||||
|
||||
self.assertEqual(count, 2)
|
||||
|
||||
chunk, count = self.make_public_rooms_request([], "test|test")
|
||||
self.assertEqual(count, 0)
|
||||
|
||||
|
||||
class PublicRoomsTestRemoteSearchFallbackTestCase(unittest.HomeserverTestCase):
|
||||
"""Test that we correctly fallback to local filtering if a remote server
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue