|
25 | 25 | import synapse.rest.admin
|
26 | 26 | from synapse.api.constants import UserTypes
|
27 | 27 | from synapse.api.errors import Codes, HttpResponseException, ResourceLimitError
|
| 28 | +from synapse.api.room_versions import RoomVersions |
28 | 29 | from synapse.rest.client.v1 import login, logout, profile, room
|
29 | 30 | from synapse.rest.client.v2_alpha import devices, sync
|
30 | 31 |
|
@@ -1234,24 +1235,26 @@ def test_requester_is_no_admin(self):
|
1234 | 1235 |
|
1235 | 1236 | def test_user_does_not_exist(self):
|
1236 | 1237 | """
|
1237 |
| - Tests that a lookup for a user that does not exist returns a 404 |
| 1238 | + Tests that a lookup for a user that does not exist returns an empty list |
1238 | 1239 | """
|
1239 | 1240 | url = "/_synapse/admin/v1/users/@unknown_person:test/joined_rooms"
|
1240 | 1241 | channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
1241 | 1242 |
|
1242 |
| - self.assertEqual(404, channel.code, msg=channel.json_body) |
1243 |
| - self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"]) |
| 1243 | + self.assertEqual(200, channel.code, msg=channel.json_body) |
| 1244 | + self.assertEqual(0, channel.json_body["total"]) |
| 1245 | + self.assertEqual(0, len(channel.json_body["joined_rooms"])) |
1244 | 1246 |
|
1245 | 1247 | def test_user_is_not_local(self):
|
1246 | 1248 | """
|
1247 |
| - Tests that a lookup for a user that is not a local returns a 400 |
| 1249 | + Tests that a lookup for a user that is not a local and participates in no conversation returns an empty list |
1248 | 1250 | """
|
1249 | 1251 | url = "/_synapse/admin/v1/users/@unknown_person:unknown_domain/joined_rooms"
|
1250 | 1252 |
|
1251 | 1253 | channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
1252 | 1254 |
|
1253 |
| - self.assertEqual(400, channel.code, msg=channel.json_body) |
1254 |
| - self.assertEqual("Can only lookup local users", channel.json_body["error"]) |
| 1255 | + self.assertEqual(200, channel.code, msg=channel.json_body) |
| 1256 | + self.assertEqual(0, channel.json_body["total"]) |
| 1257 | + self.assertEqual(0, len(channel.json_body["joined_rooms"])) |
1255 | 1258 |
|
1256 | 1259 | def test_no_memberships(self):
|
1257 | 1260 | """
|
@@ -1282,6 +1285,49 @@ def test_get_rooms(self):
|
1282 | 1285 | self.assertEqual(number_rooms, channel.json_body["total"])
|
1283 | 1286 | self.assertEqual(number_rooms, len(channel.json_body["joined_rooms"]))
|
1284 | 1287 |
|
| 1288 | + def test_get_rooms_with_nonlocal_user(self): |
| 1289 | + """ |
| 1290 | + Tests that a normal lookup for rooms is successful with a non-local user |
| 1291 | + """ |
| 1292 | + |
| 1293 | + other_user_tok = self.login("user", "pass") |
| 1294 | + event_builder_factory = self.hs.get_event_builder_factory() |
| 1295 | + event_creation_handler = self.hs.get_event_creation_handler() |
| 1296 | + storage = self.hs.get_storage() |
| 1297 | + |
| 1298 | + # Create two rooms, one with a local user only and one with both a local |
| 1299 | + # and remote user. |
| 1300 | + self.helper.create_room_as(self.other_user, tok=other_user_tok) |
| 1301 | + local_and_remote_room_id = self.helper.create_room_as( |
| 1302 | + self.other_user, tok=other_user_tok |
| 1303 | + ) |
| 1304 | + |
| 1305 | + # Add a remote user to the room. |
| 1306 | + builder = event_builder_factory.for_room_version( |
| 1307 | + RoomVersions.V1, |
| 1308 | + { |
| 1309 | + "type": "m.room.member", |
| 1310 | + "sender": "@joiner:remote_hs", |
| 1311 | + "state_key": "@joiner:remote_hs", |
| 1312 | + "room_id": local_and_remote_room_id, |
| 1313 | + "content": {"membership": "join"}, |
| 1314 | + }, |
| 1315 | + ) |
| 1316 | + |
| 1317 | + event, context = self.get_success( |
| 1318 | + event_creation_handler.create_new_client_event(builder) |
| 1319 | + ) |
| 1320 | + |
| 1321 | + self.get_success(storage.persistence.persist_event(event, context)) |
| 1322 | + |
| 1323 | + # Now get rooms |
| 1324 | + url = "/_synapse/admin/v1/users/@joiner:remote_hs/joined_rooms" |
| 1325 | + channel = self.make_request("GET", url, access_token=self.admin_user_tok,) |
| 1326 | + |
| 1327 | + self.assertEqual(200, channel.code, msg=channel.json_body) |
| 1328 | + self.assertEqual(1, channel.json_body["total"]) |
| 1329 | + self.assertEqual([local_and_remote_room_id], channel.json_body["joined_rooms"]) |
| 1330 | + |
1285 | 1331 |
|
1286 | 1332 | class PushersRestTestCase(unittest.HomeserverTestCase):
|
1287 | 1333 |
|
|
0 commit comments