aboutsummaryrefslogtreecommitdiff
path: root/src/bin/scripts
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2016-08-04 14:44:23 -0400
committerPeter Eisentraut <peter_e@gmx.net>2016-09-22 12:00:00 -0400
commit8b845520fb0aa50fea7aae44a45cee1b6d87845d (patch)
tree92ccc8596edadb6fb529c9b1c9872451e5e185df /src/bin/scripts
parente7010ce4794a4c12a6a8bfb0ca1de49b61046847 (diff)
downloadpostgresql-8b845520fb0aa50fea7aae44a45cee1b6d87845d.tar.gz
postgresql-8b845520fb0aa50fea7aae44a45cee1b6d87845d.zip
Add tests for various connection string issues
Add tests for consistent support of connection strings in frontend programs as well as proper handling of unusual characters in database and user names. These tests were developed for the issues of CVE-2016-5424. To allow testing of names with spaces, change the pg_regress command-line options --create-role and --dbname to split their arguments by comma only, not space or comma as before. Only commas were actually used in existing uses. Noah Misch, Michael Paquier, Peter Eisentraut
Diffstat (limited to 'src/bin/scripts')
-rw-r--r--src/bin/scripts/t/010_clusterdb.pl5
-rw-r--r--src/bin/scripts/t/090_reindexdb.pl9
-rw-r--r--src/bin/scripts/t/100_vacuumdb.pl4
-rw-r--r--src/bin/scripts/t/200_connstr.pl38
4 files changed, 53 insertions, 3 deletions
diff --git a/src/bin/scripts/t/010_clusterdb.pl b/src/bin/scripts/t/010_clusterdb.pl
index 0e677cacf18..f3de9c016ce 100644
--- a/src/bin/scripts/t/010_clusterdb.pl
+++ b/src/bin/scripts/t/010_clusterdb.pl
@@ -3,7 +3,7 @@ use warnings;
use PostgresNode;
use TestLib;
-use Test::More tests => 13;
+use Test::More tests => 14;
program_help_ok('clusterdb');
program_version_ok('clusterdb');
@@ -28,3 +28,6 @@ $node->issues_sql_like(
[ 'clusterdb', '-t', 'test1' ],
qr/statement: CLUSTER test1;/,
'cluster specific table');
+
+$node->command_ok([qw(clusterdb --echo --verbose dbname=template1)],
+ 'clusterdb with connection string');
diff --git a/src/bin/scripts/t/090_reindexdb.pl b/src/bin/scripts/t/090_reindexdb.pl
index d92896f34f6..42d6fb4eb45 100644
--- a/src/bin/scripts/t/090_reindexdb.pl
+++ b/src/bin/scripts/t/090_reindexdb.pl
@@ -3,7 +3,7 @@ use warnings;
use PostgresNode;
use TestLib;
-use Test::More tests => 20;
+use Test::More tests => 23;
program_help_ok('reindexdb');
program_version_ok('reindexdb');
@@ -42,3 +42,10 @@ $node->issues_sql_like(
[ 'reindexdb', '-v', '-t', 'test1', 'postgres' ],
qr/statement: REINDEX \(VERBOSE\) TABLE test1;/,
'reindex with verbose output');
+
+$node->command_ok([qw(reindexdb --echo --table=pg_am dbname=template1)],
+ 'reindexdb table with connection string');
+$node->command_ok([qw(reindexdb --echo dbname=template1)],
+ 'reindexdb database with connection string');
+$node->command_ok([qw(reindexdb --echo --system dbname=template1)],
+ 'reindexdb system with connection string');
diff --git a/src/bin/scripts/t/100_vacuumdb.pl b/src/bin/scripts/t/100_vacuumdb.pl
index c183ccb6a19..07c6e9e7ce1 100644
--- a/src/bin/scripts/t/100_vacuumdb.pl
+++ b/src/bin/scripts/t/100_vacuumdb.pl
@@ -3,7 +3,7 @@ use warnings;
use PostgresNode;
use TestLib;
-use Test::More tests => 18;
+use Test::More tests => 19;
program_help_ok('vacuumdb');
program_version_ok('vacuumdb');
@@ -33,3 +33,5 @@ $node->issues_sql_like(
[ 'vacuumdb', '-Z', 'postgres' ],
qr/statement: ANALYZE;/,
'vacuumdb -Z');
+$node->command_ok([qw(vacuumdb -Z --table=pg_am dbname=template1)],
+ 'vacuumdb with connection string');
diff --git a/src/bin/scripts/t/200_connstr.pl b/src/bin/scripts/t/200_connstr.pl
new file mode 100644
index 00000000000..89945712d29
--- /dev/null
+++ b/src/bin/scripts/t/200_connstr.pl
@@ -0,0 +1,38 @@
+use strict;
+use warnings;
+
+use PostgresNode;
+use TestLib;
+use Test::More tests => 3;
+
+# Tests to check connection string handling in utilities
+
+# In a SQL_ASCII database, pgwin32_message_to_UTF16() needs to
+# interpret everything as UTF8. We're going to use byte sequences
+# that aren't valid UTF-8 strings, so that would fail. Use LATIN1,
+# which accepts any byte and has a conversion from each byte to UTF-8.
+$ENV{LC_ALL} = 'C';
+$ENV{PGCLIENTENCODING} = 'LATIN1';
+
+# Create database names covering the range of LATIN1 characters and
+# run the utilities' --all options over them.
+my $dbname1 = generate_ascii_string(1, 63); # contains '='
+my $dbname2 = generate_ascii_string(67, 129); # skip 64-66 to keep length to 62
+my $dbname3 = generate_ascii_string(130, 192);
+my $dbname4 = generate_ascii_string(193, 255);
+
+my $node = get_new_node('main');
+$node->init(extra => ['--locale=C', '--encoding=LATIN1']);
+$node->start;
+
+foreach my $dbname ($dbname1, $dbname2, $dbname3, $dbname4, 'CamelCase')
+{
+ $node->run_log(['createdb', $dbname]);
+}
+
+$node->command_ok([qw(vacuumdb --all --echo --analyze-only)],
+ 'vacuumdb --all with unusual database names');
+$node->command_ok([qw(reindexdb --all --echo)],
+ 'reindexdb --all with unusual database names');
+$node->command_ok([qw(clusterdb --all --echo --verbose)],
+ 'clusterdb --all with unusual database names');