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

Commit

Permalink
Additional error checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Aug 11, 2021
1 parent 9ccef14 commit ef4329f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
16 changes: 15 additions & 1 deletion synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,14 +1332,28 @@ async def send_request(
if not isinstance(room, dict):
raise InvalidResponseError("'room' must be a dict")

# TODO Validate children_state of the room.
# Validate children_state of the room.
children_state = room.get("children_state", [])
if not isinstance(children_state, Sequence):
raise InvalidResponseError("'room.children_state' must be a list")
if any(not isinstance(e, dict) for e in children_state):
raise InvalidResponseError("Invalid event in 'children_state' list")
try:
[
FederationSpaceSummaryEventResult.from_json_dict(e)
for e in children_state
]
except ValueError as e:
raise InvalidResponseError(str(e))

# Validate the children rooms.
children = res.get("children", [])
if not isinstance(children, Sequence):
raise InvalidResponseError("'children' must be a list")
if any(not isinstance(r, dict) for r in children):
raise InvalidResponseError("Invalid room in 'children' list")

# Validate the inaccessible children.
inaccessible_children = res.get("inaccessible_children", [])
if not isinstance(inaccessible_children, Sequence):
raise InvalidResponseError("'inaccessible_children' must be a list")
Expand Down
3 changes: 2 additions & 1 deletion synapse/handlers/space_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ async def _get_room_hierarchy(
children_room_entries.get(ev["state_key"]),
)
for ev in reversed(room_entry.children)
if ev["state_key"] not in inaccessible_children
if ev["type"] == EventTypes.SpaceChild
and ev["state_key"] not in inaccessible_children
)

result: JsonDict = {"rooms": rooms_result}
Expand Down
4 changes: 3 additions & 1 deletion tests/handlers/test_space_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def test_pagination(self):
self.assertNotIn("next_token", result)

def test_invalid_pagination_token(self):
""""""
"""An invalid pagination token, or changing other parameters, shoudl be rejected."""
room_ids = []
for i in range(1, 10):
room = self.helper.create_room_as(self.user, tok=self.token)
Expand Down Expand Up @@ -575,6 +575,7 @@ def test_fed_complex(self):
},
[
{
"type": EventTypes.SpaceChild,
"room_id": subspace,
"state_key": subroom,
"content": {"via": [fed_hostname]},
Expand Down Expand Up @@ -731,6 +732,7 @@ def test_fed_filtering(self):
# Place each room in the sub-space.
[
{
"type": EventTypes.SpaceChild,
"room_id": subspace,
"state_key": room_id,
"content": {"via": [fed_hostname]},
Expand Down

0 comments on commit ef4329f

Please sign in to comment.