New API /_synapse/admin/rooms/{roomId}/context/{eventId}

Signed-off-by: David Teller <davidt@element.io>
This commit is contained in:
David Teller 2021-01-18 15:02:22 +01:00
parent 34efb4c604
commit 10332c175c
6 changed files with 136 additions and 8 deletions

View file

@ -1430,6 +1430,54 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
self.assertEqual(private_room_id, channel.json_body["joined_rooms"][0])
def test_context(self):
"""
Test that, as admin, we can find the context of an event without having joined the room.
"""
# Create a room. We're not part of it.
user_id = self.register_user("test", "test")
user_tok = self.login("test", "test")
room_id = self.helper.create_room_as(user_id, tok=user_tok)
# Populate the room with events.
events = []
for i in range(30):
events.append(
self.helper.send_event(
room_id, "com.example.test", content={"index": i}, tok=user_tok
)
)
# Now let's fetch the context for this room.
midway = (len(events) - 1) // 2
channel = self.make_request(
"GET",
"/_synapse/admin/v1/rooms/%s/context/%s"
% (room_id, events[midway]["event_id"]),
access_token=self.admin_user_tok,
)
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
self.assertEquals(
channel.json_body["event"]["event_id"], events[midway]["event_id"]
)
for i, found_event in enumerate(channel.json_body["events_before"]):
for j, posted_event in enumerate(events):
if found_event["event_id"] == posted_event["event_id"]:
self.assertTrue(j < midway)
break
else:
self.fail("Event %s from events_before not found" % j)
for i, found_event in enumerate(channel.json_body["events_after"]):
for j, posted_event in enumerate(events):
if found_event["event_id"] == posted_event["event_id"]:
self.assertTrue(j > midway)
break
else:
self.fail("Event %s from events_after not found" % j)
class MakeRoomAdminTestCase(unittest.HomeserverTestCase):
servlets = [