Skip to content

Commit

Permalink
Add tests for a user with sufficient power level removing an alias. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep authored Mar 4, 2020
1 parent 7c8890f commit 9113b56
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions tests/30rooms/05aliases.pl
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@
do => sub {
my ( $creator, $other_user, $room_id, $alias ) = @_;

my $server_name = $other_user->http->server_name;

matrix_change_room_power_levels(
$creator, $room_id, sub {
$_[0]->{events}->{'m.room.aliases'} = 50;
Expand Down Expand Up @@ -169,8 +167,6 @@
sub _test_can_create_and_delete_alias {
my ( $room_id, $user, $alias ) = @_;

my $server_name = $user->http->server_name;

do_request_json_for( $user,
method => "PUT",
uri => "/r0/directory/room/$alias",
Expand Down Expand Up @@ -209,7 +205,6 @@ sub _test_can_create_and_delete_alias {

do => sub {
my ( $user, $room_id, $other_user, $room_alias ) = @_;
my $server_name = $user->http->server_name;

do_request_json_for( $user,
method => "PUT",
Expand All @@ -226,6 +221,50 @@ sub _test_can_create_and_delete_alias {
})
};

test "Users with sufficient power-level can delete other's aliases",
requires => [ $creator_fixture, local_user_fixture(), room_alias_fixture(),
qw( can_create_room_alias )],

do => sub {
my ( $user, $other_user, $room_alias ) = @_;
my $room_id;

matrix_create_and_join_room(
[ $user, $other_user ],
)->then( sub {
( $room_id ) = @_;

matrix_change_room_power_levels(
$user, $room_id, sub {
$_[0]->{users}->{$other_user->user_id} = 100;
},
)
})->then( sub {
do_request_json_for( $user,
method => "PUT",
uri => "/r0/directory/room/$room_alias",

content => { room_id => $room_id },
)
})->then( sub {
do_request_json_for( $other_user,
method => "DELETE",
uri => "/r0/directory/room/$room_alias",

content => {},
)
})->then( sub {
my ( $res ) = @_;
log_if_fail "Unable to delete alias", $res;

do_request_json_for(
$user,
method => "GET",
uri => "/r0/directory/room/$room_alias",
);
})->main::expect_http_404;
};

test "Can delete canonical alias",
requires => [ local_user_fixture( with_events => 0 ), room_alias_fixture(),
qw( can_create_room_alias )],
Expand Down Expand Up @@ -275,7 +314,6 @@ sub _test_can_create_and_delete_alias {

do => sub {
my ( $creator, $other_user, $room_alias ) = @_;
my $server_name = $creator->http->server_name;
my $room_id;

matrix_create_and_join_room( [ $creator, $other_user ] )
Expand Down Expand Up @@ -305,7 +343,6 @@ sub _test_can_create_and_delete_alias {

do => sub {
my ( $creator, $other_user, $room_alias ) = @_;
my $server_name = $creator->http->server_name;
my $room_id;

matrix_create_and_join_room( [ $creator, $other_user ] )
Expand Down

0 comments on commit 9113b56

Please sign in to comment.