Skip to content

Commit

Permalink
Merge pull request #802 from matrix-org/clokep/stop-sending-aliases
Browse files Browse the repository at this point in the history
Update tests to match removal alias event sending.
  • Loading branch information
clokep authored Feb 18, 2020
2 parents ac23101 + ddc482e commit 86ceaf9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 187 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
/var
\#*
.vscode
.coverage*
.coverage*
.idea
99 changes: 0 additions & 99 deletions tests/30rooms/05aliases.pl
Original file line number Diff line number Diff line change
Expand Up @@ -177,40 +177,13 @@ sub _test_can_create_and_delete_alias {

content => { room_id => $room_id },
)->then( sub {
matrix_get_room_state( $user, $room_id,
type => "m.room.aliases",
state_key => $server_name,
)
})->then( sub {
my ( $body ) = @_;

log_if_fail "Aliases after adding alias", $body;

assert_json_keys( $body, qw( aliases ) );
assert_json_list( my $aliases = $body->{aliases} );

any { $_ eq $alias } @$aliases or die "Expected alias to be in list";

do_request_json_for( $user,
method => "DELETE",
uri => "/r0/directory/room/$alias",

content => {},
)
})->then( sub {
matrix_get_room_state( $user, $room_id,
type => "m.room.aliases",
state_key => $server_name,
)
})->then( sub {
my ( $body ) = @_;

log_if_fail "Aliases after deleting alias", $body;
assert_json_keys( $body, qw( aliases ) );
assert_json_list( my $aliases = $body->{aliases} );

none { $_ eq $alias } @$aliases or die "Expected alias to not be in list";

Future->done;
});
}
Expand Down Expand Up @@ -278,37 +251,13 @@ sub _test_can_create_and_delete_alias {
content => { alias => $room_alias }
)
})->then( sub {
matrix_get_room_state( $creator, $room_id,
type => "m.room.aliases",
state_key => $server_name,
)
})->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, qw( aliases ) );
assert_json_list( my $aliases = $body->{aliases} );

any { $_ eq $room_alias } @$aliases or die "Expected alias to be in list";

do_request_json_for( $creator,
method => "DELETE",
uri => "/r0/directory/room/$room_alias",

content => {},
)
})->then( sub {
matrix_get_room_state( $creator, $room_id,
type => "m.room.aliases",
state_key => $server_name,
)
})->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, qw( aliases ) );
assert_json_list( my $aliases = $body->{aliases} );

none { $_ eq $room_alias } @$aliases or die "Expected alias to not be in list";

matrix_get_room_state( $creator, $room_id,
type => "m.room.canonical_alias",
)
Expand Down Expand Up @@ -340,37 +289,13 @@ sub _test_can_create_and_delete_alias {
content => { room_id => $room_id },
)
})->then( sub {
matrix_get_room_state( $creator, $room_id,
type => "m.room.aliases",
state_key => $server_name,
)
})->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, qw( aliases ) );
assert_json_list( my $aliases = $body->{aliases} );

any { $_ eq $room_alias } @$aliases or die "Expected alias to be in list";

do_request_json_for( $other_user,
method => "DELETE",
uri => "/r0/directory/room/$room_alias",

content => {},
)
})->then( sub {
matrix_get_room_state( $creator, $room_id,
type => "m.room.aliases",
state_key => $server_name,
)
})->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, qw( aliases ) );
assert_json_list( my $aliases = $body->{aliases} );

none { $_ eq $room_alias } @$aliases or die "Expected alias to not be in list";

Future->done(1);
})
};
Expand Down Expand Up @@ -399,37 +324,13 @@ sub _test_can_create_and_delete_alias {
content => { alias => $room_alias }
)
})->then( sub {
matrix_get_room_state( $creator, $room_id,
type => "m.room.aliases",
state_key => $server_name,
)
})->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, qw( aliases ) );
assert_json_list( my $aliases = $body->{aliases} );

any { $_ eq $room_alias } @$aliases or die "Expected alias to be in list";

do_request_json_for( $other_user,
method => "DELETE",
uri => "/r0/directory/room/$room_alias",

content => {},
)
})->then( sub {
matrix_get_room_state( $creator, $room_id,
type => "m.room.aliases",
state_key => $server_name,
)
})->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, qw( aliases ) );
assert_json_list( my $aliases = $body->{aliases} );

none { $_ eq $room_alias } @$aliases or die "Expected alias to not be in list";

