Skip to content

Commit

Permalink
Use a consistent public baseurl. (#1011)
Browse files Browse the repository at this point in the history
Ensure the `public_baseurl` setting matches what is queried by sytest.
  • Loading branch information
clokep authored Feb 11, 2021
1 parent 10bf22a commit 9c8791d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/SyTest/Homeserver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ sub configure
my %params = @_;

exists $params{$_} and $self->{$_} = delete $params{$_} for qw(
recaptcha_config cas_config smtp_server_config
public_baseurl recaptcha_config cas_config smtp_server_config
app_service_config_files
);

Expand Down
19 changes: 17 additions & 2 deletions lib/SyTest/Homeserver/Synapse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ sub start

my $listeners = [ $self->generate_listeners ];
my $bind_host = $self->{bind_host};
my $unsecure_port = $self->{ports}{synapse_unsecure};

my $macaroon_secret_key = "secret_$port";
my $registration_shared_secret = "reg_secret";
Expand All @@ -172,7 +171,7 @@ sub start
my $config_path = $self->{paths}{config} = $self->write_yaml_file( "config.yaml" => {
server_name => $self->server_name,
log_config => $log_config_file,
public_baseurl => "http://${bind_host}:$unsecure_port",
public_baseurl => $self->{public_baseurl},

# We configure synapse to use a TLS cert which is signed by our dummy CA...
tls_certificate_path => $self->{paths}{cert_file},
Expand Down Expand Up @@ -594,6 +593,16 @@ sub unsecure_port
return $self->{ports}{synapse_unsecure};
}

sub public_baseurl
{
my $self = shift;
# run-tests.pl defines whether TLS should be used or not.
my ( $want_tls ) = @_;
return $want_tls ?
"https://$self->{bind_host}:" . $self->secure_port() :
"http://$self->{bind_host}:" . $self->unsecure_port();
}

package SyTest::Homeserver::Synapse::Direct;
use base qw( SyTest::Homeserver::Synapse );

Expand Down Expand Up @@ -1108,6 +1117,12 @@ sub unsecure_port
die "haproxy does not have an unsecure port mode\n";
}

sub public_baseurl
{
my $self = shift;
return "https://$self->{bind_host}:" . $self->secure_port();
}

sub start
{
my $self = shift;
Expand Down
9 changes: 5 additions & 4 deletions tests/05homeserver.pl
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@

my $api_host = $server->http_api_host;

my $location = $WANT_TLS ?
"https://$api_host:" . $server->secure_port :
"http://$api_host:" . $server->unsecure_port;
my $location = $server->public_baseurl($WANT_TLS);

$server->configure(
smtp_server_config => $mail_server_info,
);

$server->configure(
# Annoyingly we ask the homeserver object for public_baseurl and then
# pass it back into the configuration since this is the only location
# we have $WANT_TLS.
public_baseurl => $location,
# Config for testing recaptcha. 90jira/SYT-8.pl
recaptcha_config => {
siteverify_api => $test_server_info->client_location .
Expand All @@ -70,7 +72,6 @@
private_key => "sytest_recaptcha_private_key",
}, cas_config => {
server_url => $test_server_info->client_location . "/cas",
service_url => $location,
},
);

Expand Down

0 comments on commit 9c8791d

Please sign in to comment.