Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1782571

Browse files
committed
Improve check in LDAP test to find the OpenLDAP installation
If the OpenLDAP installation directory is not found, set $setup to 0 so that the LDAP tests are skipped. The macOS checks were already doing that, but the checks on other OS's were not. While we're at it, improve the error message when the tests are skipped, to specify whether the OS is supported at all, or if we just didn't find the installation directory. This was accidentally "working" without this, i.e. we were skipping the tests if the OpenLDAP installation was not found, because of a bug in the LdapServer test module: the END block clobbered the exit code so if the script die()s before running the first subtest, the whole test script was marked as SKIPped. The next commit will fix that bug, but we need to fix the setup code first. These checks should probably go into configure/meson, but this is better than nothing and allows fixing the bug in the END block. Backpatch to all supported versions. Discussion: https://www.postgresql.org/message-id/fb898a70-3a88-4629-88e9-f2375020061d@iki.fi
1 parent 360d007 commit 1782571

File tree

1 file changed

+56
-28
lines changed

1 file changed

+56
-28
lines changed

src/test/ldap/t/001_auth.pl

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,73 @@
44
use PostgresNode;
55
use Test::More;
66

7-
if ($ENV{with_ldap} eq 'yes')
8-
{
9-
plan tests => 22;
10-
}
11-
else
12-
{
13-
plan skip_all => 'LDAP not supported by this build';
14-
}
15-
167
my ($slapd, $ldap_bin_dir, $ldap_schema_dir);
178

189
$ldap_bin_dir = undef; # usually in PATH
1910

20-
if ($^O eq 'darwin' && -d '/opt/homebrew/opt/openldap')
11+
if ($ENV{with_ldap} ne 'yes')
2112
{
22-
# typical paths for Homebrew on ARM
23-
$slapd = '/opt/homebrew/opt/openldap/libexec/slapd';
24-
$ldap_schema_dir = '/opt/homebrew/etc/openldap/schema';
25-
}
26-
elsif ($^O eq 'darwin' && -d '/usr/local/opt/openldap')
27-
{
28-
# typical paths for Homebrew on Intel
29-
$slapd = '/usr/local/opt/openldap/libexec/slapd';
30-
$ldap_schema_dir = '/usr/local/etc/openldap/schema';
13+
plan skip_all => 'LDAP not supported by this build';
3114
}
32-
elsif ($^O eq 'darwin' && -d '/opt/local/etc/openldap')
15+
# Find the OpenLDAP server binary and directory containing schema
16+
# definition files.
17+
elsif ($^O eq 'darwin')
3318
{
34-
# typical paths for MacPorts
35-
$slapd = '/opt/local/libexec/slapd';
36-
$ldap_schema_dir = '/opt/local/etc/openldap/schema';
19+
if (-d '/opt/homebrew/opt/openldap')
20+
{
21+
# typical paths for Homebrew on ARM
22+
$slapd = '/opt/homebrew/opt/openldap/libexec/slapd';
23+
$ldap_schema_dir = '/opt/homebrew/etc/openldap/schema';
24+
}
25+
elsif (-d '/usr/local/opt/openldap')
26+
{
27+
# typical paths for Homebrew on Intel
28+
$slapd = '/usr/local/opt/openldap/libexec/slapd';
29+
$ldap_schema_dir = '/usr/local/etc/openldap/schema';
30+
}
31+
elsif (-d '/opt/local/etc/openldap')
32+
{
33+
# typical paths for MacPorts
34+
$slapd = '/opt/local/libexec/slapd';
35+
$ldap_schema_dir = '/opt/local/etc/openldap/schema';
36+
}
37+
else
38+
{
39+
plan skip_all => "OpenLDAP server installation not found";
40+
}
3741
}
3842
elsif ($^O eq 'linux')
3943
{
40-
$slapd = '/usr/sbin/slapd';
41-
$ldap_schema_dir = '/etc/ldap/schema' if -d '/etc/ldap/schema';
42-
$ldap_schema_dir = '/etc/openldap/schema' if -d '/etc/openldap/schema';
44+
if (-d '/etc/ldap/schema')
45+
{
46+
$slapd = '/usr/sbin/slapd';
47+
$ldap_schema_dir = '/etc/ldap/schema';
48+
}
49+
elsif (-d '/etc/openldap/schema')
50+
{
51+
$slapd = '/usr/sbin/slapd';
52+
$ldap_schema_dir = '/etc/openldap/schema';
53+
}
54+
else
55+
{
56+
plan skip_all => "OpenLDAP server installation not found";
57+
}
4358
}
4459
elsif ($^O eq 'freebsd')
4560
{
46-
$slapd = '/usr/local/libexec/slapd';
47-
$ldap_schema_dir = '/usr/local/etc/openldap/schema';
61+
if (-d '/usr/local/etc/openldap/schema')
62+
{
63+
$slapd = '/usr/local/libexec/slapd';
64+
$ldap_schema_dir = '/usr/local/etc/openldap/schema';
65+
}
66+
else
67+
{
68+
plan skip_all => "OpenLDAP server installation not found";
69+
}
70+
}
71+
else
72+
{
73+
plan skip_all => "ldap tests not supported on $^O";
4874
}
4975

5076
# make your own edits here
@@ -336,3 +362,5 @@ sub test_access
336362

337363
$ENV{"PGPASSWORD"} = 'secret1';
338364
test_access($node, 'test1', 2, 'bad combination of LDAPS and StartTLS');
365+
366+
done_testing();

0 commit comments

Comments
 (0)