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

Stop sending incorrect knock_state_events. #16403

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/16403.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove legacy unspecced `knock_state_events` field returned in some responses.
4 changes: 2 additions & 2 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ async def send_knock(self, destinations: List[str], pdu: EventBase) -> JsonDict:
The remote homeserver return some state from the room. The response
dictionary is in the form:

{"knock_state_events": [<state event dict>, ...]}
{"knock_room_state": [<state event dict>, ...]}

The list of state events may be empty.

Expand All @@ -1429,7 +1429,7 @@ async def _do_send_knock(self, destination: str, pdu: EventBase) -> JsonDict:
The remote homeserver can optionally return some state from the room. The response
dictionary is in the form:

{"knock_state_events": [<state event dict>, ...]}
{"knock_room_state": [<state event dict>, ...]}

The list of state events may be empty.
"""
Expand Down
9 changes: 1 addition & 8 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,14 +850,7 @@ async def on_send_knock_request(
context, self._room_prejoin_state_types
)
)
return {
"knock_room_state": stripped_room_state,
# Since v1.37, Synapse incorrectly used "knock_state_events" for this field.
# Thus, we also populate a 'knock_state_events' with the same content to
# support old instances.
# See https://github.com/matrix-org/synapse/issues/14088.
"knock_state_events": stripped_room_state,
}
return {"knock_room_state": stripped_room_state}

async def _on_send_membership_event(
self, origin: str, content: JsonDict, membership_type: str, room_id: str
Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/transport/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ async def send_knock_v1(
The remote homeserver can optionally return some state from the room. The response
dictionary is in the form:

{"knock_state_events": [<state event dict>, ...]}
{"knock_room_state": [<state event dict>, ...]}

The list of state events may be empty.
"""
Expand Down
13 changes: 2 additions & 11 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,19 +868,10 @@ async def do_knock(
# This is a bit of a hack and is cribbing off of invites. Basically we
# store the room state here and retrieve it again when this event appears
# in the invitee's sync stream. It is stripped out for all other local users.
stripped_room_state = (
knock_response.get("knock_room_state")
# Since v1.37, Synapse incorrectly used "knock_state_events" for this field.
# Thus, we also check for a 'knock_state_events' to support old instances.
# See https://github.com/matrix-org/synapse/issues/14088.
or knock_response.get("knock_state_events")
)
stripped_room_state = knock_response.get("knock_room_state")

if stripped_room_state is None:
raise KeyError(
"Missing 'knock_room_state' (or legacy 'knock_state_events') field in "
"send_knock response"
)
raise KeyError("Missing 'knock_room_state' field in send_knock response")

event.unsigned["knock_room_state"] = stripped_room_state

Expand Down
2 changes: 1 addition & 1 deletion tests/federation/transport/test_knocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def test_room_state_returned_when_knocking(self) -> None:
self.assertEqual(200, channel.code, channel.result)

# Check that we got the stripped room state in return
room_state_events = channel.json_body["knock_state_events"]
room_state_events = channel.json_body["knock_room_state"]

# Validate the stripped room state events
self.check_knock_room_state_against_room_state(
Expand Down
Loading