1 |
dpavlin |
75 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
use warnings; |
4 |
|
|
use strict; |
5 |
|
|
|
6 |
dpavlin |
89 |
use Test::More tests => 76; |
7 |
dpavlin |
75 |
use Data::Dump qw(dump); |
8 |
|
|
|
9 |
|
|
BEGIN { |
10 |
|
|
use_ok 'Net::LDAP'; |
11 |
|
|
} |
12 |
|
|
|
13 |
dpavlin |
89 |
our $config; |
14 |
|
|
ok( require( ( shift @ARGV || 't/config.pl' ) ), 'config.pl' ); |
15 |
|
|
|
16 |
|
|
diag "config ",dump($config); |
17 |
|
|
|
18 |
dpavlin |
75 |
sub ldap_check_error { |
19 |
|
|
my $o = shift; |
20 |
|
|
ok( ! $o->code, 'no errror' ); |
21 |
|
|
diag $o->error if $o->code; |
22 |
|
|
} |
23 |
|
|
|
24 |
dpavlin |
103 |
ok( my $ldap = Net::LDAP->new( $ENV{LISTEN} || 'localhost:2389' ), 'new Net::LDAP' ); |
25 |
dpavlin |
75 |
|
26 |
|
|
ok( my $bind = $ldap->bind, 'bind' ); |
27 |
|
|
ldap_check_error $bind; |
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 |
dpavlin |
77 |
sub search { |
39 |
|
|
my ($ldap,$search) = @_; |
40 |
dpavlin |
89 |
ok( my $result = $ldap->search( filter => $search ), "search $search" ); |
41 |
|
|
ldap_check_error $result; |
42 |
|
|
ok( $result->entries, 'have results' ); |
43 |
|
|
return $result; |
44 |
dpavlin |
77 |
} |
45 |
dpavlin |
75 |
|
46 |
dpavlin |
77 |
foreach my $search ( qw/ |
47 |
|
|
uid=dpavlin@ffzg.hr |
48 |
|
|
pager=E00401001F77E218 |
49 |
|
|
/ ) { |
50 |
|
|
my $entries = search $ldap => $search; |
51 |
|
|
check_search_attributes $entries => 'uid', 'mail', 'pager', 'memberOf'; |
52 |
|
|
|
53 |
|
|
$entries = search $ldap => "(&(objectclass=HrEduPerson)($search))"; |
54 |
|
|
check_search_attributes $entries => 'uid', 'mail', 'pager', 'memberOf'; |
55 |
dpavlin |
75 |
} |
56 |
|
|
|
57 |
dpavlin |
77 |
search $ldap => $_ foreach ( qw/ |
58 |
|
|
objectclass=organizationalUnit |
59 |
|
|
objectclass=group |
60 |
|
|
/ ); |
61 |
dpavlin |
75 |
|
62 |
|
|
ok( $ldap->unbind, 'unbind' ); |