-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy path51transactions.pl
85 lines (70 loc) · 2.71 KB
/
51transactions.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
test "Server correctly handles transactions that break edu limits",
requires => [ $main::OUTBOUND_CLIENT,
local_user_and_room_fixtures(),
federation_user_id_fixture() ],
do => sub {
my ( $outbound_client, $creator, $room_id, $user_id ) = @_;
$outbound_client->join_room(
server_name => $creator->server_name,
room_id => $room_id,
user_id => $user_id,
)->then( sub {
my ( $room ) = @_;
my $new_event = $room->create_and_insert_event(
type => "m.room.message",
sender => $user_id,
content => {
body => "Message 1",
},
);
# Generate two transactions, one that breaks the 50 PDU limit and one
# that does not
my @bad_pdus = ( $new_event ) x 51;
my @good_pdus = ( $new_event ) x 10;
Future->needs_all(
# Send the transaction to the client and expect a fail
$outbound_client->send_transaction(
pdus => \@bad_pdus,
destination => $creator->server_name,
)->main::expect_http_400(),
# Send the transaction to the client and expect a succeed
$outbound_client->send_transaction(
pdus => \@good_pdus,
destination => $creator->server_name,
)->then( sub {
my ( $response ) = @_;
Future->done( 1 );
}),
);
});
};
# Room version 6 states that homeservers should strictly enforce canonical JSON
# on PDUs. Test that a transaction to `send` with a PDU that has bad data will
# be handled properly.
#
# This enforces that the entire transaction is rejected if a single bad PDU is
# sent. It is unclear if this is the correct behavior or not.
#
# See https://github.com/matrix-org/synapse/issues/7543
test "Server rejects invalid JSON in a version 6 room",
requires => [ $main::OUTBOUND_CLIENT,
federated_rooms_fixture( room_opts => { room_version => "6" } ) ],
do => sub {
my ( $outbound_client, $creator, $user_id, @rooms ) = @_;
my $room = $rooms[0];
my $bad_event = $room->create_and_insert_event(
type => "m.room.message",
sender => $user_id,
content => {
body => "Message 1",
# Insert a "bad" value into the PDU, in this case a float.
bad_val => 1.1,
},
);
my @pdus = ( $bad_event );
# Send the transaction to the client and expect a fail
$outbound_client->send_transaction(
pdus => \@pdus,
destination => $creator->server_name,
)->main::expect_m_bad_json;
};