| 1 |
|
| 2 |
# Copyright (c) 2021-2025, PostgreSQL Global Development Group |
| 3 |
|
| 4 |
use strict; |
| 5 |
use warnings FATAL => 'all'; |
| 6 |
|
| 7 |
use PostgreSQL::Test::Cluster; |
| 8 |
use PostgreSQL::Test::Utils; |
| 9 |
use Test::More; |
| 10 |
|
| 11 |
my $tempdir = PostgreSQL::Test::Utils::tempdir; |
| 12 |
|
| 13 |
my $node = PostgreSQL::Test::Cluster->new('main'); |
| 14 |
my $port = $node->port; |
| 15 |
|
| 16 |
$node->init; |
| 17 |
$node->start; |
| 18 |
|
| 19 |
######################################### |
| 20 |
# pg_dumpall: newline in database name |
| 21 |
|
| 22 |
$node->safe_psql('postgres', qq{CREATE DATABASE "regress_\nattack"}); |
| 23 |
|
| 24 |
my (@cmd, $stdout, $stderr); |
| 25 |
@cmd = ("pg_dumpall", '--port' => $port, '--exclude-database=postgres'); |
| 26 |
print("# Running: " . join(" ", @cmd) . "\n"); |
| 27 |
my $result = IPC::Run::run \@cmd, '>' => \$stdout, '2>' => \$stderr; |
| 28 |
ok(!$result, "newline in dbname: exit code not 0"); |
| 29 |
like( |
| 30 |
$stderr, |
| 31 |
qr/shell command argument contains a newline/, |
| 32 |
"newline in dbname: stderr matches"); |
| 33 |
unlike($stdout, qr/^attack/m, "newline in dbname: no comment escape"); |
| 34 |
|
| 35 |
######################################### |
| 36 |
# Verify that dumping foreign data includes only foreign tables of |
| 37 |
# matching servers |
| 38 |
|
| 39 |
$node->safe_psql('postgres', "CREATE FOREIGN DATA WRAPPER dummy"); |
| 40 |
$node->safe_psql('postgres', "CREATE SERVER s0 FOREIGN DATA WRAPPER dummy"); |
| 41 |
$node->safe_psql('postgres', "CREATE SERVER s1 FOREIGN DATA WRAPPER dummy"); |
| 42 |
$node->safe_psql('postgres', "CREATE SERVER s2 FOREIGN DATA WRAPPER dummy"); |
| 43 |
$node->safe_psql('postgres', "CREATE FOREIGN TABLE t0 (a int) SERVER s0"); |
| 44 |
$node->safe_psql('postgres', "CREATE FOREIGN TABLE t1 (a int) SERVER s1"); |
| 45 |
|
| 46 |
command_fails_like( |
| 47 |
[ |
| 48 |
"pg_dump", |
| 49 |
'--port' => $port, |
| 50 |
'--include-foreign-data' => 's0', |
| 51 |
'postgres' |
| 52 |
], |
| 53 |
qr/foreign-data wrapper \"dummy\" has no handler\r?\npg_dump: detail: Query was: .*t0/, |
| 54 |
"correctly fails to dump a foreign table from a dummy FDW"); |
| 55 |
|
| 56 |
command_ok( |
| 57 |
[ |
| 58 |
"pg_dump", |
| 59 |
'--port' => $port, |
| 60 |
'--data-only', |
| 61 |
'--include-foreign-data' => 's2', |
| 62 |
'postgres' |
| 63 |
], |
| 64 |
"dump foreign server with no tables"); |
| 65 |
|
| 66 |
done_testing(); |