-
Notifications
You must be signed in to change notification settings - Fork 55
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
test peeking via MSC2753 on dendrite #944
Merged
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4e08d6b
first cut at a test for MSC2753 on dendrite
ara4n 9ca6148
make test run
ara4n 3ee4dc5
warn about sodium version
ara4n 41dd900
first passing test :)
ara4n f7d696d
test peeking by alias
ara4n ff13930
add test that only the peeking device get peeked msgs
ara4n cac05b1
add failing test for ensuring peeks require world_readable history vi…
ara4n fb08c36
fix worldreadable test; add new stubs
ara4n a0a67db
Merge branch 'develop' into matthew/peeking
neilalexander 9a7cbd9
derace matrix_sync
ara4n ef863af
remove rogue line
ara4n 03b26e7
allow running against dendrite + sqlite
ara4n feb6069
fix spurious r flag causing a warning
ara4n d62a4de
disambiguate room alias to ensure re-running the test doesn't break
ara4n 15090d3
Merge branch 'matthew/tweaks' into matthew/peeking
ara4n d9a7427
fix race: send the peekable msg after rather than before the /peek
ara4n 5055724
#942 got fixed
ara4n ae72430
add stub test
ara4n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,220 @@ | ||
use Future::Utils qw( repeat ); | ||
use JSON qw( decode_json ); | ||
|
||
# Tests MSC2753 style peeking | ||
|
||
test "Local users can peek into world_readable rooms by room ID", | ||
requires => [ local_user_and_room_fixtures(), local_user_fixture() ], | ||
|
||
check => sub { | ||
my ( $user, $room_id, $peeking_user ) = @_; | ||
|
||
matrix_set_room_history_visibility( $user, $room_id, "world_readable" )->then(sub { | ||
do_request_json_for( $peeking_user, | ||
method => "POST", | ||
uri => "/r0/peek/$room_id", | ||
content => {}, | ||
) | ||
})->then( sub { | ||
matrix_send_room_text_message_synced( $user, $room_id, body => "something 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 "first 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( $room->{timeline}->{events}->[0]->{type} eq 'm.room.create', "peek has m.room.create" ); | ||
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( @{$room->{state}->{events}} == 0 ); | ||
|
||
assert_ok( scalar keys(%{$body->{rooms}{join}}) == 0, "no joined rooms present"); | ||
|
||
matrix_sync_again( $peeking_user ); | ||
})->then( sub { | ||
my ( $body ) = @_; | ||
|
||
log_if_fail "second sync response", $body; | ||
my $room = $body->{rooms}{peek}{$room_id}; | ||
(!defined $room) or die "Unchanged rooms shouldn't be in the sync response"; | ||
})->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 "third 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) | ||
}) | ||
}; | ||
|
||
|
||
for my $visibility (qw(shared invited joined)) { | ||
test "We can't peek into rooms with $visibility history_visibility", | ||
requires => [ local_user_and_room_fixtures(), local_user_fixture() ], | ||
|
||
check => sub { | ||
my ( $user, $room_id, $peeking_user ) = @_; | ||
|
||
matrix_set_room_history_visibility( $user, $room_id, $visibility )->then(sub { | ||
do_request_json_for( $peeking_user, | ||
method => "POST", | ||
uri => "/r0/peek/$room_id", | ||
content => {}, | ||
); | ||
})->main::expect_http_403() | ||
->then( sub { | ||
my ( $response ) = @_; | ||
my $body = decode_json( $response->content ); | ||
log_if_fail "error body", $body; | ||
assert_eq( $body->{errcode}, "M_FORBIDDEN", 'responsecode' ); | ||
Future->done( 1 ); | ||
}); | ||
}; | ||
} | ||
|
||
|
||
my $room_alias_name = sprintf("peektest-%s", $TEST_RUN_ID); | ||
test "Local users can peek by room alias", | ||
requires => [ | ||
local_user_and_room_fixtures(room_opts => { room_alias_name => $room_alias_name }), | ||
local_user_fixture() | ||
], | ||
|
||
check => sub { | ||
my ( $user, $room_id, $peeking_user ) = @_; | ||
|
||
matrix_set_room_history_visibility( $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, | ||
content => {}, | ||
) | ||
})->then(sub { | ||
matrix_send_room_text_message_synced( $user, $room_id, body => "something 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 "first sync response", $body; | ||
|
||
my $room = $body->{rooms}{peek}{$room_id}; | ||
assert_ok( $room->{timeline}->{events}->[-1]->{content}->{body} eq 'something to peek', "peek has message body" ); | ||
Future->done(1) | ||
}) | ||
}; | ||
|
||
test "Peeked rooms only turn up in the sync for the device who peeked them", | ||
requires => [ local_user_and_room_fixtures(), local_user_fixture() ], | ||
|
||
check => sub { | ||
my ( $user, $room_id, $peeking_user ) = @_; | ||
my ( $peeking_user_device2 ); | ||
|
||
matrix_set_room_history_visibility( $user, $room_id, "world_readable" )->then(sub { | ||
matrix_login_again_with_user($peeking_user); | ||
})->then(sub { | ||
$peeking_user_device2 = $_[0]; | ||
do_request_json_for( $peeking_user, | ||
method => "POST", | ||
uri => "/r0/peek/$room_id", | ||
content => {}, | ||
) | ||
})->then(sub { | ||
matrix_send_room_text_message_synced( $user, $room_id, body => "something 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 "device 1 first sync response", $body; | ||
my $room = $body->{rooms}{peek}{$room_id}; | ||
assert_ok( $room->{timeline}->{events}->[-1]->{content}->{body} eq 'something to peek', "peek has message body" ); | ||
})->then(sub { | ||
# FIXME: racey - this may return blank due to the peek not having taken effect yet | ||
matrix_sync( $peeking_user_device2, timeout => 1000 ); | ||
})->then( sub { | ||
my ( $body ) = @_; | ||
log_if_fail "device 2 first sync response", $body; | ||
assert_ok( scalar keys(%{$body->{rooms}{peek}}) == 0, "no peeked 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 "device 1 second sync response", $body; | ||
my $room = $body->{rooms}{peek}{$room_id}; | ||
assert_ok( $room->{timeline}->{events}->[-1]->{content}->{body} eq 'something else to peek', "second peek has message body" ); | ||
# FIXME: racey - this may return blank due to the peek not having taken effect yet | ||
matrix_sync_again( $peeking_user_device2, timeout => 1000 ); | ||
})->then( sub { | ||
my ( $body ) = @_; | ||
log_if_fail "device 2 second sync response", $body; | ||
assert_ok( scalar keys(%{$body->{rooms}{peek}}) == 0, "still no peeked rooms present"); | ||
Future->done(1) | ||
}) | ||
}; | ||
|
||
# test "Users can unpeek from rooms" | ||
|
||
# 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" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was causing test fails when run on an existing db if that alias already existed.