From b9d5f82a015ccca844059a55f5d62ae7676fc2cf Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 30 Jan 2019 14:31:44 +0000 Subject: [PATCH 1/3] Add test for PDU limit on transactions API --- tests/50federation/51transactions.pl | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/50federation/51transactions.pl diff --git a/tests/50federation/51transactions.pl b/tests/50federation/51transactions.pl new file mode 100644 index 000000000..e8e3a2629 --- /dev/null +++ b/tests/50federation/51transactions.pl @@ -0,0 +1,46 @@ +test "Server correctly handles transactions that break edu limits", + requires => [ $main::OUTBOUND_CLIENT, $main::INBOUND_SERVER, $main::HOMESERVER_INFO[0], + local_user_and_room_fixtures( user_opts => { with_events => 1 } ), + federation_user_id_fixture(), room_alias_name_fixture() ], + + do => sub { + my ( $outbound_client, $inbound_server, $info, $creator, $room_id, $creator_id, $room_alias_name ) = @_; + + my $local_server_name = $info->server_name; + + my $remote_server_name = $inbound_server->server_name; + my $datastore = $inbound_server->datastore; + + my $room_alias = "#$room_alias_name:$remote_server_name"; + + my $device_id = "random_device_id"; + + $outbound_client->join_room( + server_name => $local_server_name, + room_id => $room_id, + user_id => $creator_id, + )->then( sub { + my ( $room ) = @_; + + my $new_event = $room->create_and_insert_event( + type => "m.room.message", + + sender => $creator_id, + content => { + body => "Message 1", + }, + ); + + # Generate a messge with 51 PDUs + my @pdus = (); + for my $i ( 0 .. 50 ) { + push @pdus, $new_event; + } + + # Send the transaction to the client + $outbound_client->send_transaction( + pdus => \@pdus, + destination => $local_server_name, + )->main::expect_http_400(); + }); + }; From d95e7fd85ce72697863a919da6a88aaaae5cd2bd Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 30 Jan 2019 16:46:26 +0000 Subject: [PATCH 2/3] Fixes and additional check for under-limit transactions --- tests/50federation/51transactions.pl | 38 +++++++++++++++++----------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/tests/50federation/51transactions.pl b/tests/50federation/51transactions.pl index e8e3a2629..1d357108a 100644 --- a/tests/50federation/51transactions.pl +++ b/tests/50federation/51transactions.pl @@ -1,6 +1,6 @@ test "Server correctly handles transactions that break edu limits", requires => [ $main::OUTBOUND_CLIENT, $main::INBOUND_SERVER, $main::HOMESERVER_INFO[0], - local_user_and_room_fixtures( user_opts => { with_events => 1 } ), + local_user_and_room_fixtures(), federation_user_id_fixture(), room_alias_name_fixture() ], do => sub { @@ -9,12 +9,9 @@ my $local_server_name = $info->server_name; my $remote_server_name = $inbound_server->server_name; - my $datastore = $inbound_server->datastore; my $room_alias = "#$room_alias_name:$remote_server_name"; - my $device_id = "random_device_id"; - $outbound_client->join_room( server_name => $local_server_name, room_id => $room_id, @@ -31,16 +28,27 @@ }, ); - # Generate a messge with 51 PDUs - my @pdus = (); - for my $i ( 0 .. 50 ) { - push @pdus, $new_event; - } - - # Send the transaction to the client - $outbound_client->send_transaction( - pdus => \@pdus, - destination => $local_server_name, - )->main::expect_http_400(); + # 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 => $local_server_name, + )->main::expect_http_400(), + + # Send the transaction to the client and expect a succeed + $outbound_client->send_transaction( + pdus => \@good_pdus, + destination => $local_server_name, + )->then( sub { + my ( $response ) = @_; + + Future->done( 1 ); + }), + ); }); }; From 9b9b6ae7322bd9e50761ba6044e4e336f107068f Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 30 Jan 2019 17:41:08 +0000 Subject: [PATCH 3/3] Remove --- tests/50federation/51transactions.pl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/50federation/51transactions.pl b/tests/50federation/51transactions.pl index 1d357108a..637da1387 100644 --- a/tests/50federation/51transactions.pl +++ b/tests/50federation/51transactions.pl @@ -1,10 +1,9 @@ test "Server correctly handles transactions that break edu limits", requires => [ $main::OUTBOUND_CLIENT, $main::INBOUND_SERVER, $main::HOMESERVER_INFO[0], - local_user_and_room_fixtures(), - federation_user_id_fixture(), room_alias_name_fixture() ], + local_user_and_room_fixtures(), room_alias_name_fixture() ], do => sub { - my ( $outbound_client, $inbound_server, $info, $creator, $room_id, $creator_id, $room_alias_name ) = @_; + my ( $outbound_client, $inbound_server, $info, $creator, $room_id, $room_alias_name ) = @_; my $local_server_name = $info->server_name; @@ -15,14 +14,14 @@ $outbound_client->join_room( server_name => $local_server_name, room_id => $room_id, - user_id => $creator_id, + user_id => $creator->user_id, )->then( sub { my ( $room ) = @_; my $new_event = $room->create_and_insert_event( type => "m.room.message", - sender => $creator_id, + sender => $creator->user_id, content => { body => "Message 1", },