Skip to content

Commit

Permalink
Merge branch 'develop' into paul/room-alias-fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Jan 5, 2016
2 parents 62bbd6f + 1337730 commit 74e41a8
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 29 deletions.
2 changes: 2 additions & 0 deletions tests/10apidoc/30room-create.pl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ sub matrix_create_room
( room_alias_name => $opts{room_alias_name} ) : () ),
( defined $opts{invite} ?
( invite => $opts{invite} ) : () ),
( defined $opts{invite_3pid} ?
( invite_3pid => $opts{invite_3pid} ) : () ),
( defined $opts{creation_content} ?
( creation_content => $opts{creation_content} ) : () ),
}
Expand Down
84 changes: 59 additions & 25 deletions tests/30rooms/12thirdpartyinvite.pl
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,68 @@
$id_server->bind_identity( undef, "email", $invitee_email, $invitee )
->then( sub {
matrix_create_and_join_room( [ $inviter ], visibility => "private" )
->then( sub {
( $room_id ) = @_;

do_request_json_for( $inviter,
method => "POST",
uri => "/api/v1/rooms/$room_id/invite",

content => {
id_server => $id_server->name,
medium => "email",
address => $invitee_email,
},
);
})->then( sub {
matrix_get_room_state( $inviter, $room_id,
type => "m.room.member",
state_key => $invitee_mxid,
)->on_done( sub {
my ( $body ) = @_;

log_if_fail "Body", $body;
$body->{membership} eq "invite" or
die "Expected invited user membership to be 'invite'";
});
});
})->then( sub {
( $room_id ) = @_;

do_request_json_for( $inviter,
method => "POST",
uri => "/api/v1/rooms/$room_id/invite",

content => {
id_server => $id_server->name,
medium => "email",
address => $invitee_email,
},
);
})->then( sub {
matrix_get_room_state( $inviter, $room_id,
type => "m.room.member",
state_key => $invitee_mxid,
);
})->on_done( sub {
my ( $body ) = @_;

log_if_fail "Body", $body;
assert_eq( $body->{membership}, "invite",
'invited user membership' );
});
};

test "Can invite existing 3pid in createRoom",
requires => [ local_user_fixtures( 2 ), id_server_fixture() ],

do => sub {
my ( $inviter, $invitee, $id_server ) = @_;

my $invitee_mxid = $invitee->user_id;

my $room_id;

$id_server->bind_identity( undef, "email", $invitee_email, $invitee )
->then( sub {
my $invite_info = {
medium => "email",
address => $invitee_email,
id_server => $id_server->name,
};
matrix_create_room( $inviter, invite_3pid => [ $invite_info ] );
})->then( sub {
( $room_id ) = @_;

matrix_get_room_state( $inviter, $room_id,
type => "m.room.member",
state_key => $invitee_mxid,
);
})->on_done( sub {
my ( $body ) = @_;

log_if_fail "Body", $body;
assert_eq( $body->{membership}, "invite",
'invited user membership' );
});
};


test "Can invite unbound 3pid",
requires => [ local_user_fixtures( 2 ), $main::HOMESERVER_INFO[0],
id_server_fixture() ],
Expand Down
171 changes: 167 additions & 4 deletions tests/30rooms/60anonymousaccess.pl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use Future::Utils qw( try_repeat_until_success );
use JSON qw( encode_json );

test "Anonymous user cannot view non-world-readable rooms",
requires => [ anonymous_user_fixture(), local_user_fixture() ],
Expand All @@ -17,8 +18,7 @@
matrix_send_room_text_message( $user, $room_id, body => "mice" )
})->then( sub {
matrix_get_room_messages( $anonymous_user, $room_id, limit => "1" )
->main::expect_http_403;
});
})->followed_by( \&expect_4xx_or_empty_chunk );
};

test "Anonymous user can view world-readable rooms",
Expand Down Expand Up @@ -56,7 +56,26 @@
matrix_send_room_text_message( $user, $room_id, body => "mice" )
})->then( sub {
matrix_get_room_messages( $anonymous_user, $room_id, limit => "2" )
->main::expect_http_403;
})->followed_by( \&expect_4xx_or_empty_chunk );
};

test "Anonymous user cannot call /sync on non-world_readable room",
requires => [ anonymous_user_fixture(), local_user_fixture() ],

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

my $room_id;

matrix_create_and_join_room( [ $user ] )
->then( sub {
( $room_id ) = @_;

matrix_send_room_text_message( $user, $room_id, body => "mice" )
})->then( sub {
matrix_sync( $anonymous_user, filter => encode_json( {
room => { rooms => [ $room_id ] }
}))->main::expect_http_403;
});
};

Expand All @@ -80,7 +99,6 @@ sub await_event_not_presence_for
});
}


test "Anonymous user can call /events on world_readable room",
requires => [ anonymous_user_fixture(), local_user_fixture(), local_user_fixture() ],

Expand Down Expand Up @@ -193,6 +211,44 @@ sub await_event_not_presence_for
});
};

test "Annonymous user can call /sync on a world readable room",
requires => [ anonymous_user_fixture(), local_user_fixture() ],

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

