Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 879fc1a

Browse files
committedNov 30, 2021
Extend configure_test_server_for_ssl to add extensions
In order to be able to test extensions with SSL connections, allow configure_test_server_for_ssl to create any extensions passed as an array. Each extension is created in all the test databases. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Andrew Dunstan <andrew@dunslane.net> Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> Discussion: https://postgr.es/m/E23F9811-0C77-45DA-912F-D809AB140741@yesql.se
1 parent be54551 commit 879fc1a

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed
 

‎src/test/ssl/t/002_scram.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
# Configure server for SSL connections, with password handling.
5151
configure_test_server_for_ssl($node, $SERVERHOSTADDR, $SERVERHOSTCIDR,
52-
"scram-sha-256", "pass", "scram-sha-256");
52+
"scram-sha-256", 'password' => "pass", 'password_enc' => "scram-sha-256");
5353
switch_server_cert($node, 'server-cn-only');
5454
$ENV{PGPASSWORD} = "pass";
5555
$common_connstr =

‎src/test/ssl/t/SSLServer.pm

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,38 +62,52 @@ sub copy_files
6262
# servercidr: what to put in pg_hba.conf, e.g. '127.0.0.1/32'
6363
sub configure_test_server_for_ssl
6464
{
65-
my ($node, $serverhost, $servercidr, $authmethod, $password,
66-
$password_enc) = @_;
67-
65+
my ($node, $serverhost, $servercidr, $authmethod, %params) = @_;
6866
my $pgdata = $node->data_dir;
6967

68+
my @databases = ( 'trustdb', 'certdb', 'certdb_dn', 'certdb_dn_re', 'certdb_cn', 'verifydb' );
69+
7070
# Create test users and databases
7171
$node->psql('postgres', "CREATE USER ssltestuser");
7272
$node->psql('postgres', "CREATE USER md5testuser");
7373
$node->psql('postgres', "CREATE USER anotheruser");
7474
$node->psql('postgres', "CREATE USER yetanotheruser");
75-
$node->psql('postgres', "CREATE DATABASE trustdb");
76-
$node->psql('postgres', "CREATE DATABASE certdb");
77-
$node->psql('postgres', "CREATE DATABASE certdb_dn");
78-
$node->psql('postgres', "CREATE DATABASE certdb_dn_re");
79-
$node->psql('postgres', "CREATE DATABASE certdb_cn");
80-
$node->psql('postgres', "CREATE DATABASE verifydb");
75+
76+
foreach my $db (@databases)
77+
{
78+
$node->psql('postgres', "CREATE DATABASE $db");
79+
}
8180

8281
# Update password of each user as needed.
83-
if (defined($password))
82+
if (defined($params{password}))
8483
{
84+
die "Password encryption must be specified when password is set"
85+
unless defined($params{password_enc});
86+
8587
$node->psql('postgres',
86-
"SET password_encryption='$password_enc'; ALTER USER ssltestuser PASSWORD '$password';"
88+
"SET password_encryption='$params{password_enc}'; ALTER USER ssltestuser PASSWORD '$params{password}';"
8789
);
8890
# A special user that always has an md5-encrypted password
8991
$node->psql('postgres',
90-
"SET password_encryption='md5'; ALTER USER md5testuser PASSWORD '$password';"
92+
"SET password_encryption='md5'; ALTER USER md5testuser PASSWORD '$params{password}';"
9193
);
9294
$node->psql('postgres',
93-
"SET password_encryption='$password_enc'; ALTER USER anotheruser PASSWORD '$password';"
95+
"SET password_encryption='$params{password_enc}'; ALTER USER anotheruser PASSWORD '$params{password}';"
9496
);
9597
}
9698

99+
# Create any extensions requested in the setup
100+
if (defined($params{extensions}))
101+
{
102+
foreach my $extension (@{$params{extensions}})
103+
{
104+
foreach my $db (@databases)
105+
{
106+
$node->psql($db, "CREATE EXTENSION $extension CASCADE;");
107+
}
108+
}
109+
}
110+
97111
# enable logging etc.
98112
open my $conf, '>>', "$pgdata/postgresql.conf";
99113
print $conf "fsync=off\n";

0 commit comments

Comments
 (0)
Failed to load comments.