Commit 1caef31d authored by Alvaro Herrera's avatar Alvaro Herrera

Refactor Perl test code

The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql.  This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.

This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object.  The result is quite a bit more
straightforward.

Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.

This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.

I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch.  I tried to avoid this,
but it ended up being more trouble than it's worth.

Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
parent c7485a82
......@@ -4,6 +4,7 @@
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 14;
......
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 13;
my $tempdir = TestLib::tempdir;
program_help_ok('pg_controldata');
program_version_ok('pg_controldata');
program_options_handling_ok('pg_controldata');
command_fails(['pg_controldata'], 'pg_controldata without arguments fails');
command_fails([ 'pg_controldata', 'nonexistent' ],
'pg_controldata with nonexistent directory fails');
standard_initdb "$tempdir/data";
command_like([ 'pg_controldata', "$tempdir/data" ],
my $node = get_new_node();
$node->init;
$node->start;
command_like([ 'pg_controldata', $node->data_dir ],
qr/checkpoint/, 'pg_controldata produces output');
use strict;
use warnings;
use Config;
use PostgresNode;
use TestLib;
use Test::More tests => 17;
......@@ -16,13 +18,11 @@ command_exit_is([ 'pg_ctl', 'start', '-D', "$tempdir/nonexistent" ],
command_ok([ 'pg_ctl', 'initdb', '-D', "$tempdir/data", '-o', '-N' ],
'pg_ctl initdb');
command_ok(
[ $ENV{PG_REGRESS}, '--config-auth',
"$tempdir/data" ],
command_ok([ $ENV{PG_REGRESS}, '--config-auth', "$tempdir/data" ],
'configure authentication');
open CONF, ">>$tempdir/data/postgresql.conf";
print CONF "fsync = off\n";
if (! $windows_os)
if (!$windows_os)
{
print CONF "listen_addresses = ''\n";
print CONF "unix_socket_directories = '$tempdir_short'\n";
......@@ -34,6 +34,7 @@ else
close CONF;
command_ok([ 'pg_ctl', 'start', '-D', "$tempdir/data", '-w' ],
'pg_ctl start -w');
# sleep here is because Windows builds can't check postmaster.pid exactly,
# so they may mistake a pre-existing postmaster.pid for one created by the
# postmaster they start. Waiting more than the 2 seconds slop time allowed
......
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 3;
......@@ -9,14 +11,15 @@ my $tempdir_short = TestLib::tempdir_short;
command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/nonexistent" ],
4, 'pg_ctl status with nonexistent directory');
standard_initdb "$tempdir/data";
my $node = get_new_node();
$node->init;
command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/data" ],
command_exit_is([ 'pg_ctl', 'status', '-D', $node->data_dir ],
3, 'pg_ctl status with server not running');
system_or_bail 'pg_ctl', '-l', "$tempdir/logfile", '-D',
"$tempdir/data", '-w', 'start';
command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/data" ],
$node->data_dir, '-w', 'start';
command_exit_is([ 'pg_ctl', 'status', '-D', $node->data_dir ],
0, 'pg_ctl status with server running');
system_or_bail 'pg_ctl', 'stop', '-D', "$tempdir/data", '-m', 'fast';
system_or_bail 'pg_ctl', 'stop', '-D', $node->data_dir, '-m', 'fast';
This diff is collapsed.
......@@ -17,7 +17,7 @@ sub run_test
RewindTest::setup_cluster();
RewindTest::start_master();
my $test_master_datadir = $RewindTest::test_master_datadir;
my $test_master_datadir = $node_master->data_dir;
# Create a subdir and files that will be present in both
mkdir "$test_master_datadir/tst_both_dir";
......@@ -30,6 +30,7 @@ sub run_test
RewindTest::create_standby();
# Create different subdirs and files in master and standby
my $test_standby_datadir = $node_standby->data_dir;
mkdir "$test_standby_datadir/tst_standby_dir";
append_to_file "$test_standby_datadir/tst_standby_dir/standby_file1",
......
......@@ -23,11 +23,13 @@ sub run_test
{
my $test_mode = shift;
my $master_xlogdir = "$tmp_check/xlog_master";
my $master_xlogdir = "${TestLib::tmp_check}/xlog_master";
rmtree($master_xlogdir);
RewindTest::setup_cluster();
my $test_master_datadir = $node_master->data_dir;
# turn pg_xlog into a symlink
print("moving $test_master_datadir/pg_xlog to $master_xlogdir\n");
move("$test_master_datadir/pg_xlog", $master_xlogdir) or die;
......
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 13;
......@@ -7,20 +9,22 @@ program_help_ok('clusterdb');
program_version_ok('clusterdb');
program_options_handling_ok('clusterdb');
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
issues_sql_like(
[ 'clusterdb', 'postgres' ],
$node->issues_sql_like(
['clusterdb'],
qr/statement: CLUSTER;/,
'SQL CLUSTER run');
command_fails([ 'clusterdb', '-t', 'nonexistent', 'postgres' ],
$node->command_fails([ 'clusterdb', '-t', 'nonexistent' ],
'fails with nonexistent table');
psql 'postgres',
'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a); CLUSTER test1 USING test1x';
issues_sql_like(
[ 'clusterdb', '-t', 'test1', 'postgres' ],
$node->psql('postgres',
'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a); CLUSTER test1 USING test1x'
);
$node->issues_sql_like(
[ 'clusterdb', '-t', 'test1' ],
qr/statement: CLUSTER test1;/,
'cluster specific table');
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 2;
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
# clusterdb -a is not compatible with -d, hence enforce environment variable
# correctly.
$ENV{PGDATABASE} = 'postgres';
issues_sql_like(
$node->issues_sql_like(
[ 'clusterdb', '-a' ],
qr/statement: CLUSTER.*statement: CLUSTER/s,
'cluster all databases');
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 13;
......@@ -7,16 +9,18 @@ program_help_ok('createdb');
program_version_ok('createdb');
program_options_handling_ok('createdb');
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
issues_sql_like(
$node->issues_sql_like(
[ 'createdb', 'foobar1' ],
qr/statement: CREATE DATABASE foobar1/,
'SQL CREATE DATABASE run');
issues_sql_like(
$node->issues_sql_like(
[ 'createdb', '-l', 'C', '-E', 'LATIN1', '-T', 'template0', 'foobar2' ],
qr/statement: CREATE DATABASE foobar2 ENCODING 'LATIN1'/,
'create database with encoding');
command_fails([ 'createdb', 'foobar1' ], 'fails if database already exists');
$node->command_fails([ 'createdb', 'foobar1' ],
'fails if database already exists');
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 14;
......@@ -7,18 +9,17 @@ program_help_ok('createlang');
program_version_ok('createlang');
program_options_handling_ok('createlang');
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
command_fails(
[ 'createlang', 'plpgsql', 'postgres' ],
$node->command_fails([ 'createlang', 'plpgsql' ],
'fails if language already exists');
psql 'postgres', 'DROP EXTENSION plpgsql';
issues_sql_like(
[ 'createlang', 'plpgsql', 'postgres' ],
$node->psql('postgres', 'DROP EXTENSION plpgsql');
$node->issues_sql_like(
[ 'createlang', 'plpgsql' ],
qr/statement: CREATE EXTENSION "plpgsql"/,
'SQL CREATE EXTENSION run');
command_like([ 'createlang', '--list', 'postgres' ],
qr/plpgsql/, 'list output');
$node->command_like([ 'createlang', '--list' ], qr/plpgsql/, 'list output');
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 17;
......@@ -7,24 +9,26 @@ program_help_ok('createuser');
program_version_ok('createuser');
program_options_handling_ok('createuser');
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
issues_sql_like(
$node->issues_sql_like(
[ 'createuser', 'user1' ],
qr/statement: CREATE ROLE user1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;/,
'SQL CREATE USER run');
issues_sql_like(
$node->issues_sql_like(
[ 'createuser', '-L', 'role1' ],
qr/statement: CREATE ROLE role1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT NOLOGIN;/,
'create a non-login role');
issues_sql_like(
$node->issues_sql_like(
[ 'createuser', '-r', 'user2' ],
qr/statement: CREATE ROLE user2 NOSUPERUSER NOCREATEDB CREATEROLE INHERIT LOGIN;/,
'create a CREATEROLE user');
issues_sql_like(
$node->issues_sql_like(
[ 'createuser', '-s', 'user3' ],
qr/statement: CREATE ROLE user3 SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;/,
'create a superuser');
command_fails([ 'createuser', 'user1' ], 'fails if role already exists');
$node->command_fails([ 'createuser', 'user1' ],
'fails if role already exists');
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 11;
......@@ -7,13 +9,15 @@ program_help_ok('dropdb');
program_version_ok('dropdb');
program_options_handling_ok('dropdb');
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
psql 'postgres', 'CREATE DATABASE foobar1';
issues_sql_like(
$node->psql('postgres', 'CREATE DATABASE foobar1');
$node->issues_sql_like(
[ 'dropdb', 'foobar1' ],
qr/statement: DROP DATABASE foobar1/,
'SQL DROP DATABASE run');
command_fails([ 'dropdb', 'nonexistent' ], 'fails with nonexistent database');
$node->command_fails([ 'dropdb', 'nonexistent' ],
'fails with nonexistent database');
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 11;
......@@ -7,14 +9,15 @@ program_help_ok('droplang');
program_version_ok('droplang');
program_options_handling_ok('droplang');
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
issues_sql_like(
$node->issues_sql_like(
[ 'droplang', 'plpgsql', 'postgres' ],
qr/statement: DROP EXTENSION "plpgsql"/,
'SQL DROP EXTENSION run');
command_fails(
$node->command_fails(
[ 'droplang', 'nonexistent', 'postgres' ],
'fails with nonexistent language');
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 11;
......@@ -7,13 +9,15 @@ program_help_ok('dropuser');
program_version_ok('dropuser');
program_options_handling_ok('dropuser');
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
psql 'postgres', 'CREATE ROLE foobar1';
issues_sql_like(
$node->psql('postgres', 'CREATE ROLE foobar1');
$node->issues_sql_like(
[ 'dropuser', 'foobar1' ],
qr/statement: DROP ROLE foobar1/,
'SQL DROP ROLE run');
command_fails([ 'dropuser', 'nonexistent' ], 'fails with nonexistent user');
$node->command_fails([ 'dropuser', 'nonexistent' ],
'fails with nonexistent user');
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 10;
......@@ -9,7 +11,8 @@ program_options_handling_ok('pg_isready');
command_fails(['pg_isready'], 'fails with no server running');
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
command_ok(['pg_isready'], 'succeeds with server running');
$node->command_ok(['pg_isready'], 'succeeds with server running');
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 20;
......@@ -7,35 +9,36 @@ program_help_ok('reindexdb');
program_version_ok('reindexdb');
program_options_handling_ok('reindexdb');
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
$ENV{PGOPTIONS} = '--client-min-messages=WARNING';
issues_sql_like(
$node->issues_sql_like(
[ 'reindexdb', 'postgres' ],
qr/statement: REINDEX DATABASE postgres;/,
'SQL REINDEX run');
psql 'postgres',
'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a);';
issues_sql_like(
$node->psql('postgres',
'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a);');
$node->issues_sql_like(
[ 'reindexdb', '-t', 'test1', 'postgres' ],
qr/statement: REINDEX TABLE test1;/,
'reindex specific table');
issues_sql_like(
$node->issues_sql_like(
[ 'reindexdb', '-i', 'test1x', 'postgres' ],
qr/statement: REINDEX INDEX test1x;/,
'reindex specific index');
issues_sql_like(
$node->issues_sql_like(
[ 'reindexdb', '-S', 'pg_catalog', 'postgres' ],
qr/statement: REINDEX SCHEMA pg_catalog;/,
'reindex specific schema');
issues_sql_like(
$node->issues_sql_like(
[ 'reindexdb', '-s', 'postgres' ],
qr/statement: REINDEX SYSTEM postgres;/,
'reindex system tables');
issues_sql_like(
$node->issues_sql_like(
[ 'reindexdb', '-v', '-t', 'test1', 'postgres' ],
qr/statement: REINDEX \(VERBOSE\) TABLE test1;/,
'reindex with verbose output');
use strict;
use warnings;
use TestLib;
use PostgresNode;
use Test::More tests => 2;
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
$ENV{PGOPTIONS} = '--client-min-messages=WARNING';
issues_sql_like(
$node->issues_sql_like(
[ 'reindexdb', '-a' ],
qr/statement: REINDEX.*statement: REINDEX/s,
'reindex all databases');
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 18;
......@@ -7,26 +9,27 @@ program_help_ok('vacuumdb');
program_version_ok('vacuumdb');
program_options_handling_ok('vacuumdb');
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
issues_sql_like(
$node->issues_sql_like(
[ 'vacuumdb', 'postgres' ],
qr/statement: VACUUM;/,
'SQL VACUUM run');
issues_sql_like(
$node->issues_sql_like(
[ 'vacuumdb', '-f', 'postgres' ],
qr/statement: VACUUM \(FULL\);/,
'vacuumdb -f');
issues_sql_like(
$node->issues_sql_like(
[ 'vacuumdb', '-F', 'postgres' ],
qr/statement: VACUUM \(FREEZE\);/,
'vacuumdb -F');
issues_sql_like(
$node->issues_sql_like(
[ 'vacuumdb', '-z', 'postgres' ],
qr/statement: VACUUM \(ANALYZE\);/,
'vacuumdb -z');
issues_sql_like(
$node->issues_sql_like(
[ 'vacuumdb', '-Z', 'postgres' ],
qr/statement: ANALYZE;/,
'vacuumdb -Z');
use strict;
use warnings;
use TestLib;
use PostgresNode;
use Test::More tests => 2;
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
issues_sql_like(
$node->issues_sql_like(
[ 'vacuumdb', '-a' ],
qr/statement: VACUUM.*statement: VACUUM/s,
'vacuum all databases');
use strict;
use warnings;
use TestLib;
use PostgresNode;
use Test::More tests => 4;
my $tempdir = tempdir;
start_test_server $tempdir;
my $node = get_new_node();
$node->init;
$node->start;
issues_sql_like(
$node->issues_sql_like(
[ 'vacuumdb', '--analyze-in-stages', 'postgres' ],
qr/.*statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0;
.*statement:\ ANALYZE.*
......@@ -16,8 +18,7 @@ qr/.*statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0;
.*statement:\ ANALYZE/sx,
'analyze three times');
issues_sql_like(
$node->issues_sql_like(
[ 'vacuumdb', '--analyze-in-stages', '--all' ],
qr/.*statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0;
.*statement:\ ANALYZE.*
......
This diff is collapsed.
# RecursiveCopy, a simple recursive copy implementation
package RecursiveCopy;
use strict;
use warnings;
use File::Basename;
use File::Copy;
sub copypath
{
my $srcpath = shift;
my $destpath = shift;
die "Cannot operate on symlinks" if -l $srcpath or -l $destpath;
# This source path is a file, simply copy it to destination with the
# same name.
die "Destination path $destpath exists as file" if -f $destpath;
if (-f $srcpath)
{
copy($srcpath, $destpath)
or die "copy $srcpath -> $destpath failed: $!";
return 1;
}
die "Destination needs to be a directory" unless -d $srcpath;
mkdir($destpath) or die "mkdir($destpath) failed: $!";
# Scan existing source directory and recursively copy everything.
opendir(my $directory, $srcpath) or die "could not opendir($srcpath): $!";
while (my $entry = readdir($directory))
{
next if ($entry eq '.' || $entry eq '..');
RecursiveCopy::copypath("$srcpath/$entry", "$destpath/$entry")
or die "copypath $srcpath/$entry -> $destpath/$entry failed";
}
closedir($directory);
return 1;
}
1;
This diff is collapsed.
......@@ -18,6 +18,7 @@ package ServerSetup;
use strict;
use warnings;
use PostgresNode;
use TestLib;
use File::Basename;
use File::Copy;
......@@ -45,17 +46,19 @@ sub copy_files
sub configure_test_server_for_ssl
{
my $tempdir = $_[0];
my $node = $_[0];
my $serverhost = $_[1];
my $pgdata = $node->data_dir;
# Create test users and databases
psql 'postgres', "CREATE USER ssltestuser";
psql 'postgres', "CREATE USER anotheruser";
psql 'postgres', "CREATE DATABASE trustdb";
psql 'postgres', "CREATE DATABASE certdb";
$node->psql('postgres', "CREATE USER ssltestuser");
$node->psql('postgres', "CREATE USER anotheruser");
$node->psql('postgres', "CREATE DATABASE trustdb");
$node->psql('postgres', "CREATE DATABASE certdb");
# enable logging etc.
open CONF, ">>$tempdir/pgdata/postgresql.conf";
open CONF, ">>$pgdata/postgresql.conf";
print CONF "fsync=off\n";
print CONF "log_connections=on\n";
print CONF "log_hostname=on\n";
......@@ -68,17 +71,17 @@ sub configure_test_server_for_ssl
close CONF;
# Copy all server certificates and keys, and client root cert, to the data dir
copy_files("ssl/server-*.crt", "$tempdir/pgdata");
copy_files("ssl/server-*.key", "$tempdir/pgdata");
chmod(0600, glob "$tempdir/pgdata/server-*.key") or die $!;
copy_files("ssl/root+client_ca.crt", "$tempdir/pgdata");
copy_files("ssl/root+client.crl", "$tempdir/pgdata");
copy_files("ssl/server-*.crt", $pgdata);
copy_files("ssl/server-*.key", $pgdata);
chmod(0600, glob "$pgdata/server-*.key") or die $!;
copy_files("ssl/root+client_ca.crt", $pgdata);
copy_files("ssl/root+client.crl", $pgdata);
# Only accept SSL connections from localhost. Our tests don't depend on this
# but seems best to keep it as narrow as possible for security reasons.
#
# When connecting to certdb, also check the client certificate.
open HBA, ">$tempdir/pgdata/pg_hba.conf";
open HBA, ">$pgdata/pg_hba.conf";
print HBA
"# TYPE DATABASE USER ADDRESS METHOD\n";
print HBA
......@@ -96,12 +99,13 @@ sub configure_test_server_for_ssl
# the server so that the configuration takes effect.
sub switch_server_cert
{
my $tempdir = $_[0];
my $node = $_[0];
my $certfile = $_[1];
my $pgdata = $node->data_dir;
diag "Restarting server with certfile \"$certfile\"...";
open SSLCONF, ">$tempdir/pgdata/sslconfig.conf";
open SSLCONF, ">$pgdata/sslconfig.conf";
print SSLCONF "ssl=on\n";
print SSLCONF "ssl_ca_file='root+client_ca.crt'\n";
print SSLCONF "ssl_cert_file='$certfile.crt'\n";
......@@ -110,5 +114,5 @@ sub switch_server_cert
close SSLCONF;
# Stop and restart server to reload the new config.
restart_test_server();
$node->restart;
}
use strict;
use warnings;
use PostgresNode;
use TestLib;
use TestLib;
use Test::More tests => 38;
use ServerSetup;
......@@ -25,8 +27,6 @@ BEGIN
# postgresql-ssl-regression.test.
my $SERVERHOSTADDR = '127.0.0.1';
my $tempdir = TestLib::tempdir;
# Define a couple of helper functions to test connecting to the server.
my $common_connstr;
......@@ -74,10 +74,17 @@ chmod 0600, "ssl/client.key";
#### Part 0. Set up the server.
diag "setting up data directory in \"$tempdir\"...";
start_test_server($tempdir);
configure_test_server_for_ssl($tempdir, $SERVERHOSTADDR);
switch_server_cert($tempdir, 'server-cn-only');
diag "setting up data directory...";
my $node = get_new_node();
$node->init;
# PGHOST is enforced here to set up the node, subsequent connections
# will use a dedicated connection string.
$ENV{PGHOST} = $node->host;
$ENV{PGPORT} = $node->port;
$node->start;
configure_test_server_for_ssl($node, $SERVERHOSTADDR);
switch_server_cert($node, 'server-cn-only');
### Part 1. Run client-side tests.
###
......@@ -150,7 +157,7 @@ test_connect_ok("sslmode=verify-ca host=wronghost.test");
test_connect_fails("sslmode=verify-full host=wronghost.test");
# Test Subject Alternative Names.
switch_server_cert($tempdir, 'server-multiple-alt-names');
switch_server_cert($node, 'server-multiple-alt-names');
diag "test hostname matching with X509 Subject Alternative Names";
$common_connstr =
......@@ -165,7 +172,7 @@ test_connect_fails("host=deep.subdomain.wildcard.pg-ssltest.test");
# Test certificate with a single Subject Alternative Name. (this gives a
# slightly different error message, that's all)
switch_server_cert($tempdir, 'server-single-alt-name');
switch_server_cert($node, 'server-single-alt-name');
diag "test hostname matching with a single X509 Subject Alternative Name";
$common_connstr =
......@@ -178,7 +185,7 @@ test_connect_fails("host=deep.subdomain.wildcard.pg-ssltest.test");
# Test server certificate with a CN and SANs. Per RFCs 2818 and 6125, the CN
# should be ignored when the certificate has both.
switch_server_cert($tempdir, 'server-cn-and-alt-names');
switch_server_cert($node, 'server-cn-and-alt-names');
diag "test certificate with both a CN and SANs";
$common_connstr =
......@@ -190,7 +197,7 @@ test_connect_fails("host=common-name.pg-ssltest.test");
# Finally, test a server certificate that has no CN or SANs. Of course, that's
# not a very sensible certificate, but libpq should handle it gracefully.
switch_server_cert($tempdir, 'server-no-names');
switch_server_cert($node, 'server-no-names');
$common_connstr =
"user=ssltestuser dbname=trustdb sslcert=invalid sslrootcert=ssl/root+server_ca.crt hostaddr=$SERVERHOSTADDR";
......@@ -199,7 +206,7 @@ test_connect_fails("sslmode=verify-full host=common-name.pg-ssltest.test");
# Test that the CRL works
diag "Testing client-side CRL";
switch_server_cert($tempdir, 'server-revoked');
switch_server_cert($node, 'server-revoked');
$common_connstr =
"user=ssltestuser dbname=trustdb sslcert=invalid hostaddr=$SERVERHOSTADDR host=common-name.pg-ssltest.test";
......@@ -233,7 +240,3 @@ test_connect_fails(
test_connect_fails(
"user=ssltestuser sslcert=ssl/client-revoked.crt sslkey=ssl/client-revoked.key"
);
# All done! Save the log, before the temporary installation is deleted
copy("$tempdir/client-log", "./client-log");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment