Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Testing peeking over federation via MSC2444 #953

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion lib/SyTest/Homeserver/Dendrite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ sub _get_config
'postgresql://%s:%s@%s/%s?sslmode=%s',
$db_config{args}->{user},
$db_config{args}->{password},
"", # $db_config{args}->{host},
$db_config{args}->{host},
$db_config{args}->{database},
$db_config{args}->{sslmode},
);
Expand Down
12 changes: 8 additions & 4 deletions tests/31sync/17peeking.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
check => sub {
my ( $user, $room_id, $peeking_user ) = @_;

matrix_set_room_history_visibility( $user, $room_id, "world_readable" )->then(sub {
matrix_set_room_history_visibility_synced( $user, $room_id, "world_readable" )->then(sub {
do_request_json_for( $peeking_user,
method => "POST",
uri => "/r0/peek/$room_id",
Expand Down Expand Up @@ -85,7 +85,7 @@
check => sub {
my ( $user, $room_id, $peeking_user ) = @_;

matrix_set_room_history_visibility( $user, $room_id, $visibility )->then(sub {
matrix_set_room_history_visibility_synced( $user, $room_id, $visibility )->then(sub {
do_request_json_for( $peeking_user,
method => "POST",
uri => "/r0/peek/$room_id",
Expand Down Expand Up @@ -113,7 +113,7 @@
check => sub {
my ( $user, $room_id, $peeking_user ) = @_;

matrix_set_room_history_visibility( $user, $room_id, "world_readable" )->then(sub {
matrix_set_room_history_visibility_synced( $user, $room_id, "world_readable" )->then(sub {
do_request_json_for( $peeking_user,
method => "POST",
uri => "/r0/peek/#$room_alias_name:".$user->http->server_name,
Expand Down Expand Up @@ -149,7 +149,7 @@
my ( $user, $room_id, $peeking_user ) = @_;
my ( $peeking_user_device2 );

matrix_set_room_history_visibility( $user, $room_id, "world_readable" )->then(sub {
matrix_set_room_history_visibility_synced( $user, $room_id, "world_readable" )->then(sub {
matrix_login_again_with_user($peeking_user);
})->then(sub {
$peeking_user_device2 = $_[0];
Expand Down Expand Up @@ -213,10 +213,14 @@

# test "Users can peek, unpeek and peek again"

# test "Peeking into an unknown room returns the right error"

# test "Peeking with full_state=true does the right thing"

# test "Joining a peeked room moves it atomically from peeked to joined rooms and stops peeking"

# test "Parting a room which was joined after being peeked doesn't go back to being peeked"

# test "Changing history visibility to non-world_readable terminates peeks"

# test "Users can peek local EDUs"
96 changes: 96 additions & 0 deletions tests/50federation/44peeking.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# see 31sync/17peeking.pl for local peeking tests

my $room_alias_name = sprintf("peektest-%s", $TEST_RUN_ID);
test "Users can peek into world-readable remote rooms",
requires => [
local_user_and_room_fixtures(room_opts => { room_alias_name => $room_alias_name }),
remote_user_fixture()
],

check => sub {
my ( $user, $room_id, $peeking_user ) = @_;

matrix_set_room_history_visibility_synced( $user, $room_id, "world_readable" )->then(sub {
matrix_send_room_text_message_synced( $user, $room_id, body => "something to peek");
# XXX: this is flakey because we don't yet atomically /send events after starting /peeking,
# so if the /peek executes after the peeked server has already processed the event at the point
# of the peek, then we'll never receive it.
})->then(sub {
do_request_json_for( $peeking_user,
method => "POST",
uri => "/r0/peek/#$room_alias_name:".$user->http->server_name,
content => {},
)
})->then( sub {
await_sync( $peeking_user,
since => $peeking_user->sync_next_batch,
check => sub {
my ( $body ) = @_;
return 0 unless $body->{rooms}{peek}{$room_id} && @{$body->{rooms}{peek}{$room_id}{timeline}{events}};
return $body;
}
)
})->then( sub {
my ( $body ) = @_;
$peeking_user->sync_next_batch = $body->{next_batch};

log_if_fail "sync response", $body;

my $room = $body->{rooms}{peek}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));
assert_json_keys( $room->{state}, qw( events ));
assert_json_keys( $room->{ephemeral}, qw( events ));

assert_ok( (grep { $_->{type} eq 'm.room.create' } @{$room->{state}->{events}}), "peek has m.room.create in state" );
assert_ok( $room->{timeline}->{events}->[-1]->{type} eq 'm.room.message', "peek has message type" );
assert_ok( $room->{timeline}->{events}->[-1]->{content}->{body} eq 'something to peek', "peek has message body" );

assert_ok( scalar keys(%{$body->{rooms}{join}}) == 0, "no joined rooms present");
})->then( sub {
matrix_send_room_text_message_synced( $user, $room_id, body => "something else to peek");
})->then( sub {
await_sync( $peeking_user,
since => $peeking_user->sync_next_batch,
check => sub {
my ( $body ) = @_;
return 0 unless $body->{rooms}{peek}{$room_id};
return $body;
}
)
})->then( sub {
my ( $body ) = @_;
$peeking_user->sync_next_batch = $body->{next_batch};

log_if_fail "next sync response", $body;
my $room = $body->{rooms}{peek}{$room_id};

assert_ok( $room->{timeline}->{events}->[-1]->{type} eq 'm.room.message', "second peek has message type" );
assert_ok( $room->{timeline}->{events}->[-1]->{content}->{body} eq 'something else to peek', "second peek has message body" );

Future->done(1)
})
};

# test "Users can re-peek into world-readable remote rooms"

# test "Users cannot peek into remote rooms with non-world-readable history visibility"

# test "Remote peeks are cancelled if a room's history visibility changes to non-world-readable"

# test "Joining a peeked remote room moves it atomically from peeked to joined rooms"

# test "Peeking uses server_name to specify the peeking server"

# test "Peeking into an unknown room returns the right error"

# test "Server implements PUT /peek over federation correctly"

# test "Server implements DELETE /peek over federation correctly"

# test "If a peek is not renewed, the peeked server stops sending events"

# test "Server can't peek into unknown room versions"

# test "Can't peek if server-ACL'd"