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

Commit e13b586

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 b7b0f3f commit e13b586

File tree

3 files changed

+67
-30
lines changed

3 files changed

+67
-30
lines changed

src/test/ldap/LdapServer.pm

+65-26
Original file line numberDiff line numberDiff line change
@@ -57,49 +57,88 @@ use File::Basename;
5757
# private variables
5858
my ($slapd, $ldap_schema_dir, @servers);
5959

60-
# visible variable
61-
our ($setup);
60+
# visible variables
61+
our ($setup, $setup_error);
6262

6363
INIT
6464
{
65+
# Find the OpenLDAP server binary and directory containing schema
66+
# definition files. On success, $setup is set to 1. On failure,
67+
# it's set to 0, and an error message is set in $setup_error.
6568
$setup = 1;
66-
if ($^O eq 'darwin' && -d '/opt/homebrew/opt/openldap')
69+
if ($^O eq 'darwin')
6770
{
68-
# typical paths for Homebrew on ARM
69-
$slapd = '/opt/homebrew/opt/openldap/libexec/slapd';
70-
$ldap_schema_dir = '/opt/homebrew/etc/openldap/schema';
71-
}
72-
elsif ($^O eq 'darwin' && -d '/usr/local/opt/openldap')
73-
{
74-
# typical paths for Homebrew on Intel
75-
$slapd = '/usr/local/opt/openldap/libexec/slapd';
76-
$ldap_schema_dir = '/usr/local/etc/openldap/schema';
77-
}
78-
elsif ($^O eq 'darwin' && -d '/opt/local/etc/openldap')
79-
{
80-
# typical paths for MacPorts
81-
$slapd = '/opt/local/libexec/slapd';
82-
$ldap_schema_dir = '/opt/local/etc/openldap/schema';
71+
if (-d '/opt/homebrew/opt/openldap')
72+
{
73+
# typical paths for Homebrew on ARM
74+
$slapd = '/opt/homebrew/opt/openldap/libexec/slapd';
75+
$ldap_schema_dir = '/opt/homebrew/etc/openldap/schema';
76+
}
77+
elsif (-d '/usr/local/opt/openldap')
78+
{
79+
# typical paths for Homebrew on Intel
80+
$slapd = '/usr/local/opt/openldap/libexec/slapd';
81+
$ldap_schema_dir = '/usr/local/etc/openldap/schema';
82+
}
83+
elsif (-d '/opt/local/etc/openldap')
84+
{
85+
# typical paths for MacPorts
86+
$slapd = '/opt/local/libexec/slapd';
87+
$ldap_schema_dir = '/opt/local/etc/openldap/schema';
88+
}
89+
else
90+
{
91+
$setup_error = "OpenLDAP server installation not found";
92+
$setup = 0;
93+
}
8394
}
8495
elsif ($^O eq 'linux')
8596
{
86-
$slapd = '/usr/sbin/slapd';
87-
$ldap_schema_dir = '/etc/ldap/schema' if -d '/etc/ldap/schema';
88-
$ldap_schema_dir = '/etc/openldap/schema'
89-
if -d '/etc/openldap/schema';
97+
if (-d '/etc/ldap/schema')
98+
{
99+
$slapd = '/usr/sbin/slapd';
100+
$ldap_schema_dir = '/etc/ldap/schema';
101+
}
102+
elsif (-d '/etc/openldap/schema')
103+
{
104+
$slapd = '/usr/sbin/slapd';
105+
$ldap_schema_dir = '/etc/openldap/schema';
106+
}
107+
else
108+
{
109+
$setup_error = "OpenLDAP server installation not found";
110+
$setup = 0;
111+
}
90112
}
91113
elsif ($^O eq 'freebsd')
92114
{
93-
$slapd = '/usr/local/libexec/slapd';
94-
$ldap_schema_dir = '/usr/local/etc/openldap/schema';
115+
if (-d '/usr/local/etc/openldap/schema')
116+
{
117+
$slapd = '/usr/local/libexec/slapd';
118+
$ldap_schema_dir = '/usr/local/etc/openldap/schema';
119+
}
120+
else
121+
{
122+
$setup_error = "OpenLDAP server installation not found";
123+
$setup = 0;
124+
}
95125
}
96126
elsif ($^O eq 'openbsd')
97127
{
98-
$slapd = '/usr/local/libexec/slapd';
99-
$ldap_schema_dir = '/usr/local/share/examples/openldap/schema';
128+
if (-d '/usr/local/share/examples/openldap/schema')
129+
{
130+
$slapd = '/usr/local/libexec/slapd';
131+
$ldap_schema_dir = '/usr/local/share/examples/openldap/schema';
132+
}
133+
else
134+
{
135+
$setup_error = "OpenLDAP server installation not found";
136+
$setup = 0;
137+
}
100138
}
101139
else
102140
{
141+
$setup_error = "ldap tests not supported on $^O";
103142
$setup = 0;
104143
}
105144
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
}
2626
elsif (!$LdapServer::setup)
2727
{
28-
plan skip_all =>
29-
"ldap tests not supported on $^O or dependencies not installed";
28+
plan skip_all => $LdapServer::setup_error;
3029
}
3130

3231
note "setting up LDAP server";

src/test/ldap/t/002_bindpasswd.pl

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
}
2626
elsif (!$LdapServer::setup)
2727
{
28-
plan skip_all =>
29-
"ldap tests not supported on $^O or dependencies not installed";
28+
plan skip_all => $LdapServer::setup_error;
3029
}
3130

3231
note "setting up LDAP server";

0 commit comments

Comments
 (0)