line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
14
|
|
|
14
|
|
157110
|
use 5.006; |
|
14
|
|
|
|
|
37
|
|
|
14
|
|
|
|
|
490
|
|
2
|
14
|
|
|
14
|
|
66
|
use strict; |
|
14
|
|
|
|
|
17
|
|
|
14
|
|
|
|
|
446
|
|
3
|
14
|
|
|
14
|
|
59
|
use warnings; |
|
14
|
|
|
|
|
16
|
|
|
14
|
|
|
|
|
525
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Test::Net::LDAP::Util; |
6
|
14
|
|
|
14
|
|
56
|
use base 'Exporter'; |
|
14
|
|
|
|
|
15
|
|
|
14
|
|
|
|
|
1356
|
|
7
|
14
|
|
|
14
|
|
58
|
use Net::LDAP; |
|
14
|
|
|
|
|
22
|
|
|
14
|
|
|
|
|
68
|
|
8
|
14
|
|
|
14
|
|
643
|
use Net::LDAP::Constant qw(LDAP_SUCCESS); |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
634
|
|
9
|
14
|
|
|
14
|
|
33908
|
use Net::LDAP::Util qw(ldap_error_name ldap_error_text canonical_dn); |
|
14
|
|
|
|
|
743
|
|
|
14
|
|
|
|
|
967
|
|
10
|
14
|
|
|
14
|
|
66
|
use Test::Builder; |
|
14
|
|
|
|
|
15
|
|
|
14
|
|
|
|
|
6602
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
ldap_result_ok |
14
|
|
|
|
|
|
|
ldap_result_is |
15
|
|
|
|
|
|
|
ldap_mockify |
16
|
|
|
|
|
|
|
ldap_dn_is |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => \@EXPORT_OK); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 NAME |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Test::Net::LDAP::Util - Testing utilities for Test::Net::LDAP |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 EXPORT |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
The following subroutines are exported on demand. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use Test::Net::LDAP::Util qw( |
32
|
|
|
|
|
|
|
ldap_result_ok |
33
|
|
|
|
|
|
|
ldap_result_is |
34
|
|
|
|
|
|
|
ldap_mockify |
35
|
|
|
|
|
|
|
ldap_dn_is |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
All the subroutines are exported if C<:all> is specified. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
use Test::Net::LDAP::Util ':all'; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SUBROUTINES |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _format_diag { |
49
|
2
|
|
|
2
|
|
3
|
my ($actual_text, $expected_text) = @_; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Indent spaces are based on Test::Builder::_is_diag implementation |
52
|
|
|
|
|
|
|
# ($Test::Builder::VERSION == 0.98) |
53
|
2
|
|
|
|
|
48
|
return sprintf("%12s: %s\n", 'got', $actual_text). |
54
|
|
|
|
|
|
|
sprintf("%12s: %s\n", 'expected', $expected_text); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 ldap_result_ok |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
ldap_result_ok($mesg, $name); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Tests the result of an LDAP operation to see if the code is C. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
C<$mesg> is either a Net::LDAP::Message object returned by LDAP operation |
64
|
|
|
|
|
|
|
methods or a result code. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
C<$name> is the optional test name. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub ldap_result_ok { |
71
|
2
|
|
|
2
|
1
|
62
|
my ($mesg, $name) = @_; |
72
|
2
|
|
|
|
|
6
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
73
|
2
|
|
|
|
|
8
|
return ldap_result_is($mesg, LDAP_SUCCESS, $name); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 ldap_result_is |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
ldap_result_is($mesg, $expect, $name); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Tests the result of an LDAP operation to see if the code is equal to C<$expect>. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
The values of C<$mesg> and C<$expect> are either a Net::LDAP::Message object |
83
|
|
|
|
|
|
|
returned by LDAP operation methods or a result code. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
C<$name> is the optional test name. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $test_builder; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub ldap_result_is { |
92
|
154
|
|
|
154
|
1
|
241
|
my ($actual, $expected, $name) = @_; |
93
|
154
|
50
|
|
|
|
336
|
$expected = LDAP_SUCCESS unless defined $expected; |
94
|
|
|
|
|
|
|
|
95
|
154
|
|
66
|
|
|
374
|
$test_builder ||= Test::Builder->new; |
96
|
|
|
|
|
|
|
|
97
|
154
|
100
|
|
|
|
758
|
my $actual_code = ref $actual ? $actual->code : $actual; |
98
|
154
|
50
|
|
|
|
944
|
my $expected_code = ref $expected ? $expected->code : $expected; |
99
|
154
|
|
|
|
|
263
|
my $success = ($actual_code == $expected_code); |
100
|
|
|
|
|
|
|
|
101
|
154
|
|
|
|
|
181
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
102
|
154
|
|
|
|
|
408
|
$test_builder->ok($success, $name); |
103
|
|
|
|
|
|
|
|
104
|
154
|
100
|
|
|
|
40147
|
unless ($success) { |
105
|
2
|
|
33
|
|
|
8
|
my $actual_text = ldap_error_name($actual).' ('.$actual_code.'): '. |
106
|
|
|
|
|
|
|
((ref $actual && $actual->error) || ldap_error_text($actual)); |
107
|
|
|
|
|
|
|
|
108
|
2
|
|
|
|
|
88
|
my $expected_text = ldap_error_name($expected).' ('.$expected_code.')'; |
109
|
|
|
|
|
|
|
|
110
|
2
|
|
|
|
|
14
|
$test_builder->diag(_format_diag($actual_text, $expected_text)); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
154
|
|
|
|
|
365
|
return $actual; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 ldap_mockify |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
ldap_mockify { |
119
|
|
|
|
|
|
|
# CODE |
120
|
|
|
|
|
|
|
}; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Inside the code block, all the occurrences of C are replaced by |
123
|
|
|
|
|
|
|
C. |
124
|
|
|
|
|
|
|
See L for more details. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub ldap_mockify(&) { |
129
|
3
|
|
|
3
|
1
|
123
|
my ($callback) = @_; |
130
|
3
|
|
|
|
|
574
|
require Test::Net::LDAP::Mock; |
131
|
3
|
|
|
|
|
18
|
local *Net::LDAP::new = *Test::Net::LDAP::Mock::new; |
132
|
3
|
|
|
|
|
8
|
$callback->(); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 ldap_dn_is |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
ldap_dn_is($actual_dn, $expect_dn, $name); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Tests equality of two DNs that are not necessarily canonicalized. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
The comparison is case-insensitive. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub ldap_dn_is { |
146
|
52
|
|
|
52
|
1
|
19517
|
my ($actual_dn, $expected_dn, $name) = @_; |
147
|
52
|
|
|
|
|
96
|
my ($actual_canonical_dn, $expected_canonical_dn) = ($actual_dn, $expected_dn); |
148
|
|
|
|
|
|
|
|
149
|
52
|
|
|
|
|
124
|
for my $dn ($actual_canonical_dn, $expected_canonical_dn) { |
150
|
104
|
50
|
|
|
|
7444
|
$dn = lc canonical_dn($dn, casefold => 'none') if defined $dn; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
52
|
|
|
|
|
6159
|
my $success; |
154
|
|
|
|
|
|
|
|
155
|
52
|
50
|
|
|
|
108
|
if (defined $actual_dn) { |
156
|
52
|
50
|
|
|
|
84
|
if (defined $expected_dn) { |
157
|
52
|
|
|
|
|
89
|
$success = $actual_canonical_dn eq $expected_canonical_dn; |
158
|
|
|
|
|
|
|
} else { |
159
|
0
|
|
|
|
|
0
|
$success = 0; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} else { |
162
|
0
|
|
|
|
|
0
|
$success = !defined $expected_dn; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
52
|
|
|
|
|
79
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
166
|
52
|
|
33
|
|
|
113
|
$test_builder ||= Test::Builder->new; |
167
|
52
|
|
|
|
|
159
|
$test_builder->ok($success, $name); |
168
|
|
|
|
|
|
|
|
169
|
52
|
50
|
|
|
|
14358
|
unless ($success) { |
170
|
0
|
|
|
|
|
|
my ($actual_text, $expected_text) = ($actual_dn, $expected_dn); |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
for my $text ($actual_text, $expected_text) { |
173
|
0
|
0
|
|
|
|
|
$text = defined $text ? "'$text'" : 'undef'; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
$test_builder->diag(_format_diag($actual_text, $expected_text)); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; |