-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for not kicking users who aren't in a room (#602)
Synapse PR: matrix-org/synapse#4999
- Loading branch information
1 parent
8fdb332
commit 84a9856
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
my $creator_fixture = local_user_fixture(); | ||
|
||
test "Users cannot kick users from a room they are not in", | ||
requires => [ $creator_fixture, | ||
magic_room_fixture( requires_users => [ $creator_fixture ] ) | ||
], | ||
|
||
do => sub { | ||
my ( $creator, $room_id ) = @_; | ||
my $fake_user_id = '@bob:example.com'; | ||
|
||
do_request_json_for( $creator, | ||
method => "POST", | ||
uri => "/r0/rooms/$room_id/kick", | ||
|
||
content => { user_id => $fake_user_id, reason => "testing" }, | ||
)->main::expect_http_403; # 403 for kicking a user who isn't in the room | ||
}; | ||
|
||
my $kicked_user_fixture = local_user_fixture(); | ||
|
||
test "Users cannot kick users who have already left a room", | ||
requires => [ $creator_fixture, $kicked_user_fixture, | ||
magic_room_fixture( requires_users => [ $creator_fixture, $kicked_user_fixture ] ) | ||
], | ||
|
||
do => sub { | ||
my ( $creator, $kicked_user, $room_id ) = @_; | ||
|
||
do_request_json_for( $creator, | ||
method => "POST", | ||
uri => "/r0/rooms/$room_id/kick", | ||
|
||
content => { user_id => $kicked_user->user_id, reason => "testing" }, | ||
)->then( sub { | ||
retry_until_success { | ||
matrix_get_room_state( $creator, $room_id, | ||
type => "m.room.member", | ||
state_key => $kicked_user->user_id, | ||
)->then( sub { | ||
my ( $body ) = @_; | ||
$body->{membership} eq "leave" or | ||
die "Expected kicked user membership to be 'leave'"; | ||
|
||
Future->done ( 1 ); | ||
}) | ||
} | ||
})->then( sub { | ||
do_request_json_for( $creator, | ||
method => "POST", | ||
uri => "/r0/rooms/$room_id/kick", | ||
|
||
content => { user_id => $kicked_user->user_id, reason => "testing" }, | ||
)->main::expect_http_403; # 403 for kicking a user who isn't in the room anymore | ||
}) | ||
}; |