/[A3C]/t/11-ldap-server.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /t/11-ldap-server.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 229 - (hide annotations)
Fri Jun 27 19:31:49 2008 UTC (14 years ago) by dpavlin
File MIME type: application/x-troff
File size: 3667 byte(s)
A3C::LDAP::Server now function as full-featured LDAP relay server

- move code from bin/ldap-server.pl to A3C::LDAP::Server
- save cache of ldap searches (currently for debugging only,
  but I can envision falling back to cache if upstream
  server is unavailable)
- added ability to fork server in background (used in tests)
1 dpavlin 229 #!/usr/bin/env perl
2     use warnings;
3     use strict;
4    
5     =head1 DESCRIPTION
6    
7     test LDAP server
8    
9     =cut
10    
11     use Jifty::Test tests => 18;
12     use Data::Dump qw/dump/;
13    
14     use_ok('A3C::LDAP::Server');
15    
16     my $port = 1024 + int(rand(1024));
17    
18     diag "using port $port";
19    
20     ok( my $pid = A3C::LDAP::Server->run({ port => $port, fork => 1 }), "run( port => $port )" );
21    
22     diag "got pid: $pid";
23    
24     #isa_ok( $pid, 'A3C::LDAP::Server' );
25    
26     cmp_ok( $A3C::LDAP::Server::pids->{$port}, '==', $pid, 'pids' );
27    
28     ok( my $ldap = Net::LDAP->new( "localhost:$port" ), 'connect to server' );
29    
30     ok( my $c = Jifty->config->app('LDAP'), 'ldap config' );
31    
32     ok( $ldap->bind( $c->{dn}, password => $c->{password} ), 'bind' );
33    
34     ok( my $msg = $ldap->search(
35     base => $c->{base},
36     attrs => [
37     "uid",
38     "cn",
39     "hrEduPersonUniqueID",
40     "mail",
41     "sn",
42     "givenName",
43     "hrEduPersonUniqueNumber",
44     "hrEduPersonExpireDate",
45     "wtAdminType",
46     "hrEduPersonHomeOrg",
47     "uidNumber",
48     ],
49     filter => bless {
50     equalityMatch => {
51     assertionValue => "dobrica.pavlinusic2\@os-test0802f1-zg.skole.hr",
52     attributeDesc => "hrEduPersonUniqueID",
53     },
54     }, 'Net::LDAP::Filter',
55     ), 'search hrEduPersonUniqueID' );
56    
57     ok( my @entries = $msg->entries, 'entries' );
58     is( scalar @entries, 1, 'got 1 entry' );
59    
60     diag dump( @entries );
61    
62     is_deeply( shift @entries, bless({
63     asn => {
64     attributes => [
65     { type => "hrEduPersonUniqueNumber", vals => ["JMBG: 0000000000000"] },
66     { type => "sn", vals => ["Pavlinu\xC5\xA1i\xC4\x87"] },
67     { type => "hrEduPersonHomeOrg", vals => ["os-test0802f1-zg"] },
68     { type => "cn", vals => ["Dobrica Pavlinu\xC5\xA1i\xC4\x87"] },
69     { type => "hrEduPersonExpireDate", vals => [20100901] },
70     { type => "uid", vals => ["dobrica.pavlinusic2"] },
71     {
72     type => "hrEduPersonUniqueID",
73     vals => ["dobrica.pavlinusic2\@os-test0802f1-zg.skole.hr"],
74     },
75     { type => "wtAdminType", vals => ["AS"] },
76     { type => "uidNumber", vals => [339069] },
77     {
78     type => "mail",
79     vals => [
80     "dobrica.pavlinusic2\@skole.hr",
81     "dobrica.pavlinusic2\@os-test0802f1-zg.skole.hr",
82     ],
83     },
84     { type => "givenName", vals => ["Dobrica"] },
85     ],
86     objectName => "uid=dobrica.pavlinusic2,dc=os-test0802f1-zg,dc=skole,dc=hr",
87     },
88     changes => [],
89     changetype => "modify",
90     }, "Net::LDAP::Entry"),
91     'entry' );
92    
93     ok( $msg = $ldap->search(
94     base => $c->{base},
95     attrs => [
96     "dn",
97     ],
98     filter => bless {
99     equalityMatch => { assertionValue => "dobrica.pavlinusic2", attributeDesc => "uid" },
100     }, 'Net::LDAP::Filter',
101     ), 'search uid' );
102    
103     ok( @entries = $msg->entries, 'entries' );
104     is( scalar @entries, 1, 'got 1 entry' );
105    
106     diag dump( @entries );
107    
108     is_deeply( shift @entries,
109     bless({
110     asn => {
111     attributes => [],
112     objectName => "uid=dobrica.pavlinusic2,dc=os-test0802f1-zg,dc=skole,dc=hr",
113     },
114     changes => [],
115     changetype => "modify",
116     }, "Net::LDAP::Entry")
117     , 'entry' );
118    
119     ok( $msg = $ldap->search(
120     base => $c->{base},
121     attrs => [
122     "dn",
123     ],
124     filter => bless {
125     equalityMatch => { assertionValue => "non-existant", attributeDesc => "uid" },
126     }, 'Net::LDAP::Filter',
127     ), 'search non-existant' );
128    
129     cmp_ok( $msg->entries, '==', 0, 'no results' );
130    
131     ok( A3C::LDAP::Server->stop, 'stop' );
132    
133     ok( ! kill(9,$pid), "$pid gone" );

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26