Skip to content

Commit

Permalink
Merge from 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Feb 28, 2017
1 parent 5720b64 commit fb631ec
Show file tree
Hide file tree
Showing 11 changed files with 847 additions and 72 deletions.
4 changes: 4 additions & 0 deletions lib/SyTest/Federation/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ __PACKAGE__->mk_await_request_pair(
event => [qw( :event_id )],
);

__PACKAGE__->mk_await_request_pair(
user_devices => [qw( :user_id )],
);

sub on_request_federation_v1_send
{
my $self = shift;
Expand Down
27 changes: 13 additions & 14 deletions lib/SyTest/Homeserver/Synapse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ sub _init
my ( $args ) = @_;

$self->{$_} = delete $args->{$_} for qw(
ports synapse_dir extra_args python coverage
dendron pusher synchrotron federation_reader bind_host
media_repository appservice client_reader federation_sender
ports synapse_dir extra_args python coverage dendron bind_host
);

defined $self->{ports}{$_} or croak "Need a '$_' port\n"
Expand Down Expand Up @@ -189,11 +187,12 @@ sub start
listeners => $listeners,

bcrypt_rounds => 0,
start_pushers => ( not $self->{pusher} ),

notify_appservices => ( not $self->{appservice} ),

send_federation => ( not $self->{federation_sender} ),
# If we're using dendron-style split workers, we need to disable these
# things in the main process
start_pushers => ( not $self->{dendron} ),
notify_appservices => ( not $self->{dendron} ),
send_federation => ( not $self->{dendron} ),

url_preview_enabled => "true",
url_preview_ip_range_blacklist => [],
Expand Down Expand Up @@ -541,7 +540,7 @@ sub wrap_synapse_command
"--addr" => "$bind_host:" . $self->{ports}{dendron},
);

