Skip to content

Commit

Permalink
Add tests for validating alt_aliases of a canonical alias event. (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep authored Mar 16, 2020
1 parent 955648a commit 7beff40
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions tests/30rooms/05aliases.pl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
}
)->SyTest::pass_on_done( "m.room.canonical_alias accepts present aliases" );
})->then( sub {
# Create an unknown, but valid alias name.
my $bad_alias = $room_alias =~ s/^#/#NOT-/r;

matrix_put_room_state( $user, $room_id,
Expand All @@ -99,6 +100,84 @@
}
)->main::expect_http_4xx
->SyTest::pass_on_done( "m.room.canonical_alias rejects missing aliases" );
})->then( sub {
# Create an invalid alias name (starts with % instead of #).
my $bad_alias = $room_alias =~ s/^#/%/r;

matrix_put_room_state( $user, $room_id,
type => "m.room.canonical_alias",
content => {
alias => $bad_alias,
}
)->main::expect_http_4xx
->SyTest::pass_on_done( "m.room.canonical_alias rejects invalid aliases" );
});
};

multi_test "Canonical alias can include alt_aliases",
requires => [ local_user_fixture(), room_alias_name_fixture() ],

do => sub {
my ( $user, $room_alias_name ) = @_;

my ( $room_id, $room_alias );

matrix_create_room( $user,
room_alias_name => $room_alias_name,
)->then( sub {
( $room_id, $room_alias ) = @_;

matrix_put_room_state( $user, $room_id,
type => "m.room.canonical_alias",
content => {
alias => $room_alias,
alt_aliases => [ $room_alias ],
}
)->SyTest::pass_on_done( "m.room.canonical_alias accepts present aliases" );
})->then( sub {
# Create an unknown, but valid alias name.
my $bad_alias = $room_alias =~ s/^#/#NOT-/r;

matrix_put_room_state( $user, $room_id,
type => "m.room.canonical_alias",
content => {
alias => $room_alias,
alt_aliases => [ $bad_alias ],
}
)->main::expect_matrix_error( 404, "M_NOT_FOUND" )
->SyTest::pass_on_done( "m.room.canonical_alias rejects missing aliases" );
})->then( sub {
# Create an invalid alias name (starts with % instead of #).
my $bad_alias = $room_alias =~ s/^#/%/r;

matrix_put_room_state( $user, $room_id,
type => "m.room.canonical_alias",
content => {
alias => $room_alias,
alt_aliases => [ $bad_alias ],
}
)->main::expect_matrix_error( 400, "M_INVALID_PARAM" )
->SyTest::pass_on_done( "m.room.canonical_alias rejects invalid aliases" );
})->then( sub {
# Create a second room with an alias on it.
my $other_alias_name = $room_alias_name . "2";

matrix_create_room( $user,
room_alias_name => $other_alias_name,
)->then( sub {
my ( $other_room_id, $other_room_alias ) = @_;

# Attempt to set a canonical alias for the original room using an
# alias from the second room.
matrix_put_room_state( $user, $room_id,
type => "m.room.canonical_alias",
content => {
alias => $room_alias,
alt_aliases => [ $other_room_alias ],
}
)->main::expect_matrix_error( 400, "M_BAD_ALIAS" )
->SyTest::pass_on_done( "m.room.canonical_alias rejects alias pointing to different room" );
})
});
};

Expand Down

0 comments on commit 7beff40

Please sign in to comment.