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

Add test for updating room aliases on upgraded room join #844

Merged
merged 3 commits into from
Mar 30, 2020
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
31 changes: 28 additions & 3 deletions tests/10apidoc/30room-create.pl
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ sub matrix_create_room
});
}

push @EXPORT, qw( room_alias_name_fixture room_alias_fixture matrix_create_room_synced );
push @EXPORT, qw( room_alias_name_fixture room_alias_fixture remote_room_alias_fixture matrix_create_room_synced );

my $next_alias_name = 0;

Expand Down Expand Up @@ -356,7 +356,7 @@ sub room_alias_name_fixture

=head2 room_alias_fixture

$fixture = room_alias_fixture( prefix => $prefix )
$fixture = room_alias_fixture( prefix => $prefix, remote => 0 )

Returns a new Fixture, which when provisioned will allocate a name for a new
room alias on the first homeserver, and return it as a string. Note that this
Expand All @@ -366,6 +366,9 @@ =head2 room_alias_fixture
An optional prefix string can be provided, which will be prepended onto the
alias name.

An optional remote boolean can be supplied, which will generate an alias for
the second homeserver instead.

=cut

sub room_alias_fixture
Expand All @@ -374,7 +377,8 @@ sub room_alias_fixture

return fixture(
requires => [
room_alias_name_fixture( prefix => $args{prefix} ), $main::HOMESERVER_INFO[0],
room_alias_name_fixture( prefix => $args{prefix} ),
$args{remote} ? $main::HOMESERVER_INFO[1] : $main::HOMESERVER_INFO[0],
],

setup => sub {
Expand All @@ -385,6 +389,27 @@ sub room_alias_fixture
);
}

=head2 remote_room_alias_fixture

$fixture = remote_room_alias_fixture( prefix => $prefix )

Returns a new Fixture, which when provisioned will allocate a name for a new
room alias on the second homeserver, and return it as a string. Note that this
does not actually create the alias on the server itself, it simply suggests a
new unique name for one.

An optional prefix string can be provided, which will be prepended onto the
alias name.

=cut

sub remote_room_alias_fixture
{
my %args = @_;

return room_alias_fixture( prefix => $args{prefix}, remote => 1 );
}


=head2 matrix_create_room_synced

Expand Down
2 changes: 1 addition & 1 deletion tests/10apidoc/33room-members.pl
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ =head2 local_user_and_room_fixtures

=item room_opts => HASH

Options to use when creating the room. Thes are passed into into
Options to use when creating the room. These are passed into
C<matrix_create_room>, whence they are passed on to the server.

=back
Expand Down
65 changes: 62 additions & 3 deletions tests/30rooms/60version_upgrade.pl
Original file line number Diff line number Diff line change
Expand Up @@ -649,17 +649,15 @@ sub upgrade_room_synced {

test "/upgrade moves aliases to the new room",
requires => [
$main::HOMESERVER_INFO[0],
local_user_and_room_fixtures(),
room_alias_fixture(),
room_alias_fixture(),
qw( can_upgrade_room_version ),
],

do => sub {
my ( $info, $creator, $room_id, $room_alias_1, $room_alias_2 ) = @_;
my ( $creator, $room_id, $room_alias_1, $room_alias_2 ) = @_;

my $server_name = $info->server_name;
my $new_room_id;

do_request_json_for(
Expand Down Expand Up @@ -739,6 +737,67 @@ sub upgrade_room_synced {
});
};

test "/upgrade moves remote aliases to the new room",
requires => [
local_user_and_room_fixtures(),
remote_user_fixture(),
remote_room_alias_fixture(),
qw( can_upgrade_room_version ),
],

do => sub {
my ( $creator, $room_id, $remote_user, $remote_room_alias ) = @_;

my $new_room_id;

log_if_fail $room_id;

# Invite the remote user to our room
matrix_invite_user_to_room(
$creator, $remote_user, $room_id
)->then( sub {
# Have the remote user join the room
matrix_join_room( $remote_user, $room_id );
})->then( sub {
# Have the remote user add an alias
do_request_json_for(
$remote_user,
method => "PUT",
uri => "/r0/directory/room/$remote_room_alias",
content => { room_id => $room_id },
);
})->then( sub {
# Upgrade the room
upgrade_room_synced(
$creator, $room_id,
new_version => $TEST_NEW_VERSION,
);
})->then( sub {
( $new_room_id ) = @_;

# Invite the remote user to the new room
matrix_invite_user_to_room(
$creator, $remote_user, $new_room_id
);
})->then( sub {
# Have the remote user join the upgraded room
matrix_join_room( $remote_user, $new_room_id );
})->then( sub {
# Check that the remote alias points to the new room id
do_request_json_for(
$remote_user,
method => "GET",
uri => "/r0/directory/room/$remote_room_alias",
);
})->then( sub {
my ( $body ) = @_;

assert_eq( $body->{room_id}, $new_room_id, "room_id for remote alias" );

Future->done(1);
});
};

test "/upgrade preserves direct room state",
requires => [
local_user_and_room_fixtures(),
Expand Down