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

Commit

Permalink
Add a test case for the SendJoinParser
Browse files Browse the repository at this point in the history
This would have caught the bug #11438 introduced in #11217 and fixed in #11439.
  • Loading branch information
David Robertson committed Nov 26, 2021
1 parent 1d8b80b commit 8cd7b00
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/federation/transport/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import json

from synapse.api.room_versions import RoomVersions
from synapse.federation.transport.client import SendJoinParser
from tests.unittest import TestCase


class SendJoinParserTestCase(TestCase):
def test_two_writes(self):
"""Test that the parser can sensibly deserialise an input given in two slices."""
parser = SendJoinParser(RoomVersions.V1, True)
parent_event = {
"content": {
"see_room_version_spec": "The event format changes depending on the room version."
},
"event_id": "$authparent",
"room_id": "!somewhere:example.org",
"type": "m.room.minimal_pdu",
}
state = {
"content": {
"see_room_version_spec": "The event format changes depending on the room version."
},
"event_id": "$DoNotThinkAboutTheEvent",
"room_id": "!somewhere:example.org",
"type": "m.room.minimal_pdu",
}
response = [
200,
{
"auth_chain": [parent_event],
"origin": "matrix.org",
"state": [state],
},
]
serialised_response = json.dumps(response).encode()

# Send data to the parser
parser.write(serialised_response[:100])
parser.write(serialised_response[100:])

# Retrieve the parsed SendJoinResponse
response = parser.finish()

# Sanity check the parsing gave us sensible data.
self.assertEqual(len(response.auth_events), 1, response)
self.assertEqual(len(response.state), 1, response)
self.assertEqual(response.event_dict, {}, response)
self.assertIsNone(response.event, response)

0 comments on commit 8cd7b00

Please sign in to comment.