if( $self->{pusher} ) {
{
my $pusher_config_path = $self->write_yaml_file( pusher => {
"worker_app" => "synapse.app.pusher",
"worker_log_file" => "$log.pusher",
Expand All @@ -564,7 +563,7 @@ sub wrap_synapse_command
push @command, "--pusher-config" => $pusher_config_path;
}

if( $self->{appservice} ) {
{
my $appservice_config_path = $self->write_yaml_file( appservice => {
"worker_app" => "synapse.app.appservice",
"worker_log_file" => "$log.appservice",
Expand All @@ -587,7 +586,7 @@ sub wrap_synapse_command
push @command, "--appservice-config" => $appservice_config_path;
}

if( $self->{federation_sender} ) {
{
my $federation_sender_config_path = $self->write_yaml_file( federation_sender => {
"worker_app" => "synapse.app.federation_sender",
"worker_log_file" => "$log.federation_sender",
Expand All @@ -610,7 +609,7 @@ sub wrap_synapse_command
push @command, "--federation-sender-config" => $federation_sender_config_path;
}

if( $self->{synchrotron} ) {
{
my $synchrotron_config_path = $self->write_yaml_file( synchrotron => {
"worker_app" => "synapse.app.synchrotron",
"worker_log_file" => "$log.synchrotron",
Expand Down Expand Up @@ -641,7 +640,7 @@ sub wrap_synapse_command
"--synchrotron-url" => "http://$bind_host:$self->{ports}{synchrotron}";
}

if( $self->{federation_reader} ) {
{
my $federation_reader_config_path = $self->write_yaml_file( federation_reader => {
"worker_app" => "synapse.app.federation_reader",
"worker_log_file" => "$log.federation_reader",
Expand Down Expand Up @@ -672,7 +671,7 @@ sub wrap_synapse_command
"--federation-reader-url" => "http://$bind_host:$self->{ports}{federation_reader}";
}

if( $self->{media_repository} ) {
{
my $media_repository_config_path = $self->write_yaml_file( media_repository => {
"worker_app" => "synapse.app.media_repository",
"worker_log_file" => "$log.media_repository",
Expand Down Expand Up @@ -703,7 +702,7 @@ sub wrap_synapse_command
"--media-repository-url" => "http://$bind_host:$self->{ports}{media_repository}";
}

if( $self->{client_reader} ) {
{
my $client_reader_config_path = $self->write_yaml_file( client_reader => {
"worker_app" => "synapse.app.client_reader",
"worker_log_file" => "$log.client_reader",
Expand Down
18 changes: 7 additions & 11 deletions run-tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,13 @@

'pusher+' => \$SYNAPSE_ARGS{pusher},

'synchrotron+' => \$SYNAPSE_ARGS{synchrotron},

'federation-reader+' => \$SYNAPSE_ARGS{federation_reader},

'media-repository+' => \$SYNAPSE_ARGS{media_repository},

'appservice+' => \$SYNAPSE_ARGS{appservice},

'federation-sender+' => \$SYNAPSE_ARGS{federation_sender},

'client-reader+' => \$SYNAPSE_ARGS{client_reader},
# These are now unused, but retaining arguments for commandline parsing support
'synchrotron+' => sub {},
'federation-reader+' => sub {},
'media-repository+' => sub {},
'appservice+' => sub {},
'federation-sender+' => sub {},
'client-reader+' => sub {},

'bind-host=s' => \$BIND_HOST,

Expand Down
7 changes: 0 additions & 7 deletions tests/05synapse.pl
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ sub extract_extra_args
python => $SYNAPSE_ARGS{python},
coverage => $SYNAPSE_ARGS{coverage},
dendron => $SYNAPSE_ARGS{dendron},
pusher => $SYNAPSE_ARGS{pusher},
synchrotron => $SYNAPSE_ARGS{synchrotron},
federation_reader => $SYNAPSE_ARGS{federation_reader},
media_repository => $SYNAPSE_ARGS{media_repository},
appservice => $SYNAPSE_ARGS{appservice},
federation_sender => $SYNAPSE_ARGS{federation_sender},
client_reader => $SYNAPSE_ARGS{client_reader},
( scalar @{ $SYNAPSE_ARGS{log_filter} } ?
( filter_output => $SYNAPSE_ARGS{log_filter} ) :
() ),
Expand Down
3 changes: 1 addition & 2 deletions tests/10apidoc/12device_management.pl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use JSON qw( decode_json );
use Future::Utils qw( try_repeat_until_success );

our @EXPORT = qw( matrix_get_device matrix_set_device_display_name );
our @EXPORT = qw( matrix_get_device matrix_set_device_display_name matrix_delete_device );

sub matrix_get_device {
my ( $user, $device_id ) = @_;
Expand Down Expand Up @@ -287,4 +287,3 @@ sub matrix_delete_device {
matrix_delete_device( $user, $DEVICE_ID, undef );
})->main::expect_http_401;
};

69 changes: 37 additions & 32 deletions tests/10apidoc/31room-state.pl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use List::Util qw( any );
use List::UtilsBy qw( partition_by );
use Future::Utils qw( try_repeat_until_success );

my $name = "room name here";

Expand Down Expand Up @@ -241,33 +242,35 @@

proves => [qw( can_set_room_name )],

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

my $delay = 0.1;

do_request_json_for( $user,
method => "PUT",
uri => "/r0/rooms/$room_id/state/m.room.name",

content => { name => $name },
);
},

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

matrix_initialsync_room( $user, $room_id )->then( sub {
my ( $body ) = @_;
)->then( sub {
try_repeat_until_success( sub {
matrix_initialsync_room( $user, $room_id )->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, qw( state ));
my $state = $body->{state};
assert_json_keys( $body, qw( state ));
my $state = $body->{state};

my %state_by_type = partition_by { $_->{type} } @$state;
my %state_by_type = partition_by { $_->{type} } @$state;

$state_by_type{"m.room.name"} or
die "Expected to find m.room.name state";
$state_by_type{"m.room.name"} or
die "Expected to find m.room.name state";

Future->done(1);
});
Future->done(1);
})->else_with_f( sub {
my ( $f ) = @_; delay( $delay *= 1.5 )->then( sub { $f } );
})
});
})
};

test "GET /rooms/:room_id/state/m.room.name gets name",
Expand Down Expand Up @@ -302,33 +305,35 @@

proves => [qw( can_set_room_topic )],

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

my $delay = 0.1;

do_request_json_for( $user,
method => "PUT",
uri => "/r0/rooms/$room_id/state/m.room.topic",

content => { topic => $topic },
);
},

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

matrix_initialsync_room( $user, $room_id )->then( sub {
my ( $body ) = @_;
)->then( sub {
try_repeat_until_success( sub {
matrix_initialsync_room( $user, $room_id )->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, qw( state ));
my $state = $body->{state};
assert_json_keys( $body, qw( state ));
my $state = $body->{state};

my %state_by_type = partition_by { $_->{type} } @$state;
my %state_by_type = partition_by { $_->{type} } @$state;

$state_by_type{"m.room.topic"} or
die "Expected to find m.room.topic state";
$state_by_type{"m.room.topic"} or
die "Expected to find m.room.topic state";

Future->done(1);
});
Future->done(1);
})->else_with_f( sub {
my ( $f ) = @_; delay( $delay *= 1.5 )->then( sub { $f } );
})
})
})
};

test "GET /rooms/:room_id/state/m.room.topic gets topic",
Expand Down
13 changes: 8 additions & 5 deletions tests/30rooms/13guestaccess.pl
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,16 @@
}),
);
})->then( sub {
matrix_get_room_membership( $local_user, $room_id, $guest_user );
})->then( sub {
my ( $membership ) = @_;
try_repeat_until_success( sub {
matrix_get_room_membership( $local_user, $room_id, $guest_user )
->then( sub {
my ( $membership ) = @_;

assert_eq( $membership, "leave", "membership" );
assert_eq( $membership, "leave", "membership" );

Future->done(1);
Future->done(1);
})
})
});
})
};
Expand Down
41 changes: 41 additions & 0 deletions tests/30rooms/50context.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
test "/context/ on joined room works",
requires => [ local_user_and_room_fixtures() ],

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

matrix_send_room_text_message( $user, $room_id,
body => "hello, world",
)->then( sub {
my ( $event_id ) = @_;

do_request_json_for( $user,
method => "GET",
uri => "/r0/rooms/$room_id/context/$event_id",
);
})->then( sub {
my ( $body ) = @_;

assert_json_keys( $body, qw( state event ) );

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

test "/context/ on non world readable room does not work",
requires => [ local_user_and_room_fixtures(), local_user_fixture() ],

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

matrix_send_room_text_message( $user, $room_id,
body => "hello, world",
)->then( sub {
my ( $event_id ) = @_;

do_request_json_for( $other_user,
method => "GET",
uri => "/r0/rooms/$room_id/context/$event_id",
);
})->main::expect_http_403;
};
5 changes: 4 additions & 1 deletion tests/41end-to-end-keys/01-upload-key.pl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@
sub matrix_put_e2e_keys
{
# TODO(paul): I don't really know what's parametric about this
my ( $user ) = @_;
my ( $user, %params ) = @_;

my $device_keys = $params{device_keys} // {};

do_request_json_for( $user,
method => "POST",
Expand All @@ -179,6 +181,7 @@ sub matrix_put_e2e_keys
device_keys => {
user_id => $user->user_id,
device_id => $user->device_id,
device_keys => $device_keys,
},
one_time_keys => {
"my_algorithm:my_id_1" => "my+base64+key",
Expand Down
Loading

0 comments on commit fb631ec

Please sign in to comment.