Skip to content

Commit

Permalink
Add back v1 endpoint code
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Feb 3, 2020
1 parent ff5c2e2 commit 40b523c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
5 changes: 4 additions & 1 deletion lib/SyTest/Federation/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,14 @@ sub join_room
$self->do_request_json(
method => "PUT",
hostname => $server_name,
uri => "/v2/send_join/$room_id/$event_id",
uri => "/v1/send_join/$room_id/$event_id",
content => $member_event,
)->then( sub {
my ( $join_body ) = @_;

# /v1/send_join has an extraneous [ 200, ... ] wrapper (see MSC1802)
$join_body = $join_body->[1];

my $room = SyTest::Federation::Room->new(
datastore => $store,
room_id => $room_id,
Expand Down
36 changes: 36 additions & 0 deletions lib/SyTest/Federation/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,40 @@ sub on_event
return 1;
}

=head2 await_request_v1_send_join_reject_v2
$fut = $server->await_request_v1_send_join_reject_v2( $room_id )
Awaits inbound request for /v1/send_join endpoint while rejecting inbound
requests to /v2/send_join. Using the C<await_request_v1_send_join> standard
has the problem that C<SyTest::Federation::Server> will handle /v2/send_join
appropriately unless overriden, and so remote servers that use v2 will never
call v1 endpoint in such a case.
=cut

sub await_request_v1_send_join_reject_v2 {
my $self = shift;
my ( $room_id ) = @_;

my $v2_fut = $self->await_request_v2_send_join( $room_id )
->then( sub {
my ( $req, $room_id, $event_id ) = @_;
$req->respond( HTTP::Response->new(
404, "Not found", [ Content_length => 0 ], "",
) );

Future->done
});

$self->await_request_v1_send_join( $room_id )
->then( sub {
my ( $req, $room_id, $event_id ) = @_;

$v2_fut->cancel();

Future->done( $req, $room_id, $event_id )
})
}

1;
29 changes: 8 additions & 21 deletions tests/50federation/30room-join.pl
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,11 @@ sub assert_is_valid_pdu {
my $await_request_send_join;

if( $versionprefix eq "v1" ) {
# If we only expect a response on the v1 endpoint, the homeserver will try to
# hit the v2 one, get a 404 from SyTest (because we didn't call
# await_request_v2_send_join), then fall back to the v1 endpoint. We rely on
# that 404 response from SyTest and that fallback mechanism to test that the
# homeserver can query the v1 endpoint, and correctly handles responses from
# it.
$await_request_send_join = Future->needs_all(
$inbound_server->await_request_v2_send_join( $room_id )
->then( sub {
my ( $req, $room_id, $event_id ) = @_;
$req->respond( HTTP::Response->new(
404, "Not found", [ Content_length => 0 ], "",
) );

Future->done
}),
$inbound_server->await_request_v1_send_join( $room_id )
);
# We need to use the `_reject_v2` form here as otherwise SyTest
# will respond to /v2/send_join and v1 endpoint will never get
# called.
$await_request_send_join =
$inbound_server->await_request_v1_send_join_reject_v2($room_id );
}
elsif( $versionprefix eq "v2" ) {
$await_request_send_join = $inbound_server->await_request_v2_send_join( $room_id );
Expand Down Expand Up @@ -844,7 +831,7 @@ sub assert_is_valid_pdu {
Future->done;
}),

$inbound_server->await_request_v2_send_join( $room_id )->then( sub {
$inbound_server->await_request_v1_send_join_reject_v2( $room_id )->then( sub {
my ( $req, $room_id, $event_id ) = @_;

$req->method eq "PUT" or
Expand All @@ -861,10 +848,10 @@ sub assert_is_valid_pdu {
@auth_chain = grep { $_->{type} ne 'm.room.create' } @auth_chain;

$req->respond_json(
my $response = {
my $response = [ 200, {
auth_chain => \@auth_chain,
state => [ $room->current_state_events ],
}
} ]
);

log_if_fail "send_join response", $response;
Expand Down

0 comments on commit 40b523c

Please sign in to comment.