Skip to content

Commit

Permalink
Merge pull request #545 from matrix-org/erikj/fed_v2_invite_server
Browse files Browse the repository at this point in the history
Test sending v2 invites to server
  • Loading branch information
erikjohnston authored Jan 21, 2019
2 parents 742348d + 9fb07b4 commit cd3e3c5
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 44 deletions.
8 changes: 4 additions & 4 deletions lib/SyTest/Federation/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ sub send_transaction
$self->do_request_json(
method => "PUT",
hostname => $params{destination},
uri => "/send/$ts/",
uri => "/v1/send/$ts/",

content => \%transaction,
);
Expand Down Expand Up @@ -176,7 +176,7 @@ sub join_room
$self->do_request_json(
method => "GET",
hostname => $server_name,
uri => "/make_join/$room_id/$user_id"
uri => "/v1/make_join/$room_id/$user_id"
)->then( sub {
my ( $body ) = @_;

Expand All @@ -197,7 +197,7 @@ sub join_room
$self->do_request_json(
method => "PUT",
hostname => $server_name,
uri => "/send_join/$room_id/$member_event{event_id}",
uri => "/v1/send_join/$room_id/$member_event{event_id}",

content => \%member_event,
)->then( sub {
Expand Down Expand Up @@ -253,7 +253,7 @@ sub get_remote_forward_extremities
$self->do_request_json(
method => "GET",
hostname => $server_name,
uri => "/make_join/$room_id/$user_id",
uri => "/v1/make_join/$room_id/$user_id",
)->then( sub {
my ( $resp ) = @_;

Expand Down
2 changes: 1 addition & 1 deletion tests/50federation/00prepare.pl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ sub create_federation_server

my $outbound_client = SyTest::Federation::Client->new(
datastore => $datastore,
uri_base => "/_matrix/federation/v1",
uri_base => "/_matrix/federation",
);
$loop->add( $outbound_client );

Expand Down
2 changes: 1 addition & 1 deletion tests/50federation/10query-profile.pl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
$outbound_client->do_request_json(
method => "GET",
hostname => $info->server_name,
uri => "/query/profile",
uri => "/v1/query/profile",

params => {
user_id => $user->user_id,
Expand Down
2 changes: 1 addition & 1 deletion tests/50federation/11query-directory.pl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/query/directory",
uri => "/v1/query/directory",

params => {
room_alias => $room_alias,
Expand Down
12 changes: 6 additions & 6 deletions tests/50federation/30room-join.pl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ sub assert_is_valid_pdu {
$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/make_join/$room_id/$user_id",
uri => "/v1/make_join/$room_id/$user_id",
)->then( sub {
my ( $body ) = @_;
log_if_fail "make_join body", $body;
Expand Down Expand Up @@ -278,7 +278,7 @@ sub assert_is_valid_pdu {
$outbound_client->do_request_json(
method => "PUT",
hostname => $first_home_server,
uri => "/send_join/$room_id/$event{event_id}",
uri => "/v1/send_join/$room_id/$event{event_id}",

content => \%event,
)
Expand Down Expand Up @@ -356,7 +356,7 @@ sub assert_is_valid_pdu {
$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/make_join/$room_id/$user_id",
uri => "/v1/make_join/$room_id/$user_id",
params => {
ver => [qw/2 abc def/],
},
Expand Down Expand Up @@ -393,7 +393,7 @@ sub assert_is_valid_pdu {
$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/make_join/$room_id/$user_id",
uri => "/v1/make_join/$room_id/$user_id",
);
})->main::expect_http_400()
->then( sub {
Expand Down Expand Up @@ -427,7 +427,7 @@ sub assert_is_valid_pdu {
$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/make_join/$room_id/$user_id",
uri => "/v1/make_join/$room_id/$user_id",
params => {
ver => ["1"],
},
Expand Down Expand Up @@ -464,7 +464,7 @@ sub assert_is_valid_pdu {
$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/make_join/$room_id/$user_id",
uri => "/v1/make_join/$room_id/$user_id",
params => {
ver => [qw/abc vdh-test-version def/],
},
Expand Down
6 changes: 3 additions & 3 deletions tests/50federation/32room-getevent.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/event/$member_event->{event_id}/",
uri => "/v1/event/$member_event->{event_id}/",
);
})->then( sub {
my ( $body ) = @_;
Expand Down Expand Up @@ -73,7 +73,7 @@
$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/event/$message_id/",
uri => "/v1/event/$message_id/",
);
})->then( sub {
my ( $body ) = @_;
Expand All @@ -96,7 +96,7 @@
$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/event/$message_id/",
uri => "/v1/event/$message_id/",
);
})->then( sub {
my ( $body ) = @_;
Expand Down
2 changes: 1 addition & 1 deletion tests/50federation/33room-get-missing-events.pl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
$outbound_client->do_request_json(
method => "POST",
hostname => $first_home_server,
uri => "/get_missing_events/" . $room->room_id,
uri => "/v1/get_missing_events/" . $room->room_id,

content => {
earliest_events => [ $creation_event->{event_id} ],
Expand Down
4 changes: 2 additions & 2 deletions tests/50federation/34room-backfill.pl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/backfill/$room_id/",
uri => "/v1/backfill/$room_id/",

params => {
v => $join_event->{prev_events}[0][0],
Expand Down Expand Up @@ -219,7 +219,7 @@
$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/backfill/$pub_room_id/",
uri => "/v1/backfill/$pub_room_id/",

params => {
v => $priv_event_id,
Expand Down
153 changes: 134 additions & 19 deletions tests/50federation/35room-invite.pl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
);
};

test "Inbound federation can receive invites",
test "Inbound federation can receive invites via v1 API",
requires => [ local_user_fixture( with_events => 1 ), $main::INBOUND_SERVER,
federation_user_id_fixture() ],

Expand All @@ -65,13 +65,71 @@
creator => $creator_id,
);

invite_server( $room, $creator_id, $user, $inbound_server );
invite_server_v1( $room, $creator_id, $user, $inbound_server );
};


test "Inbound federation can receive invites via v2 API",
requires => [ local_user_fixture( with_events => 1 ), $main::INBOUND_SERVER,
federation_user_id_fixture() ],

do => sub {
my ( $user, $inbound_server, $creator_id ) = @_;

my $datastore = $inbound_server->datastore;

my $room = SyTest::Federation::Room->new(
datastore => $datastore,
);

$room->create_initial_events(
server => $inbound_server,
creator => $creator_id,
);

invite_server_v2( $room, $creator_id, $user, $inbound_server );
};


=head2 invite_server_v1
invite_server_v1( $room, $creator_id, $user, $inbound_server )
Invite a server using the V1 API. See invite_server
=cut

sub invite_server_v1
{
invite_server( @_, \&do_v1_invite_request )
}


=head2 invite_server_v2
invite_server_v1( $room, $creator_id, $user, $inbound_server )
Invite a server using the V2 API. See invite_server
=cut

sub invite_server_v2
{
invite_server( @_, \&do_v2_invite_request )
}

=head2 invite_server
invite_server( $room, $creator_id, $user, $inbound_server, $do_invite_request )
Invite a server into the room using the given `do_invite_request` parameter to
actually send the invite request
=cut

sub invite_server
{
my ( $room, $creator_id, $user, $inbound_server) = @_;
my ( $room, $creator_id, $user, $inbound_server, $do_invite_request ) = @_;

my $outbound_client = $inbound_server->client;
my $first_home_server = $user->http->server_name;
Expand Down Expand Up @@ -107,24 +165,11 @@ sub invite_server
Future->done(1);
}),

$outbound_client->do_request_json(
method => "PUT",
hostname => $first_home_server,
uri => "/invite/$room_id/$invitation->{event_id}",

content => $invitation,
$do_invite_request->(
$room, $user, $inbound_server, $invitation,
)->then( sub {
my ( $response ) = @_;

# $response seems to arrive with an extraneous layer of wrapping as
# the result of a synapse implementation bug (SYN-490).
if( ref $response eq "ARRAY" ) {
$response->[0] == 200 or
die "Expected first response element to be 200";

$response = $response->[1];
}

log_if_fail "send invite response", $response;

my $event = $response->{event};
Expand All @@ -142,6 +187,76 @@ sub invite_server
);
}

=head2 do_v1_invite_request
do_v1_invite_request( $room, $user, $inbound_server, $invitation )
Send an invite event via the V1 API
=cut

sub do_v1_invite_request
{
my ( $room, $user, $inbound_server, $invitation ) = @_;

my $outbound_client = $inbound_server->client;
my $first_home_server = $user->http->server_name;
my $room_id = $room->room_id;

$outbound_client->do_request_json(
method => "PUT",
hostname => $first_home_server,
uri => "/v1/invite/$room_id/$invitation->{event_id}",

content => $invitation,
)->then( sub {
my ( $response ) = @_;

# $response arrives with an extraneous layer of wrapping as the result of
# a synapse implementation bug (matrix-org/synapse#1383).
(ref $response eq "ARRAY") or die "V1 invite response must be an array";

$response->[0] == 200 or
die "Expected first response element to be 200";

$response = $response->[1];

Future->done( $response )
})
}

=head2 do_v2_invite_request
do_v2_invite_request( $room, $user, $inbound_server, $invitation )
Send an invite event via the V2 API
=cut

sub do_v2_invite_request
{
my ( $room, $user, $inbound_server, $invitation ) = @_;

my $outbound_client = $inbound_server->client;
my $first_home_server = $user->http->server_name;
my $room_id = $room->room_id;

my $create_event = $room->get_current_state_event( "m.room.create" );
my $room_version = $create_event->{content}{room_version} // "1";

$outbound_client->do_request_json(
method => "PUT",
hostname => $first_home_server,
uri => "/v2/invite/$room_id/$invitation->{event_id}",

content => {
event => $invitation,
room_version => $room_version,
invite_room_state => [],
},
)
}


foreach my $error_code ( 403, 500, -1 ) {
# a temporary federation server which is shut down at the end of the test.
Expand Down Expand Up @@ -180,7 +295,7 @@ sub invite_server

my $room_id = $room->room_id;

invite_server( $room, $creator_id, $user, $federation_server )
invite_server_v1( $room, $creator_id, $user, $federation_server )
->then( sub {
if( $error_code < 0 ) {
# now shut down the remote server, so that we get an 'unreachable'
Expand Down
Loading

0 comments on commit cd3e3c5

Please sign in to comment.