Skip to content

Commit f85243d

Browse files
committed
Add back v2 endpoint
1 parent ff5c2e2 commit f85243d

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

lib/SyTest/Federation/Client.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,14 @@ sub join_room
248248
$self->do_request_json(
249249
method => "PUT",
250250
hostname => $server_name,
251-
uri => "/v2/send_join/$room_id/$event_id",
251+
uri => "/v1/send_join/$room_id/$event_id",
252252
content => $member_event,
253253
)->then( sub {
254254
my ( $join_body ) = @_;
255255

256+
# /v1/send_join has an extraneous [ 200, ... ] wrapper (see MSC1802)
257+
$join_body = $join_body->[1];
258+
256259
my $room = SyTest::Federation::Room->new(
257260
datastore => $store,
258261
room_id => $room_id,

lib/SyTest/Federation/Server.pm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,4 +557,40 @@ sub on_event
557557
return 1;
558558
}
559559

560+
=head2 await_request_v1_send_join_reject_v2
561+
562+
$fut = $server->await_request_v1_send_join_reject_v2( $room_id )
563+
564+
Awaits inbound request for /v1/send_join endpoint while rejecting inbound
565+
requests to /v2/send_join. Using the C<await_request_v1_send_join> standard
566+
has the problem that C<SyTest::Federation::Server> will handle /v2/send_join
567+
appropriately unless overriden, and so remote servers that use v2 will never
568+
call v1 endpoint in such a case.
569+
570+
=cut
571+
572+
sub await_request_v1_send_join_reject_v2 {
573+
my $self = shift;
574+
my ( $room_id ) = @_;
575+
576+
my $v2_fut = $self->await_request_v2_send_join( $room_id )
577+
->then( sub {
578+
my ( $req, $room_id, $event_id ) = @_;
579+
$req->respond( HTTP::Response->new(
580+
404, "Not found", [ Content_length => 0 ], "",
581+
) );
582+
583+
Future->done
584+
});
585+
586+
$self->await_request_v1_send_join( $room_id )
587+
->then( sub {
588+
my ( $req, $room_id, $event_id ) = @_;
589+
590+
$v2_fut->cancel();
591+
592+
Future->done( $req, $room_id, $event_id )
593+
})
594+
}
595+
560596
1;

tests/50federation/30room-join.pl

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,11 @@ sub assert_is_valid_pdu {
7474
my $await_request_send_join;
7575

7676
if( $versionprefix eq "v1" ) {
77-
# If we only expect a response on the v1 endpoint, the homeserver will try to
78-
# hit the v2 one, get a 404 from SyTest (because we didn't call
79-
# await_request_v2_send_join), then fall back to the v1 endpoint. We rely on
80-
# that 404 response from SyTest and that fallback mechanism to test that the
81-
# homeserver can query the v1 endpoint, and correctly handles responses from
82-
# it.
83-
$await_request_send_join = Future->needs_all(
84-
$inbound_server->await_request_v2_send_join( $room_id )
85-
->then( sub {
86-
my ( $req, $room_id, $event_id ) = @_;
87-
$req->respond( HTTP::Response->new(
88-
404, "Not found", [ Content_length => 0 ], "",
89-
) );
90-
91-
Future->done
92-
}),
93-
$inbound_server->await_request_v1_send_join( $room_id )
94-
);
77+
# We need to use the `_reject_v2` form here as otherwise SyTest
78+
# will respond to /v2/send_join and v1 endpoint will never get
79+
# called.
80+
$await_request_send_join =
81+
$inbound_server->await_request_v1_send_join_reject_v2($room_id );
9582
}
9683
elsif( $versionprefix eq "v2" ) {
9784
$await_request_send_join = $inbound_server->await_request_v2_send_join( $room_id );
@@ -844,7 +831,7 @@ sub assert_is_valid_pdu {
844831
Future->done;
845832
}),
846833

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

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

863850
$req->respond_json(
864-
my $response = {
851+
my $response = [ 200, {
865852
auth_chain => \@auth_chain,
866853
state => [ $room->current_state_events ],
867-
}
854+
} ]
868855
);
869856

870857
log_if_fail "send_join response", $response;

0 commit comments

Comments
 (0)