From 033dc315304c07af7d69857f13fd8f787562a074 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Wed, 3 Jul 2019 10:41:41 +0100 Subject: [PATCH 01/10] uri_escape key_id on /key/v2/server endpoint (#635) It was possible for `$key_id` to have a `/` in it, which caused some homeservers to not path-match correctly (and rightly so). Make sure we URL encode before sending to the server. (This worked on Synapse because the keyID in this endpoint is actually deprecated and Synapse ignores it entirely). --- lib/SyTest/Federation/Client.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/SyTest/Federation/Client.pm b/lib/SyTest/Federation/Client.pm index e71c5a354..6f670ced8 100644 --- a/lib/SyTest/Federation/Client.pm +++ b/lib/SyTest/Federation/Client.pm @@ -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; @@ -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 ) = @_; From 1a5c6c65c95e7343a02fd1f27a7f11effb09eb38 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Wed, 3 Jul 2019 14:58:32 +0100 Subject: [PATCH 02/10] Remove disabled test (#637) This test has been disabled for 4 years and doesn't have a need to exist anymore. --- tests/30rooms/20typing.pl | 67 --------------------------------------- 1 file changed, 67 deletions(-) diff --git a/tests/30rooms/20typing.pl b/tests/30rooms/20typing.pl index 64bad82bb..27b49eaa3 100644 --- a/tests/30rooms/20typing.pl +++ b/tests/30rooms/20typing.pl @@ -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); - }); - }; From dbe85e380de575a8d9a4f0f27a540bff0780f444 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Thu, 4 Jul 2019 13:58:18 +0100 Subject: [PATCH 03/10] Remove "bug" & "fixed" parameters, and reimplement functionality with a blacklist (#638) Sytest has a feature that allows you to mark a test as expected fail, along with a bug ID with the reasoning for it. This is nice, but really only works in the context of a single homeserver, where tests were being disabled for everyone because something didn't work in Synapse. Since homeserver-specific test white/blacklist was added, we can recreate the functionality of the bug parameter using a blacklist instead. This PR pairs with matrix-org/synapse#5611 --- docker/synapse_sytest.sh | 2 +- run-tests.pl | 11 ----------- tests/30rooms/04messages.pl | 3 --- tests/30rooms/13guestaccess.pl | 2 -- tests/31sync/15lazy-members.pl | 2 -- tests/40presence.pl | 3 --- tests/41end-to-end-keys/01-upload-key.pl | 2 -- tests/52user-directory/01public.pl | 6 ------ tests/61push/07_set_enabled.pl | 2 -- tests/90jira/SYN-115.pl | 4 ---- 10 files changed, 1 insertion(+), 36 deletions(-) diff --git a/docker/synapse_sytest.sh b/docker/synapse_sytest.sh index 21be810b5..8941e6b32 100755 --- a/docker/synapse_sytest.sh +++ b/docker/synapse_sytest.sh @@ -82,7 +82,7 @@ fi >&2 echo "+++ Running tests" RUN_TESTS=( - perl -I "$SYTEST_LIB" ./run-tests.pl --python=/venv/bin/python --synapse-directory=/src --coverage -O tap --all + perl -I "$SYTEST_LIB" ./run-tests.pl --python=/venv/bin/python --synapse-directory=/src -B /src/sytest-blacklist --coverage -O tap --all ) TEST_STATUS=0 diff --git a/run-tests.pl b/run-tests.pl index ec15c4801..ee1ccf1f2 100755 --- a/run-tests.pl +++ b/run-tests.pl @@ -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; @@ -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); @@ -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; @@ -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; diff --git a/tests/30rooms/04messages.pl b/tests/30rooms/04messages.pl index 3e2f37850..4e5ea04c8 100644 --- a/tests/30rooms/04messages.pl +++ b/tests/30rooms/04messages.pl @@ -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 ) = @_; diff --git a/tests/30rooms/13guestaccess.pl b/tests/30rooms/13guestaccess.pl index 0a7704299..fbecb9486 100644 --- a/tests/30rooms/13guestaccess.pl +++ b/tests/30rooms/13guestaccess.pl @@ -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 ) = @_; diff --git a/tests/31sync/15lazy-members.pl b/tests/31sync/15lazy-members.pl index 5844063e4..ec1145c97 100644 --- a/tests/31sync/15lazy-members.pl +++ b/tests/31sync/15lazy-members.pl @@ -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 ) = @_; diff --git a/tests/40presence.pl b/tests/40presence.pl index f1f165c66..d19dfc46a 100644 --- a/tests/40presence.pl +++ b/tests/40presence.pl @@ -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 ) = @_; diff --git a/tests/41end-to-end-keys/01-upload-key.pl b/tests/41end-to-end-keys/01-upload-key.pl index c7460db3b..0efb5f7d1 100644 --- a/tests/41end-to-end-keys/01-upload-key.pl +++ b/tests/41end-to-end-keys/01-upload-key.pl @@ -38,8 +38,6 @@ test "Should reject keys claiming to belong to a different user", requires => [ $fixture ], - bug => "synapse#1396", - do => sub { my ( $user ) = @_; diff --git a/tests/52user-directory/01public.pl b/tests/52user-directory/01public.pl index 588264747..584304bb6 100644 --- a/tests/52user-directory/01public.pl +++ b/tests/52user-directory/01public.pl @@ -151,9 +151,6 @@ multi_test "Users appear/disappear from directory when $type are changed", requires => [ local_user_fixtures( 2 ) ], - # this test is currently flaky due to a synapse bug - bug => "synapse#2306", - check => sub { my ( $creator, $user ) = @_; @@ -249,9 +246,6 @@ multi_test "Users stay in directory when join_rules are changed but history_visibility is world_readable", requires => [ local_user_fixtures( 2 ) ], - # this test is currently flaky due to a synapse bug - bug => "synapse#2306", - check => sub { my ( $creator, $user ) = @_; diff --git a/tests/61push/07_set_enabled.pl b/tests/61push/07_set_enabled.pl index ef35d55da..c5916f31f 100644 --- a/tests/61push/07_set_enabled.pl +++ b/tests/61push/07_set_enabled.pl @@ -60,8 +60,6 @@ sub check_enable_disable_rule { test "Enabling an unknown default rule fails with 404", requires => [ local_user_fixture() ], - bug => "SYN-676", - check => sub { my ( $user ) = @_; matrix_set_push_rule_enabled( diff --git a/tests/90jira/SYN-115.pl b/tests/90jira/SYN-115.pl index 029d3ae21..28a639500 100644 --- a/tests/90jira/SYN-115.pl +++ b/tests/90jira/SYN-115.pl @@ -4,10 +4,6 @@ requires => [ local_user_fixture(), remote_user_fixture( with_events => 1 ), qw( can_create_private_room )], - # this test fails intermittently on dendron-fronted builds, for unknown - # reasons. - bug => 'synapse#1663', - do => sub { my ( $alice, $bob ) = @_; From b1f59ca03544fff9a2346b2860b84947e8052615 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Fri, 5 Jul 2019 11:09:47 +0100 Subject: [PATCH 04/10] Improve diagnostics for some flaky tests (#641) --- tests/10apidoc/01register.pl | 4 ++-- tests/41end-to-end-keys/06-device-lists.pl | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/10apidoc/01register.pl b/tests/10apidoc/01register.pl index 7b92896f6..e5d3fe42b 100644 --- a/tests/10apidoc/01register.pl +++ b/tests/10apidoc/01register.pl @@ -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; }); }); } @@ -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; }); }); } diff --git a/tests/41end-to-end-keys/06-device-lists.pl b/tests/41end-to-end-keys/06-device-lists.pl index 4c43cfd6e..86c6a14be 100644 --- a/tests/41end-to-end-keys/06-device-lists.pl +++ b/tests/41end-to-end-keys/06-device-lists.pl @@ -25,7 +25,7 @@ sub sync_until_user_in_device_list # my $trace = Devel::StackTrace->new(no_args => 1); # log_if_fail $trace->frame(1)->as_string(); - $msg = "$msg: waiting for $wait_for_id in $device_list"; + log_if_fail "$msg: waiting for $wait_for_id in $device_list"; return repeat_until_true { matrix_sync_again( $syncing_user, timeout => 1000 ) @@ -34,11 +34,15 @@ sub sync_until_user_in_device_list log_if_fail "$msg: body", $body; - my $res = $body->{device_lists} && + if( + $body->{device_lists} && $body->{device_lists}{$device_list} && - any { $_ eq $wait_for_id } @{ $body->{device_lists}{$device_list} }; - - Future->done( $res && $body ); + any { $_ eq $wait_for_id } @{ $body->{device_lists}{$device_list} } + ) { + log_if_fail "$msg: found $wait_for_id in $device_list"; + return Future->done( $body ); + } + return Future->done(0); }); }; } @@ -371,14 +375,18 @@ sub sync_until_user_in_device_list })->then( sub { matrix_set_device_display_name( $remote_leaver, $remote_leaver->device_id, "test display name" ), })->then( sub { + log_if_fail "Remote_leaver " . $remote_leaver->user_id . " set display name"; sync_until_user_in_device_list( $creator, $remote_leaver ); })->then( sub { matrix_leave_room_synced( $remote_leaver, $room_id ) })->then( sub { + log_if_fail "Remote_leaver " . $remote_leaver->user_id . " left room"; matrix_put_e2e_keys( $remote_leaver, device_keys => { updated => "keys" } ) })->then( sub { + log_if_fail "Remote_leaver " . $remote_leaver->user_id . " updated keys"; matrix_put_e2e_keys( $remote2, device_keys => { updated => "keys" } ) })->then( sub { + log_if_fail "Remote user 2 " . $remote2->user_id . " updated keys"; sync_until_user_in_device_list( $creator, $remote2 ); })->then( sub { my ( $body ) = @_; From 43e6847c4d9be4669d79d9f58b912a70fbfa1e94 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Fri, 5 Jul 2019 11:10:05 +0100 Subject: [PATCH 05/10] Increase synapse's federation ratelimit (#640) We hit 10 requests per second pretty quickly and then our requests start getting tarpitted and the tests time out. Let's increase the limit. --- lib/SyTest/Homeserver/Synapse.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/SyTest/Homeserver/Synapse.pm b/lib/SyTest/Homeserver/Synapse.pm index 513721fa2..d1bbbf931 100644 --- a/lib/SyTest/Homeserver/Synapse.pm +++ b/lib/SyTest/Homeserver/Synapse.pm @@ -191,6 +191,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, From 9fd4fd2be95260de2379622bd7a9c70ebabb6544 Mon Sep 17 00:00:00 2001 From: Alex Chen Date: Fri, 5 Jul 2019 19:16:34 +0800 Subject: [PATCH 06/10] Remove check for obsolete json key prev_state (#642) The prev_state key isn't mentioned at all in the spec. If merged, this PR should obsolete matrix-org/gomatrixserverlib#95 and matrix-org/dendrite#526. Signed-off-by: Alex Chen minecnly@gmail.com --- tests/50federation/30room-join.pl | 9 +++------ tests/50federation/35room-invite.pl | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/50federation/30room-join.pl b/tests/50federation/30room-join.pl index c59154018..a6bc56b9a 100644 --- a/tests/50federation/30room-join.pl +++ b/tests/50federation/30room-join.pl @@ -39,14 +39,11 @@ sub assert_is_valid_pdu { # for event types which are known to be state events, check that they # have the relevant keys if ( $STATE_EVENT_TYPES{ $event->{type} }) { - # XXX richvdh: I'm unconvinced prev_state is required here - I think - # it's deprecated. It's certainly not mentioned in the spec. assert_json_keys( $event, qw( - state_key prev_state + state_key )); assert_json_string( $event->{state_key} ); - assert_json_list( $event->{prev_state} ); } # TODO: Check signatures and hashes @@ -233,7 +230,7 @@ sub assert_is_valid_pdu { my $protoevent = $body->{event}; assert_json_keys( $protoevent, qw( - auth_events content depth prev_state room_id sender state_key type + auth_events content depth room_id sender state_key type )); assert_json_nonempty_list( my $auth_events = $protoevent->{auth_events} ); @@ -265,7 +262,7 @@ sub assert_is_valid_pdu { my %event = ( ( map { $_ => $protoevent->{$_} } qw( - auth_events content depth prev_events prev_state room_id sender + auth_events content depth prev_events room_id sender state_key type ) ), event_id => $datastore->next_event_id, diff --git a/tests/50federation/35room-invite.pl b/tests/50federation/35room-invite.pl index 78854cd3b..f17f87abc 100644 --- a/tests/50federation/35room-invite.pl +++ b/tests/50federation/35room-invite.pl @@ -27,7 +27,7 @@ assert_eq( $body->{sender}, $user->user_id, 'event sender' ); - assert_json_keys( $body, qw( content state_key prev_state )); + assert_json_keys( $body, qw( content state_key )); assert_eq( $body->{content}{membership}, "invite", 'event content membership' ); From 3852b33f9ca058e2ff952523a7647a95a318846a Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Fri, 5 Jul 2019 16:47:48 +0100 Subject: [PATCH 07/10] Remove test which relies on guest 3pid tokens (#643) --- lib/SyTest/Homeserver/Synapse.pm | 1 - tests/30rooms/12thirdpartyinvite.pl | 22 ---------------------- 2 files changed, 23 deletions(-) diff --git a/lib/SyTest/Homeserver/Synapse.pm b/lib/SyTest/Homeserver/Synapse.pm index d1bbbf931..cd653a6cf 100644 --- a/lib/SyTest/Homeserver/Synapse.pm +++ b/lib/SyTest/Homeserver/Synapse.pm @@ -208,7 +208,6 @@ sub start use_frozen_events => "true", allow_guest_access => "True", - invite_3pid_guest => "true", # Metrics are always useful enable_metrics => 1, diff --git a/tests/30rooms/12thirdpartyinvite.pl b/tests/30rooms/12thirdpartyinvite.pl index d580bb05a..421a5c7cb 100644 --- a/tests/30rooms/12thirdpartyinvite.pl +++ b/tests/30rooms/12thirdpartyinvite.pl @@ -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() ], From 16d1241e0b73d20c56f8c98a30db76cec1479415 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Mon, 8 Jul 2019 12:16:42 +0100 Subject: [PATCH 08/10] Create new SSL certs for each run (#644) Fixes a problem where the sytests would suddenly start failing because they were still using the certs taht we generated a month ago. --- lib/SyTest/Homeserver/Synapse.pm | 5 +-- lib/SyTest/SSL.pm | 55 +++++++++++++++++++------------- tests/01http-server.pl | 5 +-- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/lib/SyTest/Homeserver/Synapse.pm b/lib/SyTest/Homeserver/Synapse.pm index cd653a6cf..0cd260f5e 100644 --- a/lib/SyTest/Homeserver/Synapse.pm +++ b/lib/SyTest/Homeserver/Synapse.pm @@ -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 { @@ -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, diff --git a/lib/SyTest/SSL.pm b/lib/SyTest/SSL.pm index da4339086..1d67a7152 100644 --- a/lib/SyTest/SSL.pm +++ b/lib/SyTest/SSL.pm @@ -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 $?"; } diff --git a/tests/01http-server.pl b/tests/01http-server.pl index d5fb80648..8edd4d490 100644 --- a/tests/01http-server.pl +++ b/tests/01http-server.pl @@ -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__ ); @@ -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, From da31f915951bf6356e2f1759ead0c5179dd7a7c5 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 8 Jul 2019 14:57:55 +0100 Subject: [PATCH 09/10] Use JSON for /store-invite requests --- lib/SyTest/Identity/Server.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/SyTest/Identity/Server.pm b/lib/SyTest/Identity/Server.pm index 4fe8a9687..91733983b 100644 --- a/lib/SyTest/Identity/Server.pm +++ b/lib/SyTest/Identity/Server.pm @@ -141,7 +141,7 @@ sub on_request $req->respond_json( \%resp ); } elsif ( $path eq "/_matrix/identity/api/v1/3pid/bind" ) { - my $body = $req->body_from_form; + my $body = $req->body_from_json; my $sid = $body->{sid}; my $mxid = $body->{mxid}; From 5c06d9644c1d22a106dc9dcc2e15e01deee235c7 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 8 Jul 2019 15:13:29 +0100 Subject: [PATCH 10/10] Atom y u no save --- lib/SyTest/Identity/Server.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/SyTest/Identity/Server.pm b/lib/SyTest/Identity/Server.pm index 91733983b..2300689d7 100644 --- a/lib/SyTest/Identity/Server.pm +++ b/lib/SyTest/Identity/Server.pm @@ -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}; @@ -141,7 +141,7 @@ sub on_request $req->respond_json( \%resp ); } elsif ( $path eq "/_matrix/identity/api/v1/3pid/bind" ) { - my $body = $req->body_from_json; + my $body = $req->body_from_form; my $sid = $body->{sid}; my $mxid = $body->{mxid};