summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMichael Telatynski <7t3chguy@gmail.com>2021-08-16 15:49:12 +0100
committerGitHub <noreply@github.com>2021-08-16 14:49:12 +0000
commit0ace38b7b310fc1b4f88ac93d01ec900f33f7a07 (patch)
treebb160a73520626885425129aa088d1135dcc77f7 /tests
parentSplit `synapse.federation.transport.server` into multiple files. (#10590) (diff)
downloadsynapse-0ace38b7b310fc1b4f88ac93d01ec900f33f7a07.tar.xz
Experimental support for MSC3266 Room Summary API. (#10394)
Diffstat (limited to 'tests')
-rw-r--r--tests/handlers/test_room_summary.py (renamed from tests/handlers/test_space_summary.py)108
1 files changed, 93 insertions, 15 deletions
diff --git a/tests/handlers/test_space_summary.py b/tests/handlers/test_room_summary.py
index bc8e131f4a..732d746e38 100644
--- a/tests/handlers/test_space_summary.py
+++ b/tests/handlers/test_room_summary.py
@@ -23,10 +23,10 @@ from synapse.api.constants import (
     RestrictedJoinRuleTypes,
     RoomTypes,
 )
-from synapse.api.errors import AuthError, SynapseError
+from synapse.api.errors import AuthError, NotFoundError, SynapseError
 from synapse.api.room_versions import RoomVersions
 from synapse.events import make_event_from_dict
-from synapse.handlers.space_summary import _child_events_comparison_key, _RoomEntry
+from synapse.handlers.room_summary import _child_events_comparison_key, _RoomEntry
 from synapse.rest import admin
 from synapse.rest.client.v1 import login, room
 from synapse.server import HomeServer
@@ -106,7 +106,7 @@ class SpaceSummaryTestCase(unittest.HomeserverTestCase):
 
     def prepare(self, reactor, clock, hs: HomeServer):
         self.hs = hs
-        self.handler = self.hs.get_space_summary_handler()
+        self.handler = self.hs.get_room_summary_handler()
 
         # Create a user.
         self.user = self.register_user("user", "pass")
@@ -624,14 +624,14 @@ class SpaceSummaryTestCase(unittest.HomeserverTestCase):
                 ),
             ]
 
