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

federated_rooms_fixture #701

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions tests/50federation/00prepare.pl
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,94 @@ sub federation_user_id_fixture
);
}
push @EXPORT, qw( federation_user_id_fixture );


=head2 federated_rooms_fixture

test "foo",
requires => [ federated_rooms_fixture( %options ) ],
do => sub {
my ( $creator_user, $joining_user_id, $room1, $room2, ... ) = @_;
};

Returns a new Fixture, which:

=over

=item * creates a user on the main test server

=item * uses that user to create one or more rooms

=item * uses a test user to join those rooms over federation

=back

The results of the Fixture are:

=over

=item * A User struct for the user on the server under test

=item * A string giving the user id of the sytest user which has joined the rooms

=item * A SyTest::Federation::Room object for each room

=back

The following options are supported:

=over

=item room_count => SCALAR

The number of rooms to be created. Defaults to 1.

=item room_opts => HASH

A set of options to be passed into C<matrix_create_room> for all of the rooms.

=back

=cut

sub federated_rooms_fixture {
my %options = @_;

my $room_count = $options{room_count} // 1;
my $room_opts = $options{room_opts} // {};

return fixture(
requires => [
local_user_fixture(),
$main::OUTBOUND_CLIENT,
federation_user_id_fixture(),
],

setup => sub {
my ( $synapse_user, $outbound_client, $sytest_user_id ) = @_;
my $synapse_server_name = $synapse_user->http->server_name;

my @rooms;

repeat( sub {
my ( $idx ) = @_;
matrix_create_room( $synapse_user, %$room_opts )->then( sub {
my ( $room_id ) = @_;
$outbound_client->join_room(
server_name => $synapse_server_name,
room_id => $room_id,
user_id => $sytest_user_id,
);
})->on_done( sub {
my ( $room ) = @_;
log_if_fail "Joined room $idx: " . $room->room_id;
push @rooms, $room;
});
}, foreach => [ 1 .. $room_count ]) -> then( sub {
Future->done( $synapse_user, $sytest_user_id, @rooms );
});
},
);
}

push @EXPORT, qw( federated_rooms_fixture );
60 changes: 22 additions & 38 deletions tests/50federation/32room-getevent.pl
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
test "Inbound federation can return events",
requires => [ $main::OUTBOUND_CLIENT,
local_user_and_room_fixtures(),
federation_user_id_fixture() ],
requires => [
$main::OUTBOUND_CLIENT,
federated_rooms_fixture(),
],

do => sub {
my ( $outbound_client, $creator, $room_id, $user_id ) = @_;
my ( $outbound_client, $creator, $user_id, $room ) = @_;
my $first_home_server = $creator->server_name;

my $local_server_name = $outbound_client->server_name;
my $member_event = $room->get_current_state_event( "m.room.member", $user_id );
log_if_fail "Member event", $member_event;

my ( $member_event, $room );
my $event_id = $room->id_for_event( $member_event );

$outbound_client->join_room(
server_name => $first_home_server,
room_id => $room_id,
user_id => $user_id,
$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/v1/event/$event_id",
)->then( sub {
( $room ) = @_;

$member_event = $room->get_current_state_event( "m.room.member", $user_id );
log_if_fail "Member event", $member_event;

my $event_id = $room->id_for_event( $member_event );

$outbound_client->do_request_json(
method => "GET",
hostname => $first_home_server,
uri => "/v1/event/$event_id",
);
})->then( sub {
my ( $body ) = @_;
log_if_fail "Body", $body;

Expand All @@ -53,27 +42,22 @@


test "Inbound federation redacts events from erased users",
requires => [ $main::OUTBOUND_CLIENT,
local_user_and_room_fixtures(),
federation_user_id_fixture() ],
requires => [
$main::OUTBOUND_CLIENT,
federated_rooms_fixture(),
],

do => sub {
my ( $outbound_client, $creator, $room_id, $user_id ) = @_;
my ( $outbound_client, $creator, $user_id, $room ) = @_;
my $first_home_server = $creator->server_name;
my $room_id = $room->room_id;

my $message_id;

$outbound_client->join_room(
server_name => $first_home_server,
room_id => $room_id,
user_id => $user_id,
)->then( sub {
my ( $room ) = @_;

# have the creator send a message into the room, which we will try to
# fetch.
matrix_send_room_text_message( $creator, $room_id, body => "body1" );
})->then( sub {
# have the creator send a message into the room, which we will try to
# fetch.
matrix_send_room_text_message( $creator, $room_id, body => "body1" )
->then( sub {
( $message_id ) = @_;

$outbound_client->do_request_json(
Expand Down
Loading