aboutsummaryrefslogtreecommitdiff
path: root/src/test/ldap
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-04-25 14:00:19 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-04-25 14:00:19 -0400
commitf04d4ac919b9ae9b57e977523e4b40979aa8b951 (patch)
treeea104f87f210c15479c92bc5f4dd8c06f7a30583 /src/test/ldap
parent46cda5bf7bc209554b3c1bbb3040b45735387e0c (diff)
downloadpostgresql-f04d4ac919b9ae9b57e977523e4b40979aa8b951.tar.gz
postgresql-f04d4ac919b9ae9b57e977523e4b40979aa8b951.zip
Reindent Perl files with perltidy version 20170521.
Discussion: https://postgr.es/m/CABUevEzK3cNiHZQ18f5tK0guoT+cN_jWeVzhYYxY=r+1Q3SmoA@mail.gmail.com
Diffstat (limited to 'src/test/ldap')
-rw-r--r--src/test/ldap/t/001_auth.pl142
1 files changed, 91 insertions, 51 deletions
diff --git a/src/test/ldap/t/001_auth.pl b/src/test/ldap/t/001_auth.pl
index 3a71e053538..10680b78375 100644
--- a/src/test/ldap/t/001_auth.pl
+++ b/src/test/ldap/t/001_auth.pl
@@ -15,22 +15,22 @@ else
my ($slapd, $ldap_bin_dir, $ldap_schema_dir);
-$ldap_bin_dir = undef; # usually in PATH
+$ldap_bin_dir = undef; # usually in PATH
if ($^O eq 'darwin')
{
- $slapd = '/usr/local/opt/openldap/libexec/slapd';
+ $slapd = '/usr/local/opt/openldap/libexec/slapd';
$ldap_schema_dir = '/usr/local/etc/openldap/schema';
}
elsif ($^O eq 'linux')
{
- $slapd = '/usr/sbin/slapd';
+ $slapd = '/usr/sbin/slapd';
$ldap_schema_dir = '/etc/ldap/schema' if -d '/etc/ldap/schema';
$ldap_schema_dir = '/etc/openldap/schema' if -d '/etc/openldap/schema';
}
elsif ($^O eq 'freebsd')
{
- $slapd = '/usr/local/libexec/slapd';
+ $slapd = '/usr/local/libexec/slapd';
$ldap_schema_dir = '/usr/local/etc/openldap/schema';
}
@@ -41,26 +41,27 @@ elsif ($^O eq 'freebsd')
$ENV{PATH} = "$ldap_bin_dir:$ENV{PATH}" if $ldap_bin_dir;
-my $ldap_datadir = "${TestLib::tmp_check}/openldap-data";
-my $slapd_certs = "${TestLib::tmp_check}/slapd-certs";
-my $slapd_conf = "${TestLib::tmp_check}/slapd.conf";
+my $ldap_datadir = "${TestLib::tmp_check}/openldap-data";
+my $slapd_certs = "${TestLib::tmp_check}/slapd-certs";
+my $slapd_conf = "${TestLib::tmp_check}/slapd.conf";
my $slapd_pidfile = "${TestLib::tmp_check}/slapd.pid";
my $slapd_logfile = "${TestLib::tmp_check}/slapd.log";
-my $ldap_conf = "${TestLib::tmp_check}/ldap.conf";
-my $ldap_server = 'localhost';
-my $ldap_port = int(rand() * 16384) + 49152;
-my $ldaps_port = $ldap_port + 1;
-my $ldap_url = "ldap://$ldap_server:$ldap_port";
-my $ldaps_url = "ldaps://$ldap_server:$ldaps_port";
-my $ldap_basedn = 'dc=example,dc=net';
-my $ldap_rootdn = 'cn=Manager,dc=example,dc=net';
-my $ldap_rootpw = 'secret';
-my $ldap_pwfile = "${TestLib::tmp_check}/ldappassword";
+my $ldap_conf = "${TestLib::tmp_check}/ldap.conf";
+my $ldap_server = 'localhost';
+my $ldap_port = int(rand() * 16384) + 49152;
+my $ldaps_port = $ldap_port + 1;
+my $ldap_url = "ldap://$ldap_server:$ldap_port";
+my $ldaps_url = "ldaps://$ldap_server:$ldaps_port";
+my $ldap_basedn = 'dc=example,dc=net';
+my $ldap_rootdn = 'cn=Manager,dc=example,dc=net';
+my $ldap_rootpw = 'secret';
+my $ldap_pwfile = "${TestLib::tmp_check}/ldappassword";
note "setting up slapd";
-append_to_file($slapd_conf,
-qq{include $ldap_schema_dir/core.schema
+append_to_file(
+ $slapd_conf,
+ qq{include $ldap_schema_dir/core.schema
include $ldap_schema_dir/cosine.schema
include $ldap_schema_dir/nis.schema
include $ldap_schema_dir/inetorgperson.schema
@@ -84,16 +85,23 @@ rootdn "$ldap_rootdn"
rootpw $ldap_rootpw});
# don't bother to check the server's cert (though perhaps we should)
-append_to_file($ldap_conf,
-qq{TLS_REQCERT never
+append_to_file(
+ $ldap_conf,
+ qq{TLS_REQCERT never
});
mkdir $ldap_datadir or die;
-mkdir $slapd_certs or die;
-
-system_or_bail "openssl", "req", "-new", "-nodes", "-keyout", "$slapd_certs/ca.key", "-x509", "-out", "$slapd_certs/ca.crt", "-subj", "/cn=CA";
-system_or_bail "openssl", "req", "-new", "-nodes", "-keyout", "$slapd_certs/server.key", "-out", "$slapd_certs/server.csr", "-subj", "/cn=server";
-system_or_bail "openssl", "x509", "-req", "-in", "$slapd_certs/server.csr", "-CA", "$slapd_certs/ca.crt", "-CAkey", "$slapd_certs/ca.key", "-CAcreateserial", "-out", "$slapd_certs/server.crt";
+mkdir $slapd_certs or die;
+
+system_or_bail "openssl", "req", "-new", "-nodes", "-keyout",
+ "$slapd_certs/ca.key", "-x509", "-out", "$slapd_certs/ca.crt", "-subj",
+ "/cn=CA";
+system_or_bail "openssl", "req", "-new", "-nodes", "-keyout",
+ "$slapd_certs/server.key", "-out", "$slapd_certs/server.csr", "-subj",
+ "/cn=server";
+system_or_bail "openssl", "x509", "-req", "-in", "$slapd_certs/server.csr",
+ "-CA", "$slapd_certs/ca.crt", "-CAkey", "$slapd_certs/ca.key",
+ "-CAcreateserial", "-out", "$slapd_certs/server.crt";
system_or_bail $slapd, '-f', $slapd_conf, '-h', "$ldap_url $ldaps_url";
@@ -105,15 +113,17 @@ END
append_to_file($ldap_pwfile, $ldap_rootpw);
chmod 0600, $ldap_pwfile or die;
-$ENV{'LDAPURI'} = $ldap_url;
+$ENV{'LDAPURI'} = $ldap_url;
$ENV{'LDAPBINDDN'} = $ldap_rootdn;
-$ENV{'LDAPCONF'} = $ldap_conf;
+$ENV{'LDAPCONF'} = $ldap_conf;
note "loading LDAP data";
-system_or_bail 'ldapadd', '-x', '-y', $ldap_pwfile, '-f', 'authdata.ldif';
-system_or_bail 'ldappasswd', '-x', '-y', $ldap_pwfile, '-s', 'secret1', 'uid=test1,dc=example,dc=net';
-system_or_bail 'ldappasswd', '-x', '-y', $ldap_pwfile, '-s', 'secret2', 'uid=test2,dc=example,dc=net';
+system_or_bail 'ldapadd', '-x', '-y', $ldap_pwfile, '-f', 'authdata.ldif';
+system_or_bail 'ldappasswd', '-x', '-y', $ldap_pwfile, '-s', 'secret1',
+ 'uid=test1,dc=example,dc=net';
+system_or_bail 'ldappasswd', '-x', '-y', $ldap_pwfile, '-s', 'secret2',
+ 'uid=test2,dc=example,dc=net';
note "setting up PostgreSQL instance";
@@ -131,50 +141,66 @@ sub test_access
{
my ($node, $role, $expected_res, $test_name) = @_;
- my $res = $node->psql('postgres', 'SELECT 1', extra_params => [ '-U', $role ]);
- is($res, $expected_res, $test_name);
+ my $res =
+ $node->psql('postgres', 'SELECT 1', extra_params => [ '-U', $role ]);
+ is($res, $expected_res, $test_name);
}
note "simple bind";
unlink($node->data_dir . '/pg_hba.conf');
-$node->append_conf('pg_hba.conf', qq{local all all ldap ldapserver=$ldap_server ldapport=$ldap_port ldapprefix="uid=" ldapsuffix=",dc=example,dc=net"});
+$node->append_conf('pg_hba.conf',
+qq{local all all ldap ldapserver=$ldap_server ldapport=$ldap_port ldapprefix="uid=" ldapsuffix=",dc=example,dc=net"}
+);
$node->restart;
$ENV{"PGPASSWORD"} = 'wrong';
-test_access($node, 'test0', 2, 'simple bind authentication fails if user not found in LDAP');
-test_access($node, 'test1', 2, 'simple bind authentication fails with wrong password');
+test_access($node, 'test0', 2,
+ 'simple bind authentication fails if user not found in LDAP');
+test_access($node, 'test1', 2,
+ 'simple bind authentication fails with wrong password');
$ENV{"PGPASSWORD"} = 'secret1';
test_access($node, 'test1', 0, 'simple bind authentication succeeds');
note "search+bind";
unlink($node->data_dir . '/pg_hba.conf');
-$node->append_conf('pg_hba.conf', qq{local all all ldap ldapserver=$ldap_server ldapport=$ldap_port ldapbasedn="$ldap_basedn"});
+$node->append_conf('pg_hba.conf',
+qq{local all all ldap ldapserver=$ldap_server ldapport=$ldap_port ldapbasedn="$ldap_basedn"}
+);
$node->restart;
$ENV{"PGPASSWORD"} = 'wrong';
-test_access($node, 'test0', 2, 'search+bind authentication fails if user not found in LDAP');
-test_access($node, 'test1', 2, 'search+bind authentication fails with wrong password');
+test_access($node, 'test0', 2,
+ 'search+bind authentication fails if user not found in LDAP');
+test_access($node, 'test1', 2,
+ 'search+bind authentication fails with wrong password');
$ENV{"PGPASSWORD"} = 'secret1';
test_access($node, 'test1', 0, 'search+bind authentication succeeds');
note "LDAP URLs";
unlink($node->data_dir . '/pg_hba.conf');
-$node->append_conf('pg_hba.conf', qq{local all all ldap ldapurl="$ldap_url/$ldap_basedn?uid?sub"});
+$node->append_conf('pg_hba.conf',
+ qq{local all all ldap ldapurl="$ldap_url/$ldap_basedn?uid?sub"});
$node->restart;
$ENV{"PGPASSWORD"} = 'wrong';
-test_access($node, 'test0', 2, 'search+bind with LDAP URL authentication fails if user not found in LDAP');
-test_access($node, 'test1', 2, 'search+bind with LDAP URL authentication fails with wrong password');
+test_access($node, 'test0', 2,
+ 'search+bind with LDAP URL authentication fails if user not found in LDAP'
+);
+test_access($node, 'test1', 2,
+ 'search+bind with LDAP URL authentication fails with wrong password');
$ENV{"PGPASSWORD"} = 'secret1';
-test_access($node, 'test1', 0, 'search+bind with LDAP URL authentication succeeds');
+test_access($node, 'test1', 0,
+ 'search+bind with LDAP URL authentication succeeds');
note "search filters";
unlink($node->data_dir . '/pg_hba.conf');
-$node->append_conf('pg_hba.conf', qq{local all all ldap ldapserver=$ldap_server ldapport=$ldap_port ldapbasedn="$ldap_basedn" ldapsearchfilter="(|(uid=\$username)(mail=\$username))"});
+$node->append_conf('pg_hba.conf',
+qq{local all all ldap ldapserver=$ldap_server ldapport=$ldap_port ldapbasedn="$ldap_basedn" ldapsearchfilter="(|(uid=\$username)(mail=\$username))"}
+);
$node->restart;
$ENV{"PGPASSWORD"} = 'secret1';
@@ -185,7 +211,9 @@ test_access($node, 'test2@example.net', 0, 'search filter finds by mail');
note "search filters in LDAP URLs";
unlink($node->data_dir . '/pg_hba.conf');
-$node->append_conf('pg_hba.conf', qq{local all all ldap ldapurl="$ldap_url/$ldap_basedn??sub?(|(uid=\$username)(mail=\$username))"});
+$node->append_conf('pg_hba.conf',
+qq{local all all ldap ldapurl="$ldap_url/$ldap_basedn??sub?(|(uid=\$username)(mail=\$username))"}
+);
$node->restart;
$ENV{"PGPASSWORD"} = 'secret1';
@@ -197,7 +225,9 @@ test_access($node, 'test2@example.net', 0, 'search filter finds by mail');
# settings. ldapurl is always parsed first, then the other settings
# override. It might be useful in a case like this.
unlink($node->data_dir . '/pg_hba.conf');
-$node->append_conf('pg_hba.conf', qq{local all all ldap ldapurl="$ldap_url/$ldap_basedn??sub" ldapsearchfilter="(|(uid=\$username)(mail=\$username))"});
+$node->append_conf('pg_hba.conf',
+qq{local all all ldap ldapurl="$ldap_url/$ldap_basedn??sub" ldapsearchfilter="(|(uid=\$username)(mail=\$username))"}
+);
$node->restart;
$ENV{"PGPASSWORD"} = 'secret1';
@@ -207,7 +237,9 @@ note "diagnostic message";
# note bad ldapprefix with a question mark that triggers a diagnostic message
unlink($node->data_dir . '/pg_hba.conf');
-$node->append_conf('pg_hba.conf', qq{local all all ldap ldapserver=$ldap_server ldapport=$ldap_port ldapprefix="?uid=" ldapsuffix=""});
+$node->append_conf('pg_hba.conf',
+qq{local all all ldap ldapserver=$ldap_server ldapport=$ldap_port ldapprefix="?uid=" ldapsuffix=""}
+);
$node->restart;
$ENV{"PGPASSWORD"} = 'secret1';
@@ -217,7 +249,9 @@ note "TLS";
# request StartTLS with ldaptls=1
unlink($node->data_dir . '/pg_hba.conf');
-$node->append_conf('pg_hba.conf', qq{local all all ldap ldapserver=$ldap_server ldapport=$ldap_port ldapbasedn="$ldap_basedn" ldapsearchfilter="(uid=\$username)" ldaptls=1});
+$node->append_conf('pg_hba.conf',
+qq{local all all ldap ldapserver=$ldap_server ldapport=$ldap_port ldapbasedn="$ldap_basedn" ldapsearchfilter="(uid=\$username)" ldaptls=1}
+);
$node->restart;
$ENV{"PGPASSWORD"} = 'secret1';
@@ -225,7 +259,9 @@ test_access($node, 'test1', 0, 'StartTLS');
# request LDAPS with ldapscheme=ldaps
unlink($node->data_dir . '/pg_hba.conf');
-$node->append_conf('pg_hba.conf', qq{local all all ldap ldapserver=$ldap_server ldapscheme=ldaps ldapport=$ldaps_port ldapbasedn="$ldap_basedn" ldapsearchfilter="(uid=\$username)"});
+$node->append_conf('pg_hba.conf',
+qq{local all all ldap ldapserver=$ldap_server ldapscheme=ldaps ldapport=$ldaps_port ldapbasedn="$ldap_basedn" ldapsearchfilter="(uid=\$username)"}
+);
$node->restart;
$ENV{"PGPASSWORD"} = 'secret1';
@@ -233,7 +269,9 @@ test_access($node, 'test1', 0, 'LDAPS');
# request LDAPS with ldapurl=ldaps://...
unlink($node->data_dir . '/pg_hba.conf');
-$node->append_conf('pg_hba.conf', qq{local all all ldap ldapurl="$ldaps_url/$ldap_basedn??sub?(uid=\$username)"});
+$node->append_conf('pg_hba.conf',
+qq{local all all ldap ldapurl="$ldaps_url/$ldap_basedn??sub?(uid=\$username)"}
+);
$node->restart;
$ENV{"PGPASSWORD"} = 'secret1';
@@ -241,7 +279,9 @@ test_access($node, 'test1', 0, 'LDAPS with URL');
# bad combination of LDAPS and StartTLS
unlink($node->data_dir . '/pg_hba.conf');
-$node->append_conf('pg_hba.conf', qq{local all all ldap ldapurl="$ldaps_url/$ldap_basedn??sub?(uid=\$username)" ldaptls=1});
+$node->append_conf('pg_hba.conf',
+qq{local all all ldap ldapurl="$ldaps_url/$ldap_basedn??sub?(uid=\$username)" ldaptls=1}
+);
$node->restart;
$ENV{"PGPASSWORD"} = 'secret1';