Stop sending incorrect knock_state_events. (#16403)

Synapse was incorrectly implemented with a knock_state_events
property on some APIs (instead of knock_room_state). This was
correct in Synapse 1.70.0, but *both* fields were sent to also be
compatible with Synapse versions expecting the wrong field.

Enough time has passed that only the correct field needs to be
included/handled.
This commit is contained in:
Patrick Cloke 2023-10-06 07:27:35 -04:00 committed by GitHub
parent ae5b997cfa
commit fc31b495b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 23 deletions

1
changelog.d/16403.bugfix Normal file
View File

@ -0,0 +1 @@
Remove legacy unspecced `knock_state_events` field returned in some responses.

View File

@ -1402,7 +1402,7 @@ class FederationClient(FederationBase):
The remote homeserver return some state from the room. The response The remote homeserver return some state from the room. The response
dictionary is in the form: 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. The list of state events may be empty.
@ -1429,7 +1429,7 @@ class FederationClient(FederationBase):
The remote homeserver can optionally return some state from the room. The response The remote homeserver can optionally return some state from the room. The response
dictionary is in the form: 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. The list of state events may be empty.
""" """

View File

@ -850,14 +850,7 @@ class FederationServer(FederationBase):
context, self._room_prejoin_state_types context, self._room_prejoin_state_types
) )
) )
return { return {"knock_room_state": stripped_room_state}
"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,
}
async def _on_send_membership_event( async def _on_send_membership_event(
self, origin: str, content: JsonDict, membership_type: str, room_id: str self, origin: str, content: JsonDict, membership_type: str, room_id: str

View File

@ -431,7 +431,7 @@ class TransportLayerClient:
The remote homeserver can optionally return some state from the room. The response The remote homeserver can optionally return some state from the room. The response
dictionary is in the form: 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. The list of state events may be empty.
""" """

View File

@ -868,19 +868,10 @@ class FederationHandler:
# This is a bit of a hack and is cribbing off of invites. Basically we # 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 # 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. # in the invitee's sync stream. It is stripped out for all other local users.
stripped_room_state = ( stripped_room_state = knock_response.get("knock_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")
)
if stripped_room_state is None: if stripped_room_state is None:
raise KeyError( raise KeyError("Missing 'knock_room_state' field in send_knock response")
"Missing 'knock_room_state' (or legacy 'knock_state_events') field in "
"send_knock response"
)
event.unsigned["knock_room_state"] = stripped_room_state event.unsigned["knock_room_state"] = stripped_room_state

View File

@ -308,7 +308,7 @@ class FederationKnockingTestCase(
self.assertEqual(200, channel.code, channel.result) self.assertEqual(200, channel.code, channel.result)
# Check that we got the stripped room state in return # 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 # Validate the stripped room state events
self.check_knock_room_state_against_room_state( self.check_knock_room_state_against_room_state(