-        async def summarize_remote_room_hiearchy(_self, room, suggested_only):
+        async def summarize_remote_room_hierarchy(_self, room, suggested_only):
             return requested_room_entry, {subroom: child_room}, set()
 
         # Add a room to the space which is on another server.
         self._add_child(self.space, subspace, self.token)
 
         with mock.patch(
-            "synapse.handlers.space_summary.SpaceSummaryHandler._summarize_remote_room",
+            "synapse.handlers.room_summary.RoomSummaryHandler._summarize_remote_room",
             new=summarize_remote_room,
         ):
             result = self.get_success(
@@ -647,8 +647,8 @@ class SpaceSummaryTestCase(unittest.HomeserverTestCase):
         self._assert_rooms(result, expected)
 
         with mock.patch(
-            "synapse.handlers.space_summary.SpaceSummaryHandler._summarize_remote_room_hiearchy",
-            new=summarize_remote_room_hiearchy,
+            "synapse.handlers.room_summary.RoomSummaryHandler._summarize_remote_room_hierarchy",
+            new=summarize_remote_room_hierarchy,
         ):
             result = self.get_success(
                 self.handler.get_room_hierarchy(self.user, self.space)
@@ -774,14 +774,14 @@ class SpaceSummaryTestCase(unittest.HomeserverTestCase):
                 for child_room in children_rooms
             ]
 
-        async def summarize_remote_room_hiearchy(_self, room, suggested_only):
+        async def summarize_remote_room_hierarchy(_self, room, suggested_only):
             return subspace_room_entry, dict(children_rooms), set()
 
         # Add a room to the space which is on another server.
         self._add_child(self.space, subspace, self.token)
 
         with mock.patch(
-            "synapse.handlers.space_summary.SpaceSummaryHandler._summarize_remote_room",
+            "synapse.handlers.room_summary.RoomSummaryHandler._summarize_remote_room",
             new=summarize_remote_room,
         ):
             result = self.get_success(
@@ -814,8 +814,8 @@ class SpaceSummaryTestCase(unittest.HomeserverTestCase):
         self._assert_rooms(result, expected)
 
         with mock.patch(
-            "synapse.handlers.space_summary.SpaceSummaryHandler._summarize_remote_room_hiearchy",
-            new=summarize_remote_room_hiearchy,
+            "synapse.handlers.room_summary.RoomSummaryHandler._summarize_remote_room_hierarchy",
+            new=summarize_remote_room_hierarchy,
         ):
             result = self.get_success(
                 self.handler.get_room_hierarchy(self.user, self.space)
@@ -850,14 +850,14 @@ class SpaceSummaryTestCase(unittest.HomeserverTestCase):
         ):
             return [fed_room_entry]
 
-        async def summarize_remote_room_hiearchy(_self, room, suggested_only):
+        async def summarize_remote_room_hierarchy(_self, room, suggested_only):
             return fed_room_entry, {}, set()
 
         # Add a room to the space which is on another server.
         self._add_child(self.space, fed_room, self.token)
 
         with mock.patch(
-            "synapse.handlers.space_summary.SpaceSummaryHandler._summarize_remote_room",
+            "synapse.handlers.room_summary.RoomSummaryHandler._summarize_remote_room",
             new=summarize_remote_room,
         ):
             result = self.get_success(
@@ -872,10 +872,88 @@ class SpaceSummaryTestCase(unittest.HomeserverTestCase):
         self._assert_rooms(result, expected)
 
         with mock.patch(
-            "synapse.handlers.space_summary.SpaceSummaryHandler._summarize_remote_room_hiearchy",
-            new=summarize_remote_room_hiearchy,
+            "synapse.handlers.room_summary.RoomSummaryHandler._summarize_remote_room_hierarchy",
+            new=summarize_remote_room_hierarchy,
         ):
             result = self.get_success(
                 self.handler.get_room_hierarchy(self.user, self.space)
             )
         self._assert_hierarchy(result, expected)
+
+
+class RoomSummaryTestCase(unittest.HomeserverTestCase):
+    servlets = [
+        admin.register_servlets_for_client_rest_resource,
+        room.register_servlets,
+        login.register_servlets,
+    ]
+
+    def prepare(self, reactor, clock, hs: HomeServer):
+        self.hs = hs
+        self.handler = self.hs.get_room_summary_handler()
+
+        # Create a user.
+        self.user = self.register_user("user", "pass")
+        self.token = self.login("user", "pass")
+
+        # Create a simple room.
+        self.room = self.helper.create_room_as(self.user, tok=self.token)
+        self.helper.send_state(
+            self.room,
+            event_type=EventTypes.JoinRules,
+            body={"join_rule": JoinRules.INVITE},
+            tok=self.token,
+        )
+
+    def test_own_room(self):
+        """Test a simple room created by the requester."""
+        result = self.get_success(self.handler.get_room_summary(self.user, self.room))
+        self.assertEqual(result.get("room_id"), self.room)
+
+    def test_visibility(self):
+        """A user not in a private room cannot get its summary."""
+        user2 = self.register_user("user2", "pass")
+        token2 = self.login("user2", "pass")
+
+        # The user cannot see the room.
+        self.get_failure(self.handler.get_room_summary(user2, self.room), NotFoundError)
+
+        # If the room is made world-readable it should return a result.
+        self.helper.send_state(
+            self.room,
+            event_type=EventTypes.RoomHistoryVisibility,
+            body={"history_visibility": HistoryVisibility.WORLD_READABLE},
+            tok=self.token,
+        )
+        result = self.get_success(self.handler.get_room_summary(user2, self.room))
+        self.assertEqual(result.get("room_id"), self.room)
+
+        # Make it not world-readable again and confirm it results in an error.
+        self.helper.send_state(
+            self.room,
+            event_type=EventTypes.RoomHistoryVisibility,
+            body={"history_visibility": HistoryVisibility.JOINED},
+            tok=self.token,
+        )
+        self.get_failure(self.handler.get_room_summary(user2, self.room), NotFoundError)
+
+        # If the room is made public it should return a result.
+        self.helper.send_state(
+            self.room,
+            event_type=EventTypes.JoinRules,
+            body={"join_rule": JoinRules.PUBLIC},
+            tok=self.token,
+        )
+        result = self.get_success(self.handler.get_room_summary(user2, self.room))
+        self.assertEqual(result.get("room_id"), self.room)
+
+        # Join the space, make it invite-only again and results should be returned.
+        self.helper.join(self.room, user2, tok=token2)
+        self.helper.send_state(
+            self.room,
+            event_type=EventTypes.JoinRules,
+            body={"join_rule": JoinRules.INVITE},
+            tok=self.token,
+        )
+        result = self.get_success(self.handler.get_room_summary(user2, self.room))
+        self.assertEqual(result.get("room_id"), self.room)