Skip to content

Commit

Permalink
Merge pull request #647 from matrix-org/babolivier/invite-json
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Feb 17, 2020
2 parents 4de9317 + 5814b6c commit 32737e6
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 166 deletions.
6 changes: 5 additions & 1 deletion lib/SyTest/Federation/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use HTTP::Headers::Util qw( join_header_words );

use SyTest::Assertions qw( :all );

use URI::Escape qw( uri_escape );

sub configure
{
my $self = shift;
Expand All @@ -30,10 +32,12 @@ sub _fetch_key
my $self = shift;
my ( $server_name, $key_id ) = @_;

my $key_id_encoded = uri_escape($key_id);

$self->do_request_json(
method => "GET",
hostname => $server_name,
full_uri => "/_matrix/key/v2/server/$key_id",
full_uri => "/_matrix/key/v2/server/$key_id_encoded",
)->then( sub {
my ( $body ) = @_;

Expand Down
12 changes: 10 additions & 2 deletions lib/SyTest/Homeserver/Synapse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use POSIX qw( strftime WIFEXITED WEXITSTATUS );

use YAML ();

use SyTest::SSL qw( ensure_ssl_cert );
use SyTest::SSL qw( ensure_ssl_key create_ssl_cert );

sub _init
{
Expand Down Expand Up @@ -150,7 +150,8 @@ sub start
$self->{paths}{cert_file} = "$hs_dir/tls.crt";
$self->{paths}{key_file} = "$hs_dir/tls.key";

ensure_ssl_cert( $self->{paths}{cert_file}, $self->{paths}{key_file}, $bind_host );
ensure_ssl_key( $self->{paths}{key_file} );
create_ssl_cert( $self->{paths}{cert_file}, $self->{paths}{key_file}, $bind_host );

my $config_path = $self->{paths}{config} = $self->write_yaml_file( "config.yaml" => {
server_name => $self->server_name,
Expand Down Expand Up @@ -195,6 +196,13 @@ sub start
burst_count => 1000,
}
},

rc_federation => {
# allow 100 requests per sec instead of 10
sleep_limit => 100,
window_size => 1000,
},

enable_registration => "true",
database => \%synapse_db_config,
macaroon_secret_key => $macaroon_secret_key,
Expand Down
2 changes: 1 addition & 1 deletion lib/SyTest/Identity/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ sub on_request
$req->respond_json( \%resp );
}
elsif( $path eq "/_matrix/identity/api/v1/store-invite" ) {
my $body = $req->body_from_form;
my $body = $req->body_from_json;
my $medium = $body->{medium};
my $address = $body->{address};
my $sender = $body->{sender};
Expand Down
55 changes: 33 additions & 22 deletions lib/SyTest/SSL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,53 @@ package SyTest::SSL;

use Exporter 'import';
our @EXPORT_OK = qw(
ensure_ssl_cert
ensure_ssl_key
create_ssl_cert
);

=head2 ensure_ssl_cert
=head2 ensure_ssl_key
ensure_ssl_cert( $cert_file, $key_file, $server_name );
ensure_ssl_key( $key_file );
Ensure that an SSL certificate file and key file exist. If they do not,
generate a key and/or certificate. The certificate will be signed by the test CA.
Create an SSL key file, if it doesn't exist.
=cut

sub ensure_ssl_cert
sub ensure_ssl_key
{
my ( $cert_file, $key_file, $server_name ) = @_;
my ( $key_file ) = @_;

if ( ! -e $key_file ) {
# todo: we can do this in pure perl
system("openssl", "genrsa", "-out", $key_file, "2048") == 0
or die "openssl genrsa failed $?";
}
}

if ( ! -e $cert_file ) {
# generate a CSR
my $csr_file = "$cert_file.csr";
system(
"openssl", "req", "-new", "-key", $key_file, "-out", $csr_file,
"-subj", "/CN=$server_name",
) == 0 or die "openssl req failed $?";

# sign it with the CA
system(
"openssl", "x509", "-req", "-in", $csr_file,
"-CA", "keys/ca.crt", "-CAkey", "keys/ca.key", "-set_serial", 1,
"-out", $cert_file,
) == 0 or die "openssl x509 failed $?";
}
=head2 create_ssl_cert
create_ssl_cert( $cert_file, $key_file, $server_name );
Create a new SSL certificate file. The certificate will be signed by the test CA.
=cut

sub create_ssl_cert
{
my ( $cert_file, $key_file, $server_name ) = @_;

# generate a CSR
my $csr_file = "$cert_file.csr";
system(
"openssl", "req", "-new", "-key", $key_file, "-out", $csr_file,
"-subj", "/CN=$server_name",
) == 0 or die "openssl req failed $?";

# sign it with the CA
system(
"openssl", "x509", "-req", "-in", $csr_file,
"-CA", "keys/ca.crt", "-CAkey", "keys/ca.key", "-set_serial", 1,
"-out", $cert_file,
) == 0 or die "openssl x509 failed $?";
}

11 changes: 0 additions & 11 deletions run-tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
# and the like.
our $TEST_RUN_ID = strftime( '%Y%m%d_%H%M%S', gmtime() );

my %FIXED_BUGS;

my $STOP_ON_FAIL;
my $SERVER_IMPL = undef;

Expand Down Expand Up @@ -107,8 +105,6 @@

'p|port-range=s' => \(my $PORT_RANGE = "8800:8899"),

'F|fixed=s' => sub { $FIXED_BUGS{$_}++ for split m/,/, $_[1] },

'h|help' => sub { usage(0) },
) or usage(1);

Expand Down Expand Up @@ -175,9 +171,6 @@ sub usage

-p, --port-range START:MAX - pool of TCP ports to allocate from

-F, --fixed BUGS - bug names that are expected to be fixed
(ignores 'bug' declarations with these names)

.
write STDERR;

Expand Down Expand Up @@ -583,10 +576,6 @@ sub _push_test
{
my ( $filename, $multi, $name, %params ) = @_;

# We expect this test to fail if it's declared to be dependent on a bug that
# is not yet fixed
$params{expect_fail}++ if $params{bug} and not $FIXED_BUGS{ $params{bug} };

if( %only_files and not exists $only_files{$filename} ) {
$proven{$_} = PRESUMED for @{ $params{proves} // [] };
return;
Expand Down
5 changes: 3 additions & 2 deletions tests/01http-server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use SyTest::HTTPClient;
use SyTest::HTTPServer::Request;
use SyTest::SSL qw( ensure_ssl_cert );
use SyTest::SSL qw( ensure_ssl_key create_ssl_cert );

my $DIR = dirname( __FILE__ );

Expand Down Expand Up @@ -35,7 +35,8 @@ sub start_test_server_ssl {

my $ssl_cert = "$test_server_dir/server.crt";
my $ssl_key = "$test_server_dir/server.key";
ensure_ssl_cert( $ssl_cert, $ssl_key, $BIND_HOST );
ensure_ssl_key( $ssl_key );
create_ssl_cert( $ssl_cert, $ssl_key, $BIND_HOST );

return $server->listen(
host => $BIND_HOST,
Expand Down
4 changes: 2 additions & 2 deletions tests/10apidoc/01register.pl
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ sub matrix_register_user

return $f->then_done( $user )
->on_done( sub {
log_if_fail "Registered new user $uid";
log_if_fail "Registered new user ". $user->user_id;
});
});
}
Expand Down Expand Up @@ -277,7 +277,7 @@ sub matrix_admin_register_user_via_secret

return Future->done( $user )
->on_done( sub {
log_if_fail "Registered new user (via secret) $uid";
log_if_fail "Registered new user (via secret) " . $user->user_id;
});
});
}
Expand Down
3 changes: 0 additions & 3 deletions tests/30rooms/04messages.pl
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@
requires => [ $senduser_fixture, $remote_fixture, $room_fixture,
qw( can_receive_room_message_locally )],

# this test frequently times out for unknown reasons
bug => "synapse#1679",

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

Expand Down
22 changes: 0 additions & 22 deletions tests/30rooms/12thirdpartyinvite.pl
Original file line number Diff line number Diff line change
Expand Up @@ -366,28 +366,6 @@ sub can_invite_unbound_3pid
})->followed_by( assert_membership( "join" ) );
};

