@@ -43,12 +43,6 @@ class UserMutualRoomsTest(unittest.HomeserverTestCase):
4343 mutual_rooms .register_servlets ,
4444 ]
4545
46- def default_config (self ) -> dict :
47- config = super ().default_config ()
48- experimental = config .setdefault ("experimental_features" , {})
49- experimental .setdefault ("msc2666_enabled" , True )
50- return config
51-
5246 def make_homeserver (self , reactor : MemoryReactor , clock : Clock ) -> HomeServer :
5347 config = self .default_config ()
5448 return self .setup_test_homeserver (config = config )
@@ -62,27 +56,12 @@ def _get_mutual_rooms(
6256 ) -> FakeChannel :
6357 return self .make_request (
6458 "GET" ,
65- "/_matrix/client/unstable/uk.half-shot.msc2666/user /mutual_rooms"
59+ "/_matrix/client/v1 /mutual_rooms"
6660 f"?user_id={ quote (other_user )} "
6761 + (f"&from={ quote (since_token )} " if since_token else "" ),
6862 access_token = token ,
6963 )
7064
71- @unittest .override_config ({"experimental_features" : {"msc2666_enabled" : False }})
72- def test_mutual_rooms_no_experimental_flag (self ) -> None :
73- """
74- The endpoint should 404 if the experimental flag is not enabled.
75- """
76- # Register a user.
77- u1 = self .register_user ("user1" , "pass" )
78- u1_token = self .login (u1 , "pass" )
79-
80- # Check that we're unable to query the endpoint due to the endpoint
81- # being unrecognised.
82- channel = self ._get_mutual_rooms (u1_token , "@not-used:test" )
83- self .assertEqual (404 , channel .code , channel .result )
84- self .assertEqual ("M_UNRECOGNIZED" , channel .json_body ["errcode" ], channel .result )
85-
8665 def test_shared_room_list_public (self ) -> None :
8766 """
8867 A room should show up in the shared list of rooms between two users
@@ -129,6 +108,7 @@ def _check_mutual_rooms_with(
129108 channel = self ._get_mutual_rooms (u1_token , u2 )
130109 self .assertEqual (200 , channel .code , channel .result )
131110 self .assertEqual (len (channel .json_body ["joined" ]), 1 )
111+ self .assertEqual (channel .json_body ["count" ], 1 )
132112 self .assertEqual (channel .json_body ["joined" ][0 ], room_id_one )
133113
134114 # Create another room and invite user2 to it
@@ -142,6 +122,7 @@ def _check_mutual_rooms_with(
142122 channel = self ._get_mutual_rooms (u1_token , u2 )
143123 self .assertEqual (200 , channel .code , channel .result )
144124 self .assertEqual (len (channel .json_body ["joined" ]), 2 )
125+ self .assertEqual (channel .json_body ["count" ], 2 )
145126 for room_id_id in channel .json_body ["joined" ]:
146127 self .assertIn (room_id_id , [room_id_one , room_id_two ])
147128
@@ -167,11 +148,13 @@ def test_shared_room_list_pagination_two_pages(self) -> None:
167148 channel = self ._get_mutual_rooms (u1_token , u2 )
168149 self .assertEqual (200 , channel .code , channel .result )
169150 self .assertEqual (channel .json_body ["joined" ], room_ids [0 :10 ])
151+ self .assertEqual (channel .json_body ["count" ], 15 )
170152 self .assertIn ("next_batch" , channel .json_body )
171153
172154 channel = self ._get_mutual_rooms (u1_token , u2 , channel .json_body ["next_batch" ])
173155 self .assertEqual (200 , channel .code , channel .result )
174156 self .assertEqual (channel .json_body ["joined" ], room_ids [10 :20 ])
157+ self .assertEqual (channel .json_body ["count" ], 15 )
175158 self .assertNotIn ("next_batch" , channel .json_body )
176159
177160 def test_shared_room_list_pagination_one_page (self ) -> None :
@@ -180,6 +163,7 @@ def test_shared_room_list_pagination_one_page(self) -> None:
180163 channel = self ._get_mutual_rooms (u1_token , u2 )
181164 self .assertEqual (200 , channel .code , channel .result )
182165 self .assertEqual (channel .json_body ["joined" ], room_ids )
166+ self .assertEqual (channel .json_body ["count" ], 10 )
183167 self .assertNotIn ("next_batch" , channel .json_body )
184168
185169 def test_shared_room_list_pagination_invalid_token (self ) -> None :
@@ -209,6 +193,7 @@ def test_shared_room_list_after_leave(self) -> None:
209193 channel = self ._get_mutual_rooms (u1_token , u2 )
210194 self .assertEqual (200 , channel .code , channel .result )
211195 self .assertEqual (len (channel .json_body ["joined" ]), 1 )
196+ self .assertEqual (channel .json_body ["count" ], 1 )
212197 self .assertEqual (channel .json_body ["joined" ][0 ], room )
213198
214199 self .helper .leave (room , user = u1 , tok = u1_token )
@@ -217,11 +202,13 @@ def test_shared_room_list_after_leave(self) -> None:
217202 channel = self ._get_mutual_rooms (u1_token , u2 )
218203 self .assertEqual (200 , channel .code , channel .result )
219204 self .assertEqual (len (channel .json_body ["joined" ]), 0 )
205+ self .assertEqual (channel .json_body ["count" ], 0 )
220206
221207 # Check user2's view of shared rooms with user1
222208 channel = self ._get_mutual_rooms (u2_token , u1 )
223209 self .assertEqual (200 , channel .code , channel .result )
224210 self .assertEqual (len (channel .json_body ["joined" ]), 0 )
211+ self .assertEqual (channel .json_body ["count" ], 0 )
225212
226213 def test_shared_room_list_nonexistent_user (self ) -> None :
227214 u1 = self .register_user ("user1" , "pass" )
@@ -232,4 +219,27 @@ def test_shared_room_list_nonexistent_user(self) -> None:
232219 channel = self ._get_mutual_rooms (u1_token , "@meow:example.com" )
233220 self .assertEqual (200 , channel .code , channel .result )
234221 self .assertEqual (len (channel .json_body ["joined" ]), 0 )
222+ self .assertEqual (channel .json_body ["count" ], 0 )
235223 self .assertNotIn ("next_batch" , channel .json_body )
224+
225+ def test_shared_room_list_invalid_user (self ) -> None :
226+ u1 = self .register_user ("user1" , "pass" )
227+ u1_token = self .login (u1 , "pass" )
228+
229+ channel = self ._get_mutual_rooms (u1_token , "@:example.com" )
230+ self .assertEqual (400 , channel .code , channel .result )
231+ self .assertEqual (
232+ "M_INVALID_PARAM" , channel .json_body ["errcode" ], channel .result
233+ )
234+
235+ channel = self ._get_mutual_rooms (u1_token , "@" + "a" * 255 + ":example.com" )
236+ self .assertEqual (400 , channel .code , channel .result )
237+ self .assertEqual (
238+ "M_INVALID_PARAM" , channel .json_body ["errcode" ], channel .result
239+ )
240+
241+ channel = self ._get_mutual_rooms (u1_token , "@🐈️:example.com" )
242+ self .assertEqual (400 , channel .code , channel .result )
243+ self .assertEqual (
244+ "M_INVALID_PARAM" , channel .json_body ["errcode" ], channel .result
245+ )
0 commit comments