my ( $room_id, $sent_event_id );

matrix_create_and_join_room( [ $user ] )
->then( sub {
( $room_id ) = @_;

matrix_set_room_history_visibility( $user, $room_id, "world_readable" );
})->then( sub {
matrix_send_room_text_message( $user, $room_id, body => "mice" );
})->then( sub {
( $sent_event_id ) = @_;

matrix_sync( $anonymous_user, filter => encode_json({
room => {
rooms => [ $room_id ],
ephemeral => { types => [] },
state => { types => [] },
timeline => { types => ["m.room.message"] },
},
presence => { types => [] }
}));
})->then( sub {
my ( $sync_body ) = @_;

assert_json_object( my $room = $sync_body->{rooms}{join}{$room_id} );
assert_json_list( my $events = $room->{timeline}{events} );
assert_eq( $events->[0]{event_id}, $sent_event_id, 'event id' );

Future->done( 1 );
});
};

test "Anonymous user doesn't get events before room made world_readable",
requires => [ anonymous_user_fixture(), local_user_fixture() ],

Expand Down Expand Up @@ -689,6 +745,87 @@ sub check_events
});
};

test "GET /publicRooms includes avatar URLs",
requires => [ $main::API_CLIENTS[0], local_user_fixture() ],

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

Future->needs_all(
matrix_create_room( $user,
visibility => "public",
room_alias_name => "nonworldreadable",
)->then( sub {
my ( $room_id ) = @_;

matrix_put_room_state( $user, $room_id,
type => "m.room.avatar",
state_key => "",
content => {
url => "https://example.com/ruffed.jpg",
}
);
}),

matrix_create_room( $user,
visibility => "public",
room_alias_name => "worldreadable",
)->then( sub {
my ( $room_id ) = @_;

Future->needs_all(
matrix_set_room_history_visibility( $user, $room_id, "world_readable" ),
matrix_put_room_state( $user, $room_id,
type => "m.room.avatar",
state_key => "",
content => {
url => "https://example.com/ringtails.jpg",
}
),
);
}),
)->then( sub {
$http->do_request_json(
method => "GET",
uri => "/api/v1/publicRooms",
)})->then( sub {
my ( $body ) = @_;

log_if_fail "publicRooms", $body;

assert_json_keys( $body, qw( start end chunk ));
assert_json_list( $body->{chunk} );

my %seen = (
worldreadable => 0,
nonworldreadable => 0,
);

foreach my $room ( @{ $body->{chunk} } ) {
my $aliases = $room->{aliases};

foreach my $alias ( @{$aliases} ) {
if( $alias =~ m/^\Q#worldreadable:/ ) {
assert_json_keys( $room, qw( avatar_url ) );
assert_eq( $room->{avatar_url}, "https://example.com/ringtails.jpg", "avatar_url" );
$seen{worldreadable} = 1;
}
elsif( $alias =~ m/^\Q#nonworldreadable:/ ) {
assert_json_keys( $room, qw( avatar_url ) );
assert_eq( $room->{avatar_url}, "https://example.com/ruffed.jpg", "avatar_url" );
$seen{nonworldreadable} = 1;
}
}
}

foreach my $key (keys %seen ) {
$seen{$key} or die "Didn't see $key";
}

Future->done(1);
});
};

sub anonymous_user_fixture
{
fixture(
Expand Down Expand Up @@ -756,3 +893,29 @@ sub ignore_presence_for
)
} @events ];
}

sub expect_4xx_or_empty_chunk
{
my ( $f ) = @_;

$f->then( sub {
my ( $body ) = @_;

log_if_fail "Body", $body;

assert_json_keys( $body, qw( chunk ) );
assert_json_list( $body->{chunk} );
die "Want list to be empty" if @{ $body->{chunk} };

Future->done( 1 );
},
http => sub {
my ( undef, undef, $response ) = @_;

log_if_fail "HTTP Response", $response;

$response->code >= 400 and $response->code < 500 or die "want 4xx";

Future->done( 1 );
});
}
47 changes: 47 additions & 0 deletions tests/31sync/08polling.pl
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,50 @@
Future->done(1)
})
};

test "Sync is woken up for leaves",
requires => [ local_user_fixture( with_events => 0 ),
qw( can_sync ) ],

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

my ( $filter_id, $room_id, $next );

matrix_create_filter( $user, {} )->then( sub {
( $filter_id ) = @_;

matrix_create_room( $user );
})->then( sub {
( $room_id ) = @_;

matrix_sync( $user, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;

$next = $body->{next_batch};
Future->needs_all(
matrix_sync( $user,
filter => $filter_id, since => $next, timeout => 10000
),

delay( 0.1 )->then( sub {
matrix_leave_room(
$user, $room_id
)
}),
)
})->then( sub {
my ( $body, $response, $event_id ) = @_;

my $room = $body->{rooms}{leave}{$room_id};

my $events = $room->{timeline}{events} or
die "Expected an event timeline";
@$events == 1 or
die "Expected one timeline event";

Future->done(1)
})
};

0 comments on commit 74e41a8

Please sign in to comment.