|
51 | 51 | # on PDUs. Test that a transaction to `send` with a PDU that has bad data will
|
52 | 52 | # be handled properly.
|
53 | 53 | #
|
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. |
56 | 59 | #
|
57 | 60 | # 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. |
58 | 126 | test "Server rejects invalid JSON in a version 6 room",
|
59 | 127 | requires => [ $main::OUTBOUND_CLIENT,
|
60 | 128 | federated_rooms_fixture( room_opts => { room_version => "6" } ) ],
|
| 129 | + implementation_specific => ['dendrite'], |
61 | 130 |
|
62 | 131 | do => sub {
|
63 | 132 | my ( $outbound_client, $creator, $user_id, @rooms ) = @_;
|
64 | 133 |
|
65 | 134 | 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 | + ); |
66 | 145 |
|
67 | 146 | my $bad_event = $room->create_and_insert_event(
|
68 | 147 | type => "m.room.message",
|
69 | 148 |
|
70 | 149 | sender => $user_id,
|
71 | 150 | content => {
|
72 |
| - body => "Message 1", |
| 151 | + body => "Bad event", |
73 | 152 | # Insert a "bad" value into the PDU, in this case a float.
|
74 | 153 | bad_val => 1.1,
|
75 | 154 | },
|
76 | 155 | );
|
77 | 156 |
|
78 |
| - my @pdus = ( $bad_event ); |
| 157 | + my @pdus = ( $good_event, $bad_event ); |
79 | 158 |
|
80 |
| - # Send the transaction to the client and expect a fail |
| 159 | + # Send the transaction to the client and expect to fail |
81 | 160 | $outbound_client->send_transaction(
|
82 | 161 | pdus => \@pdus,
|
83 | 162 | destination => $creator->server_name,
|
84 |
| - )->main::expect_m_bad_json; |
| 163 | + )->main::expect_m_bad_json |
85 | 164 | };
|
0 commit comments