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

Room version 6 tests #869

Merged
merged 36 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
79ac786
Add a test-case for invalid JSON (integers out of range).
clokep Apr 27, 2020
695dfcb
Specify the room version.
clokep Apr 28, 2020
d80cb4b
Add tests for floats.
clokep Apr 29, 2020
65855e0
Switch to room version 6 instead of experimental version.
clokep May 14, 2020
d10ad89
Add version 6.
clokep May 14, 2020
dbc682a
Add a test for asserting the notifications power levels of room ver 6.
clokep May 15, 2020
e75245c
POST not PUT
clokep May 18, 2020
972e60b
Properly send infinity / NaN from Perl.
clokep May 18, 2020
727e23f
Fix typo.
clokep May 18, 2020
18e664a
Merge remote-tracking branch 'origin/develop' into clokep/room-ver-6
clokep May 18, 2020
82ae5cd
Clarify that invalid values aren't even JSON.
clokep May 19, 2020
459d9e0
Remove erronously added import.
clokep May 19, 2020
4e65103
Send join tests.
clokep May 21, 2020
d8eaaf8
Add a test for send invite.
clokep May 22, 2020
ee7c457
Reject a v6 room invite successfully.
clokep May 22, 2020
3df4a73
Test send_leave with bad JSON.
clokep May 26, 2020
5054240
Add a test for bad data in the return to make_invite.
clokep May 27, 2020
82907bc
Abstract the code that checks for a bad JSON return code.
clokep May 27, 2020
5bab21c
Add tests for /send API with bad JSON.
clokep May 27, 2020
c4aa0ee
Partially roll-back the JSON checks.
clokep May 27, 2020
9194474
Ensure a bad event doesn't come do backfill.
clokep May 28, 2020
d4340b6
Add a passing test for get_missing_events.
clokep May 29, 2020
2e6e10d
Modify the test to have bad JSON.
clokep Jun 1, 2020
11f68ec
Remove unused variables.
clokep Jun 1, 2020
ed08c3b
Merge branch 'develop' into clokep/room-ver-6
clokep Jun 1, 2020
6663e5d
Move helper for checking for a bad JSON value.
clokep Jun 1, 2020
fa8ce9c
Remove with_events option.
clokep Jun 1, 2020
0dd8fa3
Clarify the get_missing_events test.
clokep Jun 1, 2020
ee89a40
Unique room alias.
clokep Jun 1, 2020
a17a675
Consistently use Future->done.
clokep Jun 1, 2020
4e582a8
Remove duplicate checks.
clokep Jun 1, 2020
9ab4878
Add comments.
clokep Jun 2, 2020
f3d5574
Use federated_rooms_fixture.
clokep Jun 2, 2020
0aebc56
Use matrix_join_room.
clokep Jun 2, 2020
1238be2
Switch to matrix_join_room_synced.
clokep Jun 2, 2020
a49a240
Fix typos
clokep Jun 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/SyTest/Federation/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use SyTest::Assertions qw( :all );
use URI::Escape qw( uri_escape );

use constant SUPPORTED_ROOM_VERSIONS => [qw(
1 2 3 4 5
org.matrix.msc2260
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This room version was previously removed from Synapse, it also seems a bit weird to bit unstable room versions in here.

1 2 3 4 5 6
)];

sub configure
Expand Down
27 changes: 25 additions & 2 deletions tests/30rooms/08levels.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@

sub lockeddown_room_fixture
{
my ( %options ) = @_;

fixture(
requires => [ $creator_fixture, $user_fixture,
qw( can_change_power_levels ) ],

setup => sub {
my ( $creator, $test_user ) = @_;

matrix_create_and_join_room( [ $creator, $test_user ] )
matrix_create_and_join_room( [ $creator, $test_user ], %options )
->then( sub {
my ( $room_id ) = @_;

Expand Down Expand Up @@ -154,6 +156,27 @@ sub test_powerlevel

$levels->{$levelname} = 10000000;
})->main::expect_http_403
})->SyTest::pass_on_done( "Fails at setting 75" );
})->SyTest::pass_on_done( "Fails at setting 10000000" );
};
}

multi_test "Users cannot set notifications powerlevel higher than their own",
requires => [ $creator_fixture, $user_fixture, lockeddown_room_fixture( room_version => "6" ),
qw( can_change_power_levels )],

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

