Skip to content

Commit

Permalink
Test moving aliases on room upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Oct 31, 2018
1 parent d8792a8 commit 159802c
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 2 deletions.
43 changes: 43 additions & 0 deletions tests/10apidoc/33room-members.pl
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,23 @@ sub matrix_create_and_join_room
});
}

=head2 room_fixture
$fixture = room_fixture( $user_fixture, %opts );
Returns a Fixture, which when provisioned will create a new room on the user's
server and return the room id.
C<$user_fixture> should be a Fixture which will provide a User when
provisioned.
Any other options are passed into C<matrix_create_room>, whence they are passed
on to the server.
It is generally easier to use C<local_user_and_name_fixtures>.
=cut

push @EXPORT, qw( room_fixture );

sub room_fixture
Expand Down Expand Up @@ -533,6 +550,32 @@ sub magic_room_fixture
);
}

=head2 local_user_and_room_fixtures
( $user_fixture, $room_fixture ) = local_user_and_room_fixtures( %opts );
Returns a pair of Fixtures, which when provisioned will respectively create a
new user on the main test server (returning the User object), and use that
user to create a new room (returning the room id).
The following can be passed as optional parameters:
=over
=item user_opts => HASH
Options to use when creating the user, such as C<displayname>. These are passed
through to C<setup_user>.
=item room_opts => HASH
Options to use when creating the room. Thes are passed into into
C<matrix_create_room>, whence they are passed on to the server.
=back
=cut

push @EXPORT, qw( local_user_and_room_fixtures );

sub local_user_and_room_fixtures
Expand Down
123 changes: 121 additions & 2 deletions tests/30rooms/60version_upgrade.pl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

use Future::Utils qw( repeat );
use List::Util qw( first );
use List::Util qw( all first );

# TODO: switch this to '2' once that is released
my $TEST_NEW_VERSION = 'vdh-test-version';
Expand All @@ -38,6 +38,7 @@ =head2 upgrade_room
=cut


sub upgrade_room {
my ( $user, $room_id, %opts ) = @_;

Expand All @@ -51,6 +52,7 @@ sub upgrade_room {
new_version => $new_version,
},
)->then( sub {

my ( $body ) = @_;
log_if_fail "upgrade response", $body;

Expand Down Expand Up @@ -359,6 +361,124 @@ 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 $server_name = $info->server_name;

# $received_events{room_id}->{type}->{state_key}->event
my %received_events;

do_request_json_for(
$creator,
method => "PUT",
uri => "/r0/directory/room/$room_alias_1",
content => { room_id => $room_id },
)->then( sub {
do_request_json_for(
$creator,
method => "PUT",
uri => "/r0/directory/room/$room_alias_2",
content => { room_id => $room_id },
);
})->then( sub {
# alias 1 is the canonical alias.
matrix_put_room_state( $creator, $room_id,
type => "m.room.canonical_alias",
content => {
alias => $room_alias_1,
},
);
})->then( sub {
matrix_do_and_wait_for_sync(
$creator,
do => sub {
upgrade_room(
$creator, $room_id, new_version => $TEST_NEW_VERSION,
);
},
check => sub {
my ( $sync_body, $new_room_id ) = @_;

log_if_fail "sync body", $sync_body;

my $joined = $sync_body->{rooms}{join} // {};
foreach my $room_id ( keys %{ $joined } ) {
foreach my $ev ( @{ $joined->{$room_id}{timeline}{events} } ) {
$received_events{$room_id}->{$ev->{type}}->{$ev->{state_key} // ''} = $ev;
}
}

# wait until we've received both alias events in both rooms.
foreach my $room_id ( $room_id, $new_room_id ) {
my $rs = $received_events{$room_id} // {};
foreach ( qw( m.room.aliases m.room.canonical_alias ) ) {
log_if_fail "$_ in $room_id", $rs->{$_};
return 0 unless $rs->{$_};
}
}
return 1;
},
);
})->then( sub {
my ( $new_room_id, $sync_body ) = @_;

my $old_aliases = $received_events{$room_id}->{'m.room.aliases'}->{$server_name};
assert_deeply_eq( $old_aliases->{content}, {aliases => []}, "aliases on old room" );

my $old_canonical_alias = $received_events{$room_id}->{'m.room.canonical_alias'}->{''};
assert_deeply_eq( $old_canonical_alias->{content}, {}, "canonical_alias on old room" );

my $new_aliases = $received_events{$new_room_id}->{'m.room.aliases'}->{$server_name};
assert_deeply_eq(
$new_aliases->{content}{aliases},
[ $room_alias_1, $room_alias_2 ],
"aliases on new room",
);

my $new_canonical_alias = $received_events{$new_room_id}->{'m.room.canonical_alias'}->{''};
assert_deeply_eq(
$new_canonical_alias->{content},
{ alias => $room_alias_1 },
"canonical_alias on new room",
);

# check that the directory now maps the aliases to the new room
do_request_json_for(
$creator,
method => "GET",
uri => "/r0/directory/room/$room_alias_1",
)->then( sub {
my ( $body ) = @_;

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

do_request_json_for(
$creator,
method => "GET",
uri => "/r0/directory/room/$room_alias_2",
);
})->then( sub {
my ( $body ) = @_;

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

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


test "/upgrade restricts power levels in the old room",
requires => [
local_user_and_room_fixtures(),
Expand Down Expand Up @@ -475,6 +595,5 @@ sub upgrade_room_synced {

# upgrade with other local users
# upgrade with remote users
# check names and aliases are copied


0 comments on commit 159802c

Please sign in to comment.