commit 96a47b09318b7a6b390ec1b93f8fed477e5c898e
Author: Ian Barwick <ian@2ndquadrant.com>
Date:   Wed Jul 17 10:57:06 2019 +0900

    Add TAP test for invalid "include" directives
    
    Check that "include" directives are rejected in:
    
     - postgresql.auto.conf
     - extension control files

diff --git a/src/test/configuration/t/003_forbid_include_directives.pl b/src/test/configuration/t/003_forbid_include_directives.pl
new file mode 100644
index 0000000000..1bd092eda6
--- /dev/null
+++ b/src/test/configuration/t/003_forbid_include_directives.pl
@@ -0,0 +1,131 @@
+# Test that include directives are rejected where not appropriate,
+# specifically in:
+#  - postgresql.auto.conf
+#  - extension control files
+
+use strict;
+use warnings;
+use PostgresNode;
+use TestLib;
+use Test::More tests => 6;
+
+our $postgresql_auto_conf = 'postgresql.auto.conf';
+our $extension_name = 'dummy_extension';
+our ($result, $result_stdout, $result_stderr);
+our $fh;
+
+# Initialize a single node
+# ------------------------
+
+my $node = get_new_node('primary');
+$node->init();
+$node->start;
+
+our $file_settings_query = sprintf(
+    "SELECT error FROM pg_catalog.pg_file_settings WHERE sourcefile = '%s/%s' AND sourceline = 1",
+    $node->data_dir,
+    $postgresql_auto_conf,
+);
+
+our $extension_control_file = $node->safe_psql(
+    'postgres',
+    "SELECT setting || '/extension/${extension_name}.control' FROM pg_catalog.pg_config WHERE name = 'SHAREDIR'",
+);
+
+
+# 1. Check "include" is rejected in "postgresql.auto.conf"
+# --------------------------------------------------------
+
+$node->write_conf($postgresql_auto_conf,
+                  "include = 'postgresql.conf'\n");
+
+$result = $node->safe_psql('postgres', $file_settings_query);
+
+is($result,
+   '"include" not permitted',
+   'Check "include" directive is rejected');
+
+
+# 2. Check "include_if_exists" is rejected in "postgresql.auto.conf"
+# ------------------------------------------------------------------
+
+$node->write_conf($postgresql_auto_conf,
+                  "include_if_exists = 'postgresql.conf'\n");
+
+$result = $node->safe_psql('postgres', $file_settings_query);
+
+is($result,
+   '"include_if_exists" not permitted',
+   'Check "include_if_exists" directive is rejected');
+
+
+# 3. Check "include_dir" is rejected in "postgresql.auto.conf"
+# ------------------------------------------------------------
+
+$node->write_conf($postgresql_auto_conf,
+                  "include_dir = 'postgresql.conf'\n");
+
+$result = $node->safe_psql('postgres', $file_settings_query);
+
+is($result,
+   '"include_dir" not permitted',
+   'Check "include_dir" directive is rejected');
+
+
+# 4. Check "include" is rejected in an extension control file
+# ------------------------------------------------------------
+
+open $fh, ">", $extension_control_file,
+    or die "could not write \"$extension_control_file\": $!";
+
+print $fh "include = 'postgresql.conf'\n";
+close $fh;
+
+($result, $result_stdout, $result_stderr) = $node->psql(
+    'postgres',
+    "CREATE EXTENSION $extension_name",
+);
+
+like($result_stderr,
+   qr/"include" not permitted in file/,
+   'Check "include" directive is rejected');
+
+# 5. Check "include_if_exists" is rejected in an extension control file
+# ---------------------------------------------------------------------
+
+open $fh, ">", $extension_control_file,
+    or die "could not write \"$extension_control_file\": $!";
+
+print $fh "include_if_exists = 'postgresql.conf'\n";
+close $fh;
+
+($result, $result_stdout, $result_stderr) = $node->psql(
+    'postgres',
+    "CREATE EXTENSION $extension_name",
+);
+
+like($result_stderr,
+   qr/"include_if_exists" not permitted in file/,
+   'Check "include_if_exists" directive is rejected');
+
+
+# 6. Check "include_dir" is rejected in an extension control file
+# ---------------------------------------------------------------
+
+open $fh, ">", $extension_control_file,
+    or die "could not write \"$extension_control_file\": $!";
+
+print $fh "include_dir = 'postgresql.conf'\n";
+close $fh;
+
+($result, $result_stdout, $result_stderr) = $node->psql(
+    'postgres',
+    "CREATE EXTENSION $extension_name",
+);
+
+like($result_stderr,
+   qr/"include_dir" not permitted in file/,
+   'Check "include_dir" directive is rejected');
+
+# Remove the invalid extension control file
+unlink $extension_control_file;
