Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test v2 endpoint for /send_join #760

Merged
merged 10 commits into from
Dec 11, 2019
63 changes: 41 additions & 22 deletions lib/SyTest/Federation/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ sub on_request_federation_v1_make_join
}

sub on_request_federation_v1_send_join
{
my $self = shift;

$self->on_request_federation_v2_send_join( @_ )->then( sub {
my $res = @_;

# /v1/send_join has an extraneous [ 200, ... ] wrapper (see MSC1802)
Future->done( json => [ 200, $res ] );
})
}

sub on_request_federation_v2_send_join
{
my $self = shift;
my ( $req, $room_id ) = @_;
Expand All @@ -305,20 +317,19 @@ sub on_request_federation_v1_send_join

$room->insert_event( $event );

# /v1/send_join has an extraneous [ 200, ... ] wrapper (see MSC1802)
Future->done( json => [ 200, {
Future->done( json => {
auth_chain => \@auth_chain,
state => \@state_events,
} ] );
} );
babolivier marked this conversation as resolved.
Show resolved Hide resolved
}

sub mk_await_request_pair
{
my $class = shift;
my ( $shortname, $paramnames ) = @_;
my ( $versionprefix, $shortname, $paramnames ) = @_;
my @paramnames = @$paramnames;

my $okey = "awaiting_$shortname";
my $okey = "awaiting_${versionprefix}_${shortname}";

my $awaitfunc = sub {
my $self = shift;
Expand All @@ -336,7 +347,9 @@ sub mk_await_request_pair
});
};

my $was_on_requestfunc = $class->can( "on_request_federation_v1_$shortname" );
my $was_on_requestfunc = $class->can(
"on_request_federation_${versionprefix}_${shortname}"
);
my $on_requestfunc = sub {
my $self = shift;
my ( $req, @pathvalues ) = @_;
Expand Down Expand Up @@ -375,64 +388,70 @@ sub mk_await_request_pair

no strict 'refs';
no warnings 'redefine';
*{"${class}::await_request_$shortname"} = $awaitfunc;
*{"${class}::on_request_federation_v1_$shortname"} = $on_requestfunc;
*{"${class}::await_request_${versionprefix}_${shortname}"} = $awaitfunc;
# Deprecated alternative name for v1 endpoints.
*{"${class}::await_request_${shortname}"} = $awaitfunc if ${versionprefix} eq "v1";
*{"${class}::on_request_federation_${versionprefix}_${shortname}"} = $on_requestfunc;
}

__PACKAGE__->mk_await_request_pair(
query_directory => [qw( ?room_alias )],
"v1", "query_directory", [qw( ?room_alias )],
);

__PACKAGE__->mk_await_request_pair(
"v1", "query_profile", [qw( ?user_id )],
);

__PACKAGE__->mk_await_request_pair(
query_profile => [qw( ?user_id )],
"v1", "make_join", [qw( :room_id :user_id )],
);

__PACKAGE__->mk_await_request_pair(
make_join => [qw( :room_id :user_id )],
"v1", "make_leave", [qw( :room_id :user_id )],
);

__PACKAGE__->mk_await_request_pair(
make_leave => [qw( :room_id :user_id )],
"v1", "send_join", [qw( :room_id )],
);

__PACKAGE__->mk_await_request_pair(
send_join => [qw( :room_id )],
"v2", "send_join", [qw( :room_id )],
);

__PACKAGE__->mk_await_request_pair(
state_ids => [qw( :room_id ?event_id )],
"v1", "state_ids", [qw( :room_id ?event_id )],
);

__PACKAGE__->mk_await_request_pair(
state => [qw( :room_id )],
"v1", "state", [qw( :room_id )],
);

__PACKAGE__->mk_await_request_pair(
get_missing_events => [qw( :room_id )],
"v1", "get_missing_events", [qw( :room_id )],
);

__PACKAGE__->mk_await_request_pair(
event_auth => [qw( :room_id :event_id )],
"v1", "event_auth", [qw( :room_id :event_id )],
);

__PACKAGE__->mk_await_request_pair(
backfill => [qw( :room_id )],
"v1", "backfill", [qw( :room_id )],
);

__PACKAGE__->mk_await_request_pair(
invite => [qw( :room_id )],
"v1", "invite", [qw( :room_id )],
);

__PACKAGE__->mk_await_request_pair(
event => [qw( :event_id )],
"v1", "event", [qw( :event_id )],
);

__PACKAGE__->mk_await_request_pair(
user_devices => [qw( :user_id )],
"v1", "user_devices", [qw( :user_id )],
);

__PACKAGE__->mk_await_request_pair(
user_keys_query => [qw( )],
"v1", "user_keys_query", [qw( )],
);

sub on_request_federation_v1_send
Expand Down
Loading