This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test case for the SendJoinParser (#11441)
- Loading branch information
David Robertson
authored
Nov 29, 2021
1 parent
e5c5e21
commit 776ad3e
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a bug introduced in 1.47.0 where `send_join` could fail due to an outdated `ijson` version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |