Skip to content

Commit 7ff7a31

Browse files
authored
Merge pull request #1399 from matrix-org/quenting/room-v6-bad-json
Check that invalid PDUs are ignored, instead of erroring out
2 parents 2cf761a + 7e2a47e commit 7ff7a31

File tree

1 file changed

+85
-6
lines changed

1 file changed

+85
-6
lines changed

tests/50federation/51transactions.pl

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,114 @@
5151
# on PDUs. Test that a transaction to `send` with a PDU that has bad data will
5252
# be handled properly.
5353
#
54-
# This enforces that the entire transaction is rejected if a single bad PDU is
55-
# sent. It is unclear if this is the correct behavior or not.
54+
# This enforces that invalid PDUs are discarded rather than failing the entire
55+
# transaction.
56+
#
57+
# It is unclear whether the invalid PDU should be included in the /send response
58+
# with an error, which is why there is no assertion on the response.
5659
#
5760
# See https://github.com/matrix-org/synapse/issues/7543
61+
test "Server discards events with invalid JSON in a version 6 room",
62+
requires => [ $main::OUTBOUND_CLIENT,
63+
federated_rooms_fixture( room_opts => { room_version => "6" } ) ],
64+
# This behaviour has only been changed in Synapse, not Dendrite
65+
implementation_specific => ['synapse'],
66+
67+
do => sub {
68+
my ( $outbound_client, $creator, $user_id, @rooms ) = @_;
69+
70+
my $room = $rooms[0];
71+
my $room_id = $room->room_id;
72+
73+
my $good_event = $room->create_and_insert_event(
74+
type => "m.room.message",
75+
76+
sender => $user_id,
77+
content => {
78+
body => "Good event",
79+
},
80+
);
81+
82+
my $bad_event = $room->create_and_insert_event(
83+
type => "m.room.message",
84+
85+
sender => $user_id,
86+
content => {
87+
body => "Bad event",
88+
# Insert a "bad" value into the PDU, in this case a float.
89+
bad_val => 1.1,
90+
},
91+
);
92+
93+
my @pdus = ( $good_event, $bad_event );
94+
95+
# Send the transaction to the client and expect to succeed
96+
$outbound_client->send_transaction(
97+
pdus => \@pdus,
98+
destination => $creator->server_name,
99+
)->then(sub {
100+
# Wait for the good event to be sent down through sync
101+
await_sync_timeline_contains( $creator, $room_id, check => sub {
102+
my ( $event ) = @_;
103+
$event->{type} eq "m.room.message" &&
104+
$event->{content}{body} eq "Good event"
105+
})
106+
})->then(sub {
107+
# Check that we can fetch the good event
108+
my $event_id = $room->id_for_event( $good_event );
109+
do_request_json_for( $creator,
110+
method => "GET",
111+
uri => "/v3/rooms/$room_id/event/$event_id",
112+
)
113+
})->then(sub {
114+
# Check that we have ignored the bad event PDU
115+
my $event_id = $room->id_for_event( $bad_event );
116+
do_request_json_for( $creator,
117+
method => "GET",
118+
uri => "/v3/rooms/$room_id/event/$event_id",
119+
)->main::expect_m_not_found
120+
});
121+
};
122+
123+
# This is an alternative behaviour that isn't spec compliant, where the server
124+
# rejects the whole transaction if any PDU is invalid.
125+
# This is the behaviour that Dendrite currently implements.
58126
test "Server rejects invalid JSON in a version 6 room",
59127
requires => [ $main::OUTBOUND_CLIENT,
60128
federated_rooms_fixture( room_opts => { room_version => "6" } ) ],
129+
implementation_specific => ['dendrite'],
61130

62131
do => sub {
63132
my ( $outbound_client, $creator, $user_id, @rooms ) = @_;
64133

65134
my $room = $rooms[0];
135+
my $room_id = $room->room_id;
136+
137+
my $good_event = $room->create_and_insert_event(
138+
type => "m.room.message",
139+
140+
sender => $user_id,
141+
content => {
142+
body => "Good event",
143+
},
144+
);
66145

67146
my $bad_event = $room->create_and_insert_event(
68147
type => "m.room.message",
69148

70149
sender => $user_id,
71150
content => {
72-
body => "Message 1",
151+
body => "Bad event",
73152
# Insert a "bad" value into the PDU, in this case a float.
74153
bad_val => 1.1,
75154
},
76155
);
77156

78-
my @pdus = ( $bad_event );
157+
my @pdus = ( $good_event, $bad_event );
79158

80-
# Send the transaction to the client and expect a fail
159+
# Send the transaction to the client and expect to fail
81160
$outbound_client->send_transaction(
82161
pdus => \@pdus,
83162
destination => $creator->server_name,
84-
)->main::expect_m_bad_json;
163+
)->main::expect_m_bad_json
85164
};

0 commit comments

Comments
 (0)