def test_fed(self): """ Return data over federation and ensure that it is handled properly. """ fed_hostname = self.hs.hostname + "2" fed_room = "#fed_room:" + fed_hostname requested_room_entry = _RoomEntry( fed_room, { "room_id": fed_room, "world_readable": True }, ) async def summarize_remote_room_hierarchy(_self, room, suggested_only): return requested_room_entry, {}, set() with mock.patch( "synapse.handlers.room_summary.RoomSummaryHandler._summarize_remote_room_hierarchy", new=summarize_remote_room_hierarchy, ): result = self.get_success( self.handler.get_room_summary(self.user, fed_room, remote_room_hosts=[fed_hostname ])) self.assertEqual(result.get("room_id"), fed_room)
async def summarize_remote_room(_self, room, suggested_only, max_children, exclude_rooms): return [subspace_room_entry] + [ # A copy is made of the room data since the allowed_spaces key # is removed. _RoomEntry(child_room[0], dict(child_room[1])) for child_room in children_rooms ]
def test_fed_complex(self): """ Return data over federation and ensure that it is handled properly. """ fed_hostname = self.hs.hostname + "2" subspace = "#subspace:" + fed_hostname subroom = "#subroom:" + fed_hostname # Generate some good data, and some bad data: # # * Event *back* to the root room. # * Unrelated events / rooms # * Multiple levels of events (in a not-useful order, e.g. grandchild # events before child events). # Note that these entries are brief, but should contain enough info. requested_room_entry = _RoomEntry( subspace, { "room_id": subspace, "world_readable": True, "room_type": RoomTypes.SPACE, }, [{ "type": EventTypes.SpaceChild, "room_id": subspace, "state_key": subroom, "content": { "via": [fed_hostname] }, }], ) child_room = { "room_id": subroom, "world_readable": True, } 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) expected = [ (self.space, [self.room, subspace]), (self.room, ()), (subspace, [subroom]), (subroom, ()), ] with mock.patch( "synapse.handlers.room_summary.RoomSummaryHandler._summarize_remote_room_hierarchy", new=summarize_remote_room_hierarchy, ): result = self.get_success( self.handler.get_room_hierarchy(create_requester(self.user), self.space)) self._assert_hierarchy(result, expected)
def test_fed_invited(self): """ A room which the user was invited to should be included in the response. This differs from test_fed_filtering in that the room itself is being queried over federation, instead of it being included as a sub-room of a space in the response. """ fed_hostname = self.hs.hostname + "2" fed_room = "#subroom:" + fed_hostname # Poke an invite over federation into the database. self._poke_fed_invite(fed_room, "@remote:" + fed_hostname) fed_room_entry = _RoomEntry( fed_room, { "room_id": fed_room, "world_readable": False, "join_rules": JoinRules.INVITE, }, ) async def summarize_remote_room(_self, room, suggested_only, max_children, exclude_rooms): return [fed_room_entry] 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.room_summary.RoomSummaryHandler._summarize_remote_room", new=summarize_remote_room, ): result = self.get_success( self.handler.get_space_summary(self.user, self.space)) expected = [ (self.space, [self.room, fed_room]), (self.room, ()), (fed_room, ()), ] self._assert_rooms(result, expected) with mock.patch( "synapse.handlers.room_summary.RoomSummaryHandler._summarize_remote_room_hierarchy", new=summarize_remote_room_hierarchy, ): result = self.get_success( self.handler.get_room_hierarchy(create_requester(self.user), self.space)) self._assert_hierarchy(result, expected)
async def summarize_remote_room(_self, room, suggested_only, max_children, exclude_rooms): return [ requested_room_entry, _RoomEntry( subroom, { "room_id": subroom, "world_readable": True, }, ), ]
def test_fed_filtering(self): """ Rooms returned over federation should be properly filtered to only include rooms the user has access to. """ fed_hostname = self.hs.hostname + "2" subspace = "#subspace:" + fed_hostname # Create a few rooms which will have different properties. public_room = "#public:" + fed_hostname knock_room = "#knock:" + fed_hostname not_invited_room = "#not_invited:" + fed_hostname invited_room = "#invited:" + fed_hostname restricted_room = "#restricted:" + fed_hostname restricted_accessible_room = "#restricted_accessible:" + fed_hostname world_readable_room = "#world_readable:" + fed_hostname joined_room = self.helper.create_room_as(self.user, tok=self.token) # Poke an invite over federation into the database. self._poke_fed_invite(invited_room, "@remote:" + fed_hostname) # Note that these entries are brief, but should contain enough info. children_rooms = ( ( public_room, { "room_id": public_room, "world_readable": False, "join_rules": JoinRules.PUBLIC, }, ), ( knock_room, { "room_id": knock_room, "world_readable": False, "join_rules": JoinRules.KNOCK, }, ), ( not_invited_room, { "room_id": not_invited_room, "world_readable": False, "join_rules": JoinRules.INVITE, }, ), ( invited_room, { "room_id": invited_room, "world_readable": False, "join_rules": JoinRules.INVITE, }, ), ( restricted_room, { "room_id": restricted_room, "world_readable": False, "join_rules": JoinRules.RESTRICTED, "allowed_spaces": [], }, ), ( restricted_accessible_room, { "room_id": restricted_accessible_room, "world_readable": False, "join_rules": JoinRules.RESTRICTED, "allowed_spaces": [self.room], }, ), ( world_readable_room, { "room_id": world_readable_room, "world_readable": True, "join_rules": JoinRules.INVITE, }, ), ( joined_room, { "room_id": joined_room, "world_readable": False, "join_rules": JoinRules.INVITE, }, ), ) subspace_room_entry = _RoomEntry( subspace, { "room_id": subspace, "world_readable": True, }, # Place each room in the sub-space. [{ "type": EventTypes.SpaceChild, "room_id": subspace, "state_key": room_id, "content": { "via": [fed_hostname] }, } for room_id, _ in children_rooms], ) async def summarize_remote_room(_self, room, suggested_only, max_children, exclude_rooms): return [subspace_room_entry] + [ # A copy is made of the room data since the allowed_spaces key # is removed. _RoomEntry(child_room[0], dict(child_room[1])) for child_room in children_rooms ] 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.room_summary.RoomSummaryHandler._summarize_remote_room", new=summarize_remote_room, ): result = self.get_success( self.handler.get_space_summary(self.user, self.space)) expected = [ (self.space, [self.room, subspace]), (self.room, ()), ( subspace, [ public_room, knock_room, not_invited_room, invited_room, restricted_room, restricted_accessible_room, world_readable_room, joined_room, ], ), (public_room, ()), (knock_room, ()), (invited_room, ()), (restricted_accessible_room, ()), (world_readable_room, ()), (joined_room, ()), ] self._assert_rooms(result, expected) with mock.patch( "synapse.handlers.room_summary.RoomSummaryHandler._summarize_remote_room_hierarchy", new=summarize_remote_room_hierarchy, ): result = self.get_success( self.handler.get_room_hierarchy(create_requester(self.user), self.space)) self._assert_hierarchy(result, expected)