@@ -1857,6 +1857,46 @@ def test_stream_token_is_accepted_for_fwd_pagianation(self) -> None:
1857
1857
self .assertIn ("chunk" , channel .json_body )
1858
1858
self .assertIn ("end" , channel .json_body )
1859
1859
1860
+ def test_room_messages_backward (self ) -> None :
1861
+ """Test room messages can be retrieved by an admin that isn't in the room."""
1862
+ latest_event_id = self .helper .send (
1863
+ self .room_id , body = "message 1" , tok = self .user_tok
1864
+ )["event_id" ]
1865
+
1866
+ # Check that we get the first and second message when querying /messages.
1867
+ channel = self .make_request (
1868
+ "GET" ,
1869
+ "/_synapse/admin/v1/rooms/%s/messages?dir=b" % (self .room_id ,),
1870
+ access_token = self .admin_user_tok ,
1871
+ )
1872
+ self .assertEqual (channel .code , 200 , channel .json_body )
1873
+
1874
+ chunk = channel .json_body ["chunk" ]
1875
+ self .assertEqual (len (chunk ), 6 , [event ["content" ] for event in chunk ])
1876
+
1877
+ # in backwards, this is the first event
1878
+ self .assertEqual (chunk [0 ]["event_id" ], latest_event_id )
1879
+
1880
+ def test_room_messages_forward (self ) -> None :
1881
+ """Test room messages can be retrieved by an admin that isn't in the room."""
1882
+ latest_event_id = self .helper .send (
1883
+ self .room_id , body = "message 1" , tok = self .user_tok
1884
+ )["event_id" ]
1885
+
1886
+ # Check that we get the first and second message when querying /messages.
1887
+ channel = self .make_request (
1888
+ "GET" ,
1889
+ "/_synapse/admin/v1/rooms/%s/messages?dir=f" % (self .room_id ,),
1890
+ access_token = self .admin_user_tok ,
1891
+ )
1892
+ self .assertEqual (channel .code , 200 , channel .json_body )
1893
+
1894
+ chunk = channel .json_body ["chunk" ]
1895
+ self .assertEqual (len (chunk ), 6 , [event ["content" ] for event in chunk ])
1896
+
1897
+ # in forward, this is the last event
1898
+ self .assertEqual (chunk [5 ]["event_id" ], latest_event_id )
1899
+
1860
1900
def test_room_messages_purge (self ) -> None :
1861
1901
"""Test room messages can be retrieved by an admin that isn't in the room."""
1862
1902
store = self .hs .get_datastores ().main
0 commit comments