line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
14
|
|
|
14
|
|
24309
|
use 5.006; |
|
14
|
|
|
|
|
32
|
|
|
14
|
|
|
|
|
402
|
|
2
|
14
|
|
|
14
|
|
50
|
use strict; |
|
14
|
|
|
|
|
19
|
|
|
14
|
|
|
|
|
304
|
|
3
|
14
|
|
|
14
|
|
45
|
use warnings; |
|
14
|
|
|
|
|
15
|
|
|
14
|
|
|
|
|
401
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Test::Net::LDAP; |
6
|
14
|
|
|
14
|
|
54
|
use base qw(Net::LDAP Test::Net::LDAP::Mixin); |
|
14
|
|
|
|
|
20
|
|
|
14
|
|
|
|
|
3986
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Test::Net::LDAP - A Net::LDAP subclass for testing |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.07 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Basic testing utility |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Test::More tests => 1; |
25
|
|
|
|
|
|
|
use Test::Net::LDAP; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Create an object, just like Net::LDAP->new() |
28
|
|
|
|
|
|
|
my $ldap = Test::Net::LDAP->new(...); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Same as $ldap->search(), testing the result to see if it is success |
31
|
|
|
|
|
|
|
my $search = $ldap->search_ok(...search args...); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Mocking (See L) |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Test::More tests => 1; |
36
|
|
|
|
|
|
|
use Test::Net::LDAP::Util qw(ldap_mockify); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
ldap_mockify { |
39
|
|
|
|
|
|
|
# Net::LDAP->new() will invoke Test::Net::LDAP::Mock->new() |
40
|
|
|
|
|
|
|
my $ldap = Net::LDAP->new('ldap.example.com'); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Add entries to in-memory data tree |
43
|
|
|
|
|
|
|
$ldap->add('uid=user1, ou=users, dc=example, dc=com'); |
44
|
|
|
|
|
|
|
$ldap->add('uid=user2, ou=users, dc=example, dc=com'); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Test your application |
47
|
|
|
|
|
|
|
ok my_application_routine(); |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 DESCRIPTION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
This module provides some testing methods for LDAP operations, such as |
53
|
|
|
|
|
|
|
C, C, and C, where each method is suffixed with either |
54
|
|
|
|
|
|
|
C<_ok> or C<_is>. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
C is a subclass of C, so all the methods defined |
57
|
|
|
|
|
|
|
for C are available in addition to C, C, etc. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
See L for in-memory testing with fake data, without |
60
|
|
|
|
|
|
|
connecting to the real LDAP servers. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
See L for some helper subroutines. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 METHODS |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 new |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Creates a new object. The parameters are the same as C. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $ldap = Test::Net::LDAP->new('ldap.example.com'); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 search_ok |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Available methods: |
79
|
|
|
|
|
|
|
C, C, |
80
|
|
|
|
|
|
|
C, C, C, C, |
81
|
|
|
|
|
|
|
C, C, C |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Synopsis: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$ldap->search_ok(@params); |
86
|
|
|
|
|
|
|
$ldap->search_ok(\@params, $name); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Invokes the corresponding method with C<@params> passed as arguments, |
89
|
|
|
|
|
|
|
and tests the result to see if the code is C. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Alternatively, C<@params> can be given as an array ref, so that the second |
92
|
|
|
|
|
|
|
argument C<$name> is specified as the test name. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
C<$name> is an optional test name, and if it is omitted, the test name is |
95
|
|
|
|
|
|
|
automatically configured based on C<$method> and C<@params>. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $search = $ldap->search_ok( |
98
|
|
|
|
|
|
|
base => 'dc=example, dc=com', scope => 'sub', filter => '(cn=*)', |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $search = $ldap->search_ok( |
102
|
|
|
|
|
|
|
[base => 'dc=example, dc=com', scope => 'sub', filter => '(cn=*)'], |
103
|
|
|
|
|
|
|
'Testing search (cn=*)' |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 search_is |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Available methods: |
111
|
|
|
|
|
|
|
C, C, |
112
|
|
|
|
|
|
|
C, C, C, C, |
113
|
|
|
|
|
|
|
C, C, C |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Synopsis: |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$ldap->search_is(\@params, $expect, $name); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Invokes the corresponding method with C<@params> passed as arguments, |
120
|
|
|
|
|
|
|
and tests the result to see if the code is equal to C<$expect>. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
C<$expect> can be a result code such as C or an object of |
123
|
|
|
|
|
|
|
C returned by LDAP operations. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
C<$name> is an optional test name, and if it is omitted, the test name is |
126
|
|
|
|
|
|
|
automatically configured based on C<$method> and C<@params>. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
use Net::LDAP::Constant qw(LDAP_ALREADY_EXISTS); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $mesg = $ldap->add_is( |
131
|
|
|
|
|
|
|
['uid=duplicate, dc=example, dc=com'], |
132
|
|
|
|
|
|
|
LDAP_ALREADY_EXISTS |
133
|
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 method_ok |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$ldap->method_ok($method, @params); |
140
|
|
|
|
|
|
|
$ldap->method_ok($method, \@params, $name); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Invokes the method as C<< $ldap->$method(@params) >> and tests the result to see |
143
|
|
|
|
|
|
|
if the code is C. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
C<$name> is an optional test name, and if it is omitted, the test name is |
146
|
|
|
|
|
|
|
automatically configured based on C<$method> and C<@params>. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 method_is |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
$ldap->method_is($method, \@params, $expect, $name); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Invokes the method as C<< $ldap->$method(@params) >> and tests the result to see |
155
|
|
|
|
|
|
|
if the code is equal to C<$expect>. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
C<$expect> can be a result code such as C or an object of |
158
|
|
|
|
|
|
|
C returned by LDAP operations. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
C<$name> is an optional test name, and if it is omitted, the test name is |
161
|
|
|
|
|
|
|
automatically configured based on C<$method> and C<@params>. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SEE ALSO |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=over 4 |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item * L |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item * L |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item * L |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item * L |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=back |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 AUTHOR |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Mahiro Ando, C<< >> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 BUGS |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
186
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
187
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 SUPPORT |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
perldoc Test::Net::LDAP |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
You can also look for information at: |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=over 4 |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item * GitHub repository (report bugs here) |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
L |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here, alternatively) |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
L |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
L |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item * CPAN Ratings |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
L |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item * Search CPAN |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
L |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=back |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Copyright 2013-2015 Mahiro Ando. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
228
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
229
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=cut |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
1; # End of Test::Net::LDAP |