1 |
#!/usr/bin/perl |
2 |
|
3 |
use warnings; |
4 |
use strict; |
5 |
|
6 |
use Test::More tests => 75; |
7 |
use Data::Dump qw(dump); |
8 |
|
9 |
BEGIN { |
10 |
use_ok 'Net::LDAP'; |
11 |
} |
12 |
|
13 |
sub ldap_check_error { |
14 |
my $o = shift; |
15 |
ok( ! $o->code, 'no errror' ); |
16 |
diag $o->error if $o->code; |
17 |
} |
18 |
|
19 |
ok( my $ldap = Net::LDAP->new( 'localhost:2389' ), 'new Net::LDAP' ); |
20 |
|
21 |
ok( my $bind = $ldap->bind, 'bind' ); |
22 |
ldap_check_error $bind; |
23 |
|
24 |
sub check_search_attributes { |
25 |
my $search = shift; |
26 |
|
27 |
foreach my $entry ( $search->entries ) { |
28 |
diag dump $entry; |
29 |
map { ok( $_, "attribute $_" ) } grep { /^\Q$_\E$/i } $entry->attributes; |
30 |
} |
31 |
} |
32 |
|
33 |
sub search { |
34 |
my ($ldap,$search) = @_; |
35 |
ok( my $search = $ldap->search( filter => $search ), "search $search" ); |
36 |
ldap_check_error $search; |
37 |
ok( $search->entries, 'have results' ); |
38 |
return $search; |
39 |
} |
40 |
|
41 |
foreach my $search ( qw/ |
42 |
uid=dpavlin@ffzg.hr |
43 |
pager=E00401001F77E218 |
44 |
/ ) { |
45 |
my $entries = search $ldap => $search; |
46 |
check_search_attributes $entries => 'uid', 'mail', 'pager', 'memberOf'; |
47 |
|
48 |
$entries = search $ldap => "(&(objectclass=HrEduPerson)($search))"; |
49 |
check_search_attributes $entries => 'uid', 'mail', 'pager', 'memberOf'; |
50 |
} |
51 |
|
52 |
search $ldap => $_ foreach ( qw/ |
53 |
objectclass=organizationalUnit |
54 |
objectclass=group |
55 |
/ ); |
56 |
|
57 |
ok( $ldap->unbind, 'unbind' ); |