Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a9dc7f9

Browse filesBrowse files
committed
Add a test using ldapbindpasswd in pg_hba.conf
This feature has not been covered in tests up to now. John Naylor and Andrew Dunstan Discussion: https://postgr.es/m/06005bfb-0fd7-9d08-e0e5-440f277b73b4@dunslane.net
1 parent ee4613d commit a9dc7f9
Copy full SHA for a9dc7f9

File tree

2 files changed

+96
-0
lines changed
Filter options

2 files changed

+96
-0
lines changed

‎src/test/ldap/meson.build

Copy file name to clipboardExpand all lines: src/test/ldap/meson.build
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ tests += {
77
'tap': {
88
'tests': [
99
't/001_auth.pl',
10+
't/002_bindpasswd.pl',
1011
],
1112
'env': {
1213
'with_ldap': ldap.found() ? 'yes' : 'no',

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

Copy file name to clipboard
+95Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
2+
# Copyright (c) 2023, PostgreSQL Global Development Group
3+
4+
use strict;
5+
use warnings;
6+
7+
use FindBin;
8+
use lib "$FindBin::RealBin/..";
9+
10+
use File::Copy;
11+
use File::Basename;
12+
use LdapServer;
13+
use PostgreSQL::Test::Utils;
14+
use PostgreSQL::Test::Cluster;
15+
use Test::More;
16+
17+
if ($ENV{with_ldap} ne 'yes')
18+
{
19+
plan skip_all => 'LDAP not supported by this build';
20+
}
21+
elsif ($ENV{PG_TEST_EXTRA} !~ /\bldap\b/)
22+
{
23+
plan skip_all =>
24+
'Potentially unsafe test LDAP not enabled in PG_TEST_EXTRA';
25+
}
26+
elsif (!$LdapServer::setup)
27+
{
28+
plan skip_all =>
29+
"ldap tests not supported on $^O or dependencies not installed";
30+
}
31+
32+
note "setting up LDAP server";
33+
34+
my $ldap_rootpw = 'secret';
35+
my $ldap = LdapServer->new($ldap_rootpw, 'users'); # no anonymous auth
36+
$ldap->ldapadd_file('authdata.ldif');
37+
$ldap->ldapsetpw('uid=test1,dc=example,dc=net', 'secret1');
38+
$ldap->ldapsetpw('uid=test2,dc=example,dc=net', 'secret2');
39+
40+
my ($ldap_server, $ldap_port, $ldap_basedn, $ldap_rootdn) =
41+
$ldap->prop(qw(server port basedn rootdn));
42+
43+
note "setting up PostgreSQL instance";
44+
45+
my $node = PostgreSQL::Test::Cluster->new('node');
46+
$node->init;
47+
$node->append_conf('postgresql.conf', "log_connections = on\n");
48+
$node->start;
49+
50+
$node->safe_psql('postgres', 'CREATE USER test0;');
51+
$node->safe_psql('postgres', 'CREATE USER test1;');
52+
$node->safe_psql('postgres', 'CREATE USER "test2@example.net";');
53+
54+
note "running tests";
55+
56+
sub test_access
57+
{
58+
local $Test::Builder::Level = $Test::Builder::Level + 1;
59+
60+
my ($node, $role, $expected_res, $test_name, %params) = @_;
61+
my $connstr = "user=$role";
62+
63+
if ($expected_res eq 0)
64+
{
65+
$node->connect_ok($connstr, $test_name, %params);
66+
}
67+
else
68+
{
69+
# No checks of the error message, only the status code.
70+
$node->connect_fails($connstr, $test_name, %params);
71+
}
72+
}
73+
74+
note "use ldapbindpasswd";
75+
76+
unlink($node->data_dir . '/pg_hba.conf');
77+
$node->append_conf('pg_hba.conf',
78+
qq{local all all ldap ldapserver=$ldap_server ldapport=$ldap_port ldapbasedn="$ldap_basedn" ldapbinddn="$ldap_rootdn ldapbindpasswd=wrong}
79+
);
80+
$node->restart;
81+
82+
$ENV{"PGPASSWORD"} = 'secret1';
83+
test_access($node, 'test1', 2,
84+
'search+bind authentication fails with wrong ldapbindpasswd');
85+
86+
unlink($node->data_dir . '/pg_hba.conf');
87+
$node->append_conf('pg_hba.conf',
88+
qq{local all all ldap ldapserver=$ldap_server ldapport=$ldap_port ldapbasedn="$ldap_basedn" ldapbinddn="$ldap_rootdn" ldapbindpasswd="$ldap_rootpw"}
89+
);
90+
$node->restart;
91+
92+
test_access($node, 'test1', 0,
93+
'search+bind authentication succeeds with ldapbindpasswd');
94+
95+
done_testing();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.