Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Make room alias lists peekable
Browse files Browse the repository at this point in the history
As per
matrix-org/matrix-spec-proposals#2432 (review),
make room alias lists accessible to users outside world_readable rooms.
  • Loading branch information
richvdh committed Feb 19, 2020
1 parent a0a1fd0 commit 709e81f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion synapse/handlers/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ async def get_aliases_for_room(
# allow access to server admins and current members of the room
is_admin = await self.auth.is_server_admin(requester.user)
if not is_admin:
await self.auth.check_joined_room(room_id, requester.user.to_string())
await self.auth.check_user_in_room_or_world_readable(
room_id, requester.user.to_string()
)

aliases = await self.store.get_aliases_for_room(room_id)
return aliases
17 changes: 17 additions & 0 deletions tests/rest/client/v1/test_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,23 @@ def test_with_aliases(self):
res = self._get_aliases(self.room_owner_tok)
self.assertEqual(set(res["aliases"]), {alias1, alias2})

def test_peekable_room(self):
alias1 = self._random_alias()
self._set_alias_via_directory(alias1)

self.helper.send_state(
self.room_id,
EventTypes.RoomHistoryVisibility,
body={"history_visibility": "world_readable"},
tok=self.room_owner_tok,
)

self.register_user("user", "test")
user_tok = self.login("user", "test")

res = self._get_aliases(user_tok)
self.assertEqual(res["aliases"], [alias1])

def _get_aliases(self, access_token: str, expected_code: int = 200) -> JsonDict:
"""Calls the endpoint under test. returns the json response object."""
request, channel = self.make_request(
Expand Down

0 comments on commit 709e81f

Please sign in to comment.