test "Uses consistent guest_access_token across requests",
requires => [ local_user_and_room_fixtures(), local_user_and_room_fixtures(),
$main::HOMESERVER_INFO[1], id_server_fixture() ],

do => sub {
my ( $inviter1, $room1, $inviter2, $room2, $info, $id_server ) = @_;
my $hs_uribase = $info->client_location;

Future->needs_all(
do_3pid_invite( $inviter1, $room1, $id_server->name, $invitee_email ),
do_3pid_invite( $inviter2, $room2, $id_server->name, $invitee_email ),
)->then( sub {
my $invites = $id_server->invites_for( "email", $invitee_email );

log_if_fail "invites", $invites;
assert_eq( scalar( @$invites ), 2, "Invite count" );
assert_eq( $invites->[0]{guest_access_token}, $invites->[1]{guest_access_token}, "guest_access_tokens" );

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

test "3pid invite join with wrong but valid signature are rejected",
requires => [ local_user_fixtures( 2 ), $main::HOMESERVER_INFO[0],
id_server_fixture() ],
Expand Down
2 changes: 0 additions & 2 deletions tests/30rooms/13guestaccess.pl
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,6 @@
test "Guest users can accept invites to private rooms over federation",
requires => [ remote_user_fixture(), guest_user_fixture() ],

bug => "synapse#2065",

do => sub {
my ( $remote_user, $local_guest ) = @_;

Expand Down
67 changes: 0 additions & 67 deletions tests/30rooms/20typing.pl
Original file line number Diff line number Diff line change
Expand Up @@ -133,70 +133,3 @@ sub matrix_typing
} $typinguser, $local_user );
});
};


