Lines 44-54
my $anonymous_bind = 1;
Link Here
|
44 |
# Variables controlling LDAP behaviour |
44 |
# Variables controlling LDAP behaviour |
45 |
my $desired_authentication_result = 'success'; |
45 |
my $desired_authentication_result = 'success'; |
46 |
my $desired_connection_result = 'error'; |
46 |
my $desired_connection_result = 'error'; |
47 |
my $desired_bind_result = 'error'; |
47 |
my $desired_admin_bind_result = 'error'; |
48 |
my $desired_compare_result = 'error'; |
48 |
my $desired_compare_result = 'error'; |
49 |
my $desired_search_result = 'error'; |
49 |
my $desired_search_result = 'error'; |
50 |
my $desired_count_result = 1; |
50 |
my $desired_count_result = 1; |
51 |
my $non_anonymous_bind_result = 'error'; |
51 |
my $desired_bind_result = 'error'; |
52 |
my $ret; |
52 |
my $ret; |
53 |
|
53 |
|
54 |
# Mock the context module |
54 |
# Mock the context module |
Lines 139-145
subtest 'checkpw_ldap tests' => sub {
Link Here
|
139 |
|
139 |
|
140 |
$desired_authentication_result = 'success'; |
140 |
$desired_authentication_result = 'success'; |
141 |
$anonymous_bind = 1; |
141 |
$anonymous_bind = 1; |
142 |
$desired_bind_result = 'error'; |
142 |
$desired_admin_bind_result = 'error'; |
143 |
$desired_search_result = 'error'; |
143 |
$desired_search_result = 'error'; |
144 |
reload_ldap_module(); |
144 |
reload_ldap_module(); |
145 |
|
145 |
|
Lines 153-162
subtest 'checkpw_ldap tests' => sub {
Link Here
|
153 |
|
153 |
|
154 |
$desired_authentication_result = 'success'; |
154 |
$desired_authentication_result = 'success'; |
155 |
$anonymous_bind = 1; |
155 |
$anonymous_bind = 1; |
156 |
$desired_bind_result = 'success'; |
156 |
$desired_admin_bind_result = 'success'; |
157 |
$desired_search_result = 'success'; |
157 |
$desired_search_result = 'success'; |
158 |
$desired_count_result = 1; |
158 |
$desired_count_result = 1; |
159 |
$non_anonymous_bind_result = 'success'; |
159 |
$desired_bind_result = 'success'; |
160 |
$update = 1; |
160 |
$update = 1; |
161 |
reload_ldap_module(); |
161 |
reload_ldap_module(); |
162 |
|
162 |
|
Lines 189-195
subtest 'checkpw_ldap tests' => sub {
Link Here
|
189 |
'checkpw_ldap returns 0 if user lookup returns 0' |
189 |
'checkpw_ldap returns 0 if user lookup returns 0' |
190 |
); |
190 |
); |
191 |
|
191 |
|
192 |
$non_anonymous_bind_result = 'error'; |
192 |
$desired_bind_result = 'error'; |
193 |
reload_ldap_module(); |
193 |
reload_ldap_module(); |
194 |
|
194 |
|
195 |
warning_like { |
195 |
warning_like { |
Lines 204-213
subtest 'checkpw_ldap tests' => sub {
Link Here
|
204 |
# regression tests for bug 12831 |
204 |
# regression tests for bug 12831 |
205 |
$desired_authentication_result = 'error'; |
205 |
$desired_authentication_result = 'error'; |
206 |
$anonymous_bind = 0; |
206 |
$anonymous_bind = 0; |
207 |
$desired_bind_result = 'error'; |
207 |
$desired_admin_bind_result = 'error'; |
208 |
$desired_search_result = 'success'; |
208 |
$desired_search_result = 'success'; |
209 |
$desired_count_result = 0; # user auth problem |
209 |
$desired_count_result = 0; # user auth problem |
210 |
$non_anonymous_bind_result = 'error'; |
210 |
$desired_bind_result = 'error'; |
211 |
reload_ldap_module(); |
211 |
reload_ldap_module(); |
212 |
|
212 |
|
213 |
warning_like { |
213 |
warning_like { |
Lines 229-236
subtest 'checkpw_ldap tests' => sub {
Link Here
|
229 |
|
229 |
|
230 |
# Anonymous bind |
230 |
# Anonymous bind |
231 |
$anonymous_bind = 1; |
231 |
$anonymous_bind = 1; |
232 |
$desired_bind_result = 'error'; |
232 |
$desired_admin_bind_result = 'error'; |
233 |
$non_anonymous_bind_result = 'error'; |
233 |
$desired_bind_result = 'error'; |
234 |
reload_ldap_module(); |
234 |
reload_ldap_module(); |
235 |
|
235 |
|
236 |
warning_like { |
236 |
warning_like { |
Lines 242-250
qr/LDAP bind failed as ldapuser cn=Manager,dc=metavore,dc=com: LDAP error #1: er
Link Here
|
242 |
is( $ret, 0, 'checkpw_ldap returns 0 if bind fails' ); |
242 |
is( $ret, 0, 'checkpw_ldap returns 0 if bind fails' ); |
243 |
|
243 |
|
244 |
$anonymous_bind = 1; |
244 |
$anonymous_bind = 1; |
245 |
$desired_bind_result = 'success'; |
245 |
$desired_admin_bind_result = 'success'; |
246 |
$non_anonymous_bind_result = 'success'; |
246 |
$desired_bind_result = 'error'; |
247 |
$desired_compare_result = 'error'; |
|
|
248 |
reload_ldap_module(); |
247 |
reload_ldap_module(); |
249 |
|
248 |
|
250 |
warning_like { |
249 |
warning_like { |
Lines 257-265
qr/LDAP Auth rejected : invalid password for user 'hola'. LDAP error #1: error_n
Link Here
|
257 |
|
256 |
|
258 |
# Non-anonymous bind |
257 |
# Non-anonymous bind |
259 |
$anonymous_bind = 0; |
258 |
$anonymous_bind = 0; |
260 |
$desired_bind_result = 'success'; |
259 |
$desired_admin_bind_result = 'error'; |
261 |
$non_anonymous_bind_result = 'error'; |
260 |
$desired_bind_result = 'error'; |
262 |
$desired_compare_result = 'dont care'; |
|
|
263 |
reload_ldap_module(); |
261 |
reload_ldap_module(); |
264 |
|
262 |
|
265 |
warning_like { |
263 |
warning_like { |
Lines 271-279
qr/LDAP bind failed as ldapuser cn=Manager,dc=metavore,dc=com: LDAP error #1: er
Link Here
|
271 |
is( $ret, 0, 'checkpw_ldap returns 0 if bind fails' ); |
269 |
is( $ret, 0, 'checkpw_ldap returns 0 if bind fails' ); |
272 |
|
270 |
|
273 |
$anonymous_bind = 0; |
271 |
$anonymous_bind = 0; |
274 |
$desired_bind_result = 'success'; |
272 |
$desired_admin_bind_result = 'success'; |
275 |
$non_anonymous_bind_result = 'success'; |
273 |
$desired_bind_result = 'error'; |
276 |
$desired_compare_result = 'error'; |
|
|
277 |
reload_ldap_module(); |
274 |
reload_ldap_module(); |
278 |
|
275 |
|
279 |
warning_like { |
276 |
warning_like { |
Lines 371-429
sub mock_net_ldap {
Link Here
|
371 |
|
368 |
|
372 |
my $mocked_ldap = Test::MockObject->new(); |
369 |
my $mocked_ldap = Test::MockObject->new(); |
373 |
|
370 |
|
374 |
$mocked_ldap->mock( |
371 |
$mocked_ldap->mock( 'bind', sub { |
375 |
'bind', |
372 |
if (is_admin_bind(@_)) { |
376 |
sub { |
373 |
return mock_net_ldap_message( |
377 |
|
374 |
($desired_admin_bind_result eq 'error' ) ? 1 : 0, # code |
378 |
my @args = @_; |
375 |
($desired_admin_bind_result eq 'error' ) ? 1 : 0, # error |
379 |
my $mocked_message; |
376 |
($desired_admin_bind_result eq 'error' ) ? 'error_name' : 0, # error_name |
380 |
|
377 |
($desired_admin_bind_result eq 'error' ) ? 'error_text' : 0 # error_text |
381 |
if ( $#args > 1 ) { |
378 |
); |
382 |
|
|
|
383 |
# Args passed => non-anonymous bind |
384 |
if ( $non_anonymous_bind_result eq 'error' ) { |
385 |
return mock_net_ldap_message( 1, 1, 'error_name', |
386 |
'error_text' ); |
387 |
} |
388 |
else { |
389 |
return mock_net_ldap_message( 0, 0, q{}, q{} ); |
390 |
} |
391 |
} |
392 |
else { |
393 |
$mocked_message = mock_net_ldap_message( |
394 |
( $desired_bind_result eq 'error' ) ? 1 : 0, # code |
395 |
( $desired_bind_result eq 'error' ) ? 1 : 0, # error |
396 |
( $desired_bind_result eq 'error' ) |
397 |
? 'error_name' |
398 |
: 0, # error_name |
399 |
( $desired_bind_result eq 'error' ) |
400 |
? 'error_text' |
401 |
: 0 # error_text |
402 |
); |
403 |
} |
404 |
|
405 |
return $mocked_message; |
406 |
} |
379 |
} |
407 |
); |
380 |
else { |
408 |
|
381 |
if ( $desired_bind_result eq 'error' ) { |
409 |
$mocked_ldap->mock( |
382 |
return mock_net_ldap_message(1,1,'error_name','error_text'); |
410 |
'compare', |
|
|
411 |
sub { |
412 |
|
413 |
my $mocked_message; |
414 |
|
415 |
if ( $desired_compare_result eq 'error' ) { |
416 |
$mocked_message = |
417 |
mock_net_ldap_message( 1, 1, 'error_name', 'error_text' ); |
418 |
} |
419 |
else { |
420 |
# we expect return code 6 for success |
421 |
$mocked_message = mock_net_ldap_message( 6, 0, q{}, q{} ); |
422 |
} |
383 |
} |
423 |
|
384 |
return mock_net_ldap_message(0,0,'',''); |
424 |
return $mocked_message; |
|
|
425 |
} |
385 |
} |
426 |
); |
386 |
}); |
427 |
|
387 |
|
428 |
$mocked_ldap->mock( |
388 |
$mocked_ldap->mock( |
429 |
'search', |
389 |
'search', |
Lines 508-513
sub reload_ldap_module {
Link Here
|
508 |
return; |
468 |
return; |
509 |
} |
469 |
} |
510 |
|
470 |
|
|
|
471 |
sub is_admin_bind { |
472 |
my @args = @_; |
473 |
|
474 |
if ($#args <= 1 || $args[1] eq 'cn=Manager,dc=metavore,dc=com') { |
475 |
return 1; |
476 |
} |
477 |
|
478 |
return 0; |
479 |
} |
480 |
|
511 |
$dbh->rollback; |
481 |
$dbh->rollback; |
512 |
|
482 |
|
513 |
1; |
483 |
1; |
514 |
- |
|
|