Future->done(1);
})
};
45 changes: 6 additions & 39 deletions tests/60app-services/01as-create.pl
Original file line number Diff line number Diff line change
Expand Up @@ -115,46 +115,13 @@
do => sub {
my ( $as_user, $appserv, $room_id, $room_alias ) = @_;

Future->needs_all(
$appserv->await_event( "m.room.aliases" )->then( sub {
my ( $event, $request ) = @_;

# As this is the first AS event we've received, lets check that the
# token matches, to give that coverage.

my $access_token = $request->query_param( "access_token" );

assert_ok( defined $access_token,
"HS provides an access_token" );
assert_eq( $access_token, $appserv->info->hs2as_token,
"HS provides the correct token" );

log_if_fail "Event", $event;

assert_json_keys( $event, qw( content room_id user_id ));

$event->{room_id} eq $room_id or
die "Expected room_id to be $room_id";
$event->{user_id} eq $as_user->user_id or
die "Expected user_id to be ${\$as_user->user_id}";

assert_json_keys( my $content = $event->{content}, qw( aliases ));
assert_json_list( my $aliases = $content->{aliases} );

grep { $_ eq $room_alias } @$aliases or
die "Expected to find our alias in the aliases list";

Future->done;
}),

do_request_json_for( $as_user,
method => "PUT",
uri => "/r0/directory/room/$room_alias",
do_request_json_for( $as_user,
method => "PUT",
uri => "/r0/directory/room/$room_alias",

content => {
room_id => $room_id,
},
)
content => {
room_id => $room_id,
},
)->then( sub {
# Nothing interesting in the body

Expand Down
21 changes: 0 additions & 21 deletions tests/60app-services/03passive.pl
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,6 @@
Future->done;
}),

$appserv->await_event( "m.room.aliases" )->then( sub {
my ( $event ) = @_;

log_if_fail "Event", $event;

assert_json_keys( $event, qw( content room_id user_id ));

$event->{room_id} eq $room_id or
die "Expected room_id to be $room_id";
$event->{user_id} eq $as_user->user_id or
die "Expected user_id to be ${\$as_user->user_id}";

assert_json_keys( my $content = $event->{content}, qw( aliases ));
assert_json_list( my $aliases = $content->{aliases} );

grep { $_ eq $room_alias } @$aliases or
die "Expected to find our alias in the aliases list";

Future->done;
}),

do_request_json_for( $local_user,
method => "POST",
uri => "/r0/join/$room_alias",
Expand Down
36 changes: 9 additions & 27 deletions tests/61push/01message-pushed.pl
Original file line number Diff line number Diff line change
Expand Up @@ -280,31 +280,6 @@ sub check_received_push_with_name
});
}

test "Rooms with aliases are correctly named in pushed",
requires => [
local_user_fixtures( 2, with_events => 0 ), room_alias_fixture(),
$main::TEST_SERVER_INFO
],

check => sub {
my ( $alice, $bob, $room_alias, $test_server_info ) = @_;
my $room_id;

setup_push( $alice, $bob, $test_server_info, "/alice_push" )
->then( sub {
( $room_id ) = @_;

do_request_json_for( $bob,
method => "PUT",
uri => "/r0/directory/room/$room_alias",

content => { room_id => $room_id },
)
})->then( sub {
check_received_push_with_name( $bob, $room_id, "/alice_push", $room_alias )
});
};

test "Rooms with names are correctly named in pushed",
requires => [
local_user_fixtures( 2, with_events => 0 ),
Expand Down Expand Up @@ -370,10 +345,17 @@ sub check_received_push_with_name
my ( $alice, $bob, $charlie, $room_alias, $test_server_info ) = @_;
my $room_id;

my $name = "Test Name";

setup_push( $alice, $bob, $test_server_info, "/alice_push" )
->then( sub {
( $room_id ) = @_;
($room_id) = @_;

matrix_put_room_state($bob, $room_id,
type => "m.room.name",
content => { name => $name },
);
})->then( sub {
matrix_join_room( $charlie, $room_id)
})->then( sub {
do_request_json_for( $bob,
Expand All @@ -383,7 +365,7 @@ sub check_received_push_with_name
content => { room_id => $room_id },
)
})->then( sub {
check_received_push_with_name( $bob, $room_id, "/alice_push", $room_alias )
check_received_push_with_name( $bob, $room_id, "/alice_push", $name )
});
};

Expand Down

0 comments on commit 86ceaf9

Please sign in to comment.