multi_test "Typing notifications timeout and can be resent",
requires => [ $typing_user_fixture, $room_fixture,
qw( can_set_room_typing )],

timeout => 100,

bug => "DISABLED",

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

die "This test has been disabled due to synapse no longer supporting small typing timeouts.";

my $start_time = time();

flush_events_for( $user )->then( sub {
matrix_typing( $user, $room_id,
typing => 1,
timeout => 10000, # msec; i.e. very long
);
})->then( sub {
pass( "Sent typing notification" );

# start typing
await_event_for( $user, filter => sub {
my ( $event ) = @_;
return unless $event->{type} eq "m.typing";
return unless $event->{room_id} eq $room_id;

return unless scalar @{ $event->{content}{user_ids} };

pass( "Received start notification" );
return 1;
});
})->then( sub {
matrix_typing( $user, $room_id,
typing => 1,
timeout => 100, # msec; i.e. very short
);
})->then( sub {
# stop typing
await_event_for( $user, filter => sub {
my ( $event ) = @_;
return unless $event->{type} eq "m.typing";
return unless $event->{room_id} eq $room_id;

return if scalar @{ $event->{content}{user_ids} };

( time() - $start_time ) < 0.5 or
die "Took too long to time out";

pass( "Received stop notification" );
return 1;
});
})->then( sub {
matrix_typing( $user, $room_id,
typing => 1,
timeout => 10000,
);
})->then( sub {
pass( "Sent second notification" );

Future->done(1);
});
};
2 changes: 0 additions & 2 deletions tests/31sync/15lazy-members.pl
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@
requires => [ local_user_fixtures( 4 ),
qw( can_sync ) ],

bug => "vector-im/riot-web#7211",

check => sub {
my ( $alice, $bob, $charlie, $dave ) = @_;

Expand Down
3 changes: 0 additions & 3 deletions tests/40presence.pl
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@
requires => [ local_user_fixture(),
qw( can_initial_sync )],

# this test fails sometimes. Disable it for now to avoid red-light fatigue.
bug => "synapse#1658",

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

Expand Down
2 changes: 0 additions & 2 deletions tests/41end-to-end-keys/01-upload-key.pl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
test "Should reject keys claiming to belong to a different user",
requires => [ $fixture ],

bug => "synapse#1396",

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

Expand Down
Loading

0 comments on commit 32737e6

Please sign in to comment.