From 40b523c39e7b75214258bf7cc3279608629774b1 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 3 Feb 2020 10:09:59 +0000 Subject: [PATCH] Add back v1 endpoint code --- lib/SyTest/Federation/Client.pm | 5 ++++- lib/SyTest/Federation/Server.pm | 36 +++++++++++++++++++++++++++++++ tests/50federation/30room-join.pl | 29 +++++++------------------ 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/lib/SyTest/Federation/Client.pm b/lib/SyTest/Federation/Client.pm index a7c83b624..12be421ff 100644 --- a/lib/SyTest/Federation/Client.pm +++ b/lib/SyTest/Federation/Client.pm @@ -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, diff --git a/lib/SyTest/Federation/Server.pm b/lib/SyTest/Federation/Server.pm index c6405c926..b5817193d 100644 --- a/lib/SyTest/Federation/Server.pm +++ b/lib/SyTest/Federation/Server.pm @@ -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 standard +has the problem that C 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; diff --git a/tests/50federation/30room-join.pl b/tests/50federation/30room-join.pl index 16302106f..79e056b6c 100644 --- a/tests/50federation/30room-join.pl +++ b/tests/50federation/30room-join.pl @@ -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 ); @@ -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 @@ -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;