-
Notifications
You must be signed in to change notification settings - Fork 1
/
04-bind.t
87 lines (66 loc) · 1.95 KB
/
04-bind.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use Test::More tests => 9;
use Proc::Fork;
use Net::LDAP;
use Net::LDAP::SimpleServer;
use Data::Dumper;
use constant TESTHOST => 'localhost';
use constant TESTPORT => 10389;
use constant TESTDATA => 'examples/single-entry.ldif';
use constant TESTROOTDN => 'cn=root';
use constant TESTROOTPW => 'testpw';
#sub diag { print STDERR @_; }
sub ldapconnect {
return Net::LDAP->new( TESTHOST, port => TESTPORT );
}
sub run_test {
my $mesg = undef;
my $ldap = ldapconnect();
ok($ldap);
diag('Binding anonymously');
$mesg = $ldap->bind;
ok( !$mesg->code, $mesg->error_desc );
$mesg = $ldap->unbind;
ok( !$mesg->code, $mesg->error_desc );
diag('Binding with authentication');
$ldap = ldapconnect();
$mesg = $ldap->bind( TESTROOTDN, password => TESTROOTPW );
ok( !$mesg->code, $mesg->error_desc );
$mesg = $ldap->unbind;
ok( !$mesg->code, $mesg->error_desc );
diag('Upper case bind DN');
$ldap = ldapconnect();
$mesg = $ldap->bind( uc(TESTROOTDN), password => TESTROOTPW );
ok( !$mesg->code, $mesg->error_desc );
$mesg = $ldap->unbind;
ok( !$mesg->code, $mesg->error_desc );
diag('Wrong password -> no bind');
$ldap = ldapconnect();
$mesg = $ldap->bind( TESTROOTDN, password => 'some-wrong-password' );
ok( $mesg->code, $mesg->error_desc );
diag('Unbinding');
$mesg = $ldap->unbind;
ok( !$mesg->code, $mesg->error_desc );
}
run_fork {
parent {
my $child = shift;
# give the server some time to start
sleep 10;
# run client
run_test();
kill 15, $child;
}
child {
my $s = Net::LDAP::SimpleServer->new();
# run server
diag('Starting Net::LDAP::SimpleServer [Fork]');
$s->run(
{
port => TESTPORT,
ldap_data => TESTDATA,
root_pw => TESTROOTPW,
}
);
diag('Server has quit');
}
};