1 |
#!/usr/bin/perl |
2 |
|
3 |
use warnings; |
4 |
use strict; |
5 |
|
6 |
use Test::More tests => 37; |
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 |
my @test_searches = ( qw/ |
25 |
uid=dpavlin@ffzg.hr |
26 |
pager=E00401001F77E218 |
27 |
/ ); |
28 |
|
29 |
sub check_search_attributes { |
30 |
my $search = shift; |
31 |
|
32 |
foreach my $entry ( $search->entries ) { |
33 |
diag dump $entry; |
34 |
map { ok( $_, "attribute $_" ) } grep { /^\Q$_\E$/i } $entry->attributes; |
35 |
} |
36 |
} |
37 |
|
38 |
foreach my $search ( @test_searches ) { |
39 |
|
40 |
ok( my $search = $ldap->search( filter => $search ), "search $search" ); |
41 |
ldap_check_error $search; |
42 |
ok( $search->entries, 'have results' ); |
43 |
check_search_attributes $search => 'uid', 'mail', 'pager', 'memberOf'; |
44 |
|
45 |
} |
46 |
|
47 |
|
48 |
ok( $ldap->unbind, 'unbind' ); |