Skip to content

Commit 9c8791d

Browse files
authored
Use a consistent public baseurl. (#1011)
Ensure the `public_baseurl` setting matches what is queried by sytest.
1 parent 10bf22a commit 9c8791d

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

lib/SyTest/Homeserver.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ sub configure
166166
my %params = @_;
167167

168168
exists $params{$_} and $self->{$_} = delete $params{$_} for qw(
169-
recaptcha_config cas_config smtp_server_config
169+
public_baseurl recaptcha_config cas_config smtp_server_config
170170
app_service_config_files
171171
);
172172

lib/SyTest/Homeserver/Synapse.pm

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ sub start
152152

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

157156
my $macaroon_secret_key = "secret_$port";
158157
my $registration_shared_secret = "reg_secret";
@@ -172,7 +171,7 @@ sub start
172171
my $config_path = $self->{paths}{config} = $self->write_yaml_file( "config.yaml" => {
173172
server_name => $self->server_name,
174173
log_config => $log_config_file,
175-
public_baseurl => "http://${bind_host}:$unsecure_port",
174+
public_baseurl => $self->{public_baseurl},
176175

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

596+
sub public_baseurl
597+
{
598+
my $self = shift;
599+
# run-tests.pl defines whether TLS should be used or not.
600+
my ( $want_tls ) = @_;
601+
return $want_tls ?
602+
"https://$self->{bind_host}:" . $self->secure_port() :
603+
"http://$self->{bind_host}:" . $self->unsecure_port();
604+
}
605+
597606
package SyTest::Homeserver::Synapse::Direct;
598607
use base qw( SyTest::Homeserver::Synapse );
599608

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

1120+
sub public_baseurl
1121+
{
1122+
my $self = shift;
1123+
return "https://$self->{bind_host}:" . $self->secure_port();
1124+
}
1125+
11111126
sub start
11121127
{
11131128
my $self = shift;

tests/05homeserver.pl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,17 @@
5353

5454
my $api_host = $server->http_api_host;
5555

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

6058
$server->configure(
6159
smtp_server_config => $mail_server_info,
6260
);
6361

6462
$server->configure(
63+
# Annoyingly we ask the homeserver object for public_baseurl and then
64+
# pass it back into the configuration since this is the only location
65+
# we have $WANT_TLS.
66+
public_baseurl => $location,
6567
# Config for testing recaptcha. 90jira/SYT-8.pl
6668
recaptcha_config => {
6769
siteverify_api => $test_server_info->client_location .
@@ -70,7 +72,6 @@
7072
private_key => "sytest_recaptcha_private_key",
7173
}, cas_config => {
7274
server_url => $test_server_info->client_location . "/cas",
73-
service_url => $location,
7475
},
7576
);
7677

0 commit comments

Comments
 (0)