Extend configure_test_server_for_ssl to add extensions
authorDaniel Gustafsson <dgustafsson@postgresql.org>
Tue, 30 Nov 2021 10:13:26 +0000 (11:13 +0100)
committerDaniel Gustafsson <dgustafsson@postgresql.org>
Tue, 30 Nov 2021 10:13:26 +0000 (11:13 +0100)
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

src/test/ssl/t/002_scram.pl
src/test/ssl/t/SSLServer.pm

index 983554263fb6a3138dc2387d2c651ec128381bcc..88803ee5c5f00699699dc866b8fe4ffe1d64082b 100644 (file)
@@ -49,7 +49,7 @@ $node->start;
 
 # Configure server for SSL connections, with password handling.
 configure_test_server_for_ssl($node, $SERVERHOSTADDR, $SERVERHOSTCIDR,
-       "scram-sha-256", "pass", "scram-sha-256");
+       "scram-sha-256", 'password' => "pass", 'password_enc' => "scram-sha-256");
 switch_server_cert($node, 'server-cn-only');
 $ENV{PGPASSWORD} = "pass";
 $common_connstr =
index c5999e0b3331f3dd89e58318b15cbb5210ed1042..3d7ff40b97b6ec7e95680e5829fbd5a615ee4879 100644 (file)
@@ -62,38 +62,52 @@ sub copy_files
 # servercidr: what to put in pg_hba.conf, e.g. '127.0.0.1/32'
 sub configure_test_server_for_ssl
 {
-       my ($node, $serverhost, $servercidr, $authmethod, $password,
-               $password_enc) = @_;
-
+       my ($node, $serverhost, $servercidr, $authmethod, %params) = @_;
        my $pgdata = $node->data_dir;
 
+       my @databases = ( 'trustdb', 'certdb', 'certdb_dn', 'certdb_dn_re', 'certdb_cn', 'verifydb' );
+
        # Create test users and databases
        $node->psql('postgres', "CREATE USER ssltestuser");
        $node->psql('postgres', "CREATE USER md5testuser");
        $node->psql('postgres', "CREATE USER anotheruser");
        $node->psql('postgres', "CREATE USER yetanotheruser");
-       $node->psql('postgres', "CREATE DATABASE trustdb");
-       $node->psql('postgres', "CREATE DATABASE certdb");
-       $node->psql('postgres', "CREATE DATABASE certdb_dn");
-       $node->psql('postgres', "CREATE DATABASE certdb_dn_re");
-       $node->psql('postgres', "CREATE DATABASE certdb_cn");
-       $node->psql('postgres', "CREATE DATABASE verifydb");
+
+       foreach my $db (@databases)
+       {
+               $node->psql('postgres', "CREATE DATABASE $db");
+       }
 
        # Update password of each user as needed.
-       if (defined($password))
+       if (defined($params{password}))
        {
+               die "Password encryption must be specified when password is set"
+                       unless defined($params{password_enc});
+
                $node->psql('postgres',
-                       "SET password_encryption='$password_enc'; ALTER USER ssltestuser PASSWORD '$password';"
+                       "SET password_encryption='$params{password_enc}'; ALTER USER ssltestuser PASSWORD '$params{password}';"
                );
                # A special user that always has an md5-encrypted password
                $node->psql('postgres',
-                       "SET password_encryption='md5'; ALTER USER md5testuser PASSWORD '$password';"
+                       "SET password_encryption='md5'; ALTER USER md5testuser PASSWORD '$params{password}';"
                );
                $node->psql('postgres',
-                       "SET password_encryption='$password_enc'; ALTER USER anotheruser PASSWORD '$password';"
+                       "SET password_encryption='$params{password_enc}'; ALTER USER anotheruser PASSWORD '$params{password}';"
                );
        }
 
+       # Create any extensions requested in the setup
+       if (defined($params{extensions}))
+       {
+               foreach my $extension (@{$params{extensions}})
+               {
+                       foreach my $db (@databases)
+                       {
+                               $node->psql($db, "CREATE EXTENSION $extension CASCADE;");
+                       }
+               }
+       }
+
        # enable logging etc.
        open my $conf, '>>', "$pgdata/postgresql.conf";
        print $conf "fsync=off\n";