mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-06-02 04:42:11 -04:00
Add a test case for the SendJoinParser (#11441)
This would have caught the bug #11438 introduced in #11217 and fixed in #11439.
This commit is contained in:
parent
e5c5e213ea
commit
776ad3e5e9
3 changed files with 55 additions and 0 deletions
50
tests/federation/transport/test_client.py
Normal file
50
tests/federation/transport/test_client.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
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) -> None:
|
||||
"""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
|
||||
parsed_response = parser.finish()
|
||||
|
||||
# Sanity check the parsing gave us sensible data.
|
||||
self.assertEqual(len(parsed_response.auth_events), 1, parsed_response)
|
||||
self.assertEqual(len(parsed_response.state), 1, parsed_response)
|
||||
self.assertEqual(parsed_response.event_dict, {}, parsed_response)
|
||||
self.assertIsNone(parsed_response.event, parsed_response)
|
Loading…
Add table
Add a link
Reference in a new issue