matrix_change_room_power_levels( $user, $room_id, sub {
my ( $levels ) = @_;

$levels->{notifications}{room} = 25;
})->SyTest::pass_on_done( "Succeeds at setting 25" )
->then( sub {
matrix_change_room_power_levels( $user, $room_id, sub {
my ( $levels ) = @_;

$levels->{notifications}{room} = 10000000;
})->main::expect_http_403
})->SyTest::pass_on_done( "Fails at setting 10000000" );
};
2 changes: 1 addition & 1 deletion tests/32room-versions.pl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use URI::Escape qw( uri_escape );

# We test that some basic functionality works across all room versions
foreach my $version ( qw ( 1 2 3 4 5 ) ) {
foreach my $version ( qw ( 1 2 3 4 5 6 ) ) {
multi_test "User can create and send/receive messages in a room with version $version",
requires => [ local_user_fixture() ],

Expand Down
123 changes: 123 additions & 0 deletions tests/80torture/20json.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Test integers that are outside of the range of [-2 ^ 53 + 1, 2 ^ 53 - 1].
test "Invalid JSON integers",
requires => [ local_user_and_room_fixtures(
room_opts => { room_version => "6" }
), ],

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

Future->needs_all(
do_request_json_for( $user,
method => "POST",
uri => "/r0/rooms/$room_id/send/sytest.dummy",
content => {
msgtype => "sytest.dummy",
body => 9007199254740992, # 2 ** 53
},
)->followed_by( \&main::expect_http_400 ),

do_request_json_for( $user,
method => "POST",
uri => "/r0/rooms/$room_id/send/sytest.dummy",
content => {
msgtype => "sytest.dummy",
body => -9007199254740992, # -2 ** 53
},
)->followed_by( \&main::expect_http_400 ),
);
};

# Floats should be rejected.
test "Invalid JSON floats",
requires => [ local_user_and_room_fixtures(
room_opts => { room_version => "6" }
), ],

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

do_request_json_for( $user,
method => "POST",
uri => "/r0/rooms/$room_id/send/sytest.dummy",
content => {
msgtype => "sytest.dummy",
body => 1.1,
},
)->followed_by( \&main::expect_http_400 );
};

# Special values (like inf/nan) should be rejected. Note that these values are
# not technically valid JSON, but extensions that some programming languages
# support automatically.
test "Invalid JSON special values",
requires => [ local_user_and_room_fixtures(
room_opts => { room_version => "6" }
), ],

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

my $http = $user->http;

Future->needs_all(
# Try some Perl magic values.
do_request_json_for( $user,
method => "POST",
uri => "/r0/rooms/$room_id/send/sytest.dummy",
content => {
msgtype => "sytest.dummy",
body => "NaN" + 0,
},
)->followed_by( \&main::expect_http_400 ),

do_request_json_for( $user,
method => "POST",
uri => "/r0/rooms/$room_id/send/sytest.dummy",
content => {
msgtype => "sytest.dummy",
body => "inf" + 0,
},
)->followed_by( \&main::expect_http_400 ),

do_request_json_for( $user,
method => "POST",
uri => "/r0/rooms/$room_id/send/sytest.dummy",
content => {
msgtype => "sytest.dummy",
body => "-inf" + 0,
},
)->followed_by( \&main::expect_http_400 ),

# Try some Python magic values.
$user->http->do_request(
method => "POST",
uri => "/r0/rooms/$room_id/send/sytest.dummy",
params => {
access_token => $user->access_token,
},
content => '{"msgtype": "sytest.dummy", "body": Infinity}',
content_type => "application/json",
)->followed_by( \&main::expect_http_400 ),

$user->http->do_request(
method => "POST",
uri => "/r0/rooms/$room_id/send/sytest.dummy",
params => {
access_token => $user->access_token,
},
content => '{"msgtype": "sytest.dummy", "body": -Infinity}',
content_type => "application/json",
)->followed_by( \&main::expect_http_400 ),

$user->http->do_request(
method => "POST",
uri => "/r0/rooms/$room_id/send/sytest.dummy",
params => {
access_token => $user->access_token,
},
content => '{"msgtype": "sytest.dummy", "body": NaN}',
content_type => "application/json",
)->followed_by( \&main::expect_http_400 ),
);
};