Lines 46-56
my $anonymous_bind = 1;
Link Here
|
46 |
# Variables controlling LDAP behaviour |
46 |
# Variables controlling LDAP behaviour |
47 |
my $desired_authentication_result = 'success'; |
47 |
my $desired_authentication_result = 'success'; |
48 |
my $desired_connection_result = 'error'; |
48 |
my $desired_connection_result = 'error'; |
49 |
my $desired_bind_result = 'error'; |
49 |
my $desired_admin_bind_result = 'error'; |
50 |
my $desired_compare_result = 'error'; |
50 |
my $desired_compare_result = 'error'; |
51 |
my $desired_search_result = 'error'; |
51 |
my $desired_search_result = 'error'; |
52 |
my $desired_count_result = 1; |
52 |
my $desired_count_result = 1; |
53 |
my $non_anonymous_bind_result = 'error'; |
53 |
my $desired_bind_result = 'error'; |
54 |
my $ret; |
54 |
my $ret; |
55 |
|
55 |
|
56 |
# Mock the context module |
56 |
# Mock the context module |
Lines 150-156
subtest 'checkpw_ldap tests' => sub {
Link Here
|
150 |
|
150 |
|
151 |
$desired_authentication_result = 'success'; |
151 |
$desired_authentication_result = 'success'; |
152 |
$anonymous_bind = 1; |
152 |
$anonymous_bind = 1; |
153 |
$desired_bind_result = 'error'; |
153 |
$desired_admin_bind_result = 'error'; |
154 |
$desired_search_result = 'error'; |
154 |
$desired_search_result = 'error'; |
155 |
reload_ldap_module(); |
155 |
reload_ldap_module(); |
156 |
|
156 |
|
Lines 164-173
subtest 'checkpw_ldap tests' => sub {
Link Here
|
164 |
|
164 |
|
165 |
$desired_authentication_result = 'success'; |
165 |
$desired_authentication_result = 'success'; |
166 |
$anonymous_bind = 1; |
166 |
$anonymous_bind = 1; |
167 |
$desired_bind_result = 'success'; |
167 |
$desired_admin_bind_result = 'success'; |
168 |
$desired_search_result = 'success'; |
168 |
$desired_search_result = 'success'; |
169 |
$desired_count_result = 1; |
169 |
$desired_count_result = 1; |
170 |
$non_anonymous_bind_result = 'success'; |
170 |
$desired_bind_result = 'success'; |
171 |
$update = 1; |
171 |
$update = 1; |
172 |
reload_ldap_module(); |
172 |
reload_ldap_module(); |
173 |
|
173 |
|
Lines 212-218
subtest 'checkpw_ldap tests' => sub {
Link Here
|
212 |
'checkpw_ldap returns 0 if user lookup returns 0' |
212 |
'checkpw_ldap returns 0 if user lookup returns 0' |
213 |
); |
213 |
); |
214 |
|
214 |
|
215 |
$non_anonymous_bind_result = 'error'; |
215 |
$desired_bind_result = 'error'; |
216 |
reload_ldap_module(); |
216 |
reload_ldap_module(); |
217 |
|
217 |
|
218 |
warning_like { |
218 |
warning_like { |
Lines 227-236
subtest 'checkpw_ldap tests' => sub {
Link Here
|
227 |
# regression tests for bug 12831 |
227 |
# regression tests for bug 12831 |
228 |
$desired_authentication_result = 'error'; |
228 |
$desired_authentication_result = 'error'; |
229 |
$anonymous_bind = 0; |
229 |
$anonymous_bind = 0; |
230 |
$desired_bind_result = 'error'; |
230 |
$desired_admin_bind_result = 'error'; |
231 |
$desired_search_result = 'success'; |
231 |
$desired_search_result = 'success'; |
232 |
$desired_count_result = 0; # user auth problem |
232 |
$desired_count_result = 0; # user auth problem |
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 252-259
subtest 'checkpw_ldap tests' => sub {
Link Here
|
252 |
|
252 |
|
253 |
# Anonymous bind |
253 |
# Anonymous bind |
254 |
$anonymous_bind = 1; |
254 |
$anonymous_bind = 1; |
255 |
$desired_bind_result = 'error'; |
255 |
$desired_admin_bind_result = 'error'; |
256 |
$non_anonymous_bind_result = 'error'; |
256 |
$desired_bind_result = 'error'; |
257 |
reload_ldap_module(); |
257 |
reload_ldap_module(); |
258 |
|
258 |
|
259 |
warning_like { |
259 |
warning_like { |
Lines 265-273
qr/LDAP bind failed as ldapuser cn=Manager,dc=metavore,dc=com: LDAP error #1: er
Link Here
|
265 |
is( $ret, 0, 'checkpw_ldap returns 0 if bind fails' ); |
265 |
is( $ret, 0, 'checkpw_ldap returns 0 if bind fails' ); |
266 |
|
266 |
|
267 |
$anonymous_bind = 1; |
267 |
$anonymous_bind = 1; |
268 |
$desired_bind_result = 'success'; |
268 |
$desired_admin_bind_result = 'success'; |
269 |
$non_anonymous_bind_result = 'success'; |
269 |
$desired_bind_result = 'error'; |
270 |
$desired_compare_result = 'error'; |
|
|
271 |
reload_ldap_module(); |
270 |
reload_ldap_module(); |
272 |
|
271 |
|
273 |
warning_like { |
272 |
warning_like { |
Lines 280-288
qr/LDAP Auth rejected : invalid password for user 'hola'. LDAP error #1: error_n
Link Here
|
280 |
|
279 |
|
281 |
# Non-anonymous bind |
280 |
# Non-anonymous bind |
282 |
$anonymous_bind = 0; |
281 |
$anonymous_bind = 0; |
283 |
$desired_bind_result = 'success'; |
282 |
$desired_admin_bind_result = 'error'; |
284 |
$non_anonymous_bind_result = 'error'; |
283 |
$desired_bind_result = 'error'; |
285 |
$desired_compare_result = 'dont care'; |
|
|
286 |
reload_ldap_module(); |
284 |
reload_ldap_module(); |
287 |
|
285 |
|
288 |
warning_like { |
286 |
warning_like { |
Lines 294-302
qr/LDAP bind failed as ldapuser cn=Manager,dc=metavore,dc=com: LDAP error #1: er
Link Here
|
294 |
is( $ret, 0, 'checkpw_ldap returns 0 if bind fails' ); |
292 |
is( $ret, 0, 'checkpw_ldap returns 0 if bind fails' ); |
295 |
|
293 |
|
296 |
$anonymous_bind = 0; |
294 |
$anonymous_bind = 0; |
297 |
$desired_bind_result = 'success'; |
295 |
$desired_admin_bind_result = 'success'; |
298 |
$non_anonymous_bind_result = 'success'; |
296 |
$desired_bind_result = 'error'; |
299 |
$desired_compare_result = 'error'; |
|
|
300 |
reload_ldap_module(); |
297 |
reload_ldap_module(); |
301 |
|
298 |
|
302 |
warning_like { |
299 |
warning_like { |
Lines 394-452
sub mock_net_ldap {
Link Here
|
394 |
|
391 |
|
395 |
my $mocked_ldap = Test::MockObject->new(); |
392 |
my $mocked_ldap = Test::MockObject->new(); |
396 |
|
393 |
|
397 |
$mocked_ldap->mock( |
394 |
$mocked_ldap->mock( 'bind', sub { |
398 |
'bind', |
395 |
if (is_admin_bind(@_)) { |
399 |
sub { |
396 |
return mock_net_ldap_message( |
400 |
|
397 |
($desired_admin_bind_result eq 'error' ) ? 1 : 0, # code |
401 |
my @args = @_; |
398 |
($desired_admin_bind_result eq 'error' ) ? 1 : 0, # error |
402 |
my $mocked_message; |
399 |
($desired_admin_bind_result eq 'error' ) ? 'error_name' : 0, # error_name |
403 |
|
400 |
($desired_admin_bind_result eq 'error' ) ? 'error_text' : 0 # error_text |
404 |
if ( $#args > 1 ) { |
401 |
); |
405 |
|
|
|
406 |
# Args passed => non-anonymous bind |
407 |
if ( $non_anonymous_bind_result eq 'error' ) { |
408 |
return mock_net_ldap_message( 1, 1, 'error_name', |
409 |
'error_text' ); |
410 |
} |
411 |
else { |
412 |
return mock_net_ldap_message( 0, 0, q{}, q{} ); |
413 |
} |
414 |
} |
415 |
else { |
416 |
$mocked_message = mock_net_ldap_message( |
417 |
( $desired_bind_result eq 'error' ) ? 1 : 0, # code |
418 |
( $desired_bind_result eq 'error' ) ? 1 : 0, # error |
419 |
( $desired_bind_result eq 'error' ) |
420 |
? 'error_name' |
421 |
: 0, # error_name |
422 |
( $desired_bind_result eq 'error' ) |
423 |
? 'error_text' |
424 |
: 0 # error_text |
425 |
); |
426 |
} |
427 |
|
428 |
return $mocked_message; |
429 |
} |
402 |
} |
430 |
); |
403 |
else { |
431 |
|
404 |
if ( $desired_bind_result eq 'error' ) { |
432 |
$mocked_ldap->mock( |
405 |
return mock_net_ldap_message(1,1,'error_name','error_text'); |
433 |
'compare', |
|
|
434 |
sub { |
435 |
|
436 |
my $mocked_message; |
437 |
|
438 |
if ( $desired_compare_result eq 'error' ) { |
439 |
$mocked_message = |
440 |
mock_net_ldap_message( 1, 1, 'error_name', 'error_text' ); |
441 |
} |
442 |
else { |
443 |
# we expect return code 6 for success |
444 |
$mocked_message = mock_net_ldap_message( 6, 0, q{}, q{} ); |
445 |
} |
406 |
} |
446 |
|
407 |
return mock_net_ldap_message(0,0,'',''); |
447 |
return $mocked_message; |
|
|
448 |
} |
408 |
} |
449 |
); |
409 |
}); |
450 |
|
410 |
|
451 |
$mocked_ldap->mock( |
411 |
$mocked_ldap->mock( |
452 |
'search', |
412 |
'search', |
Lines 531-536
sub reload_ldap_module {
Link Here
|
531 |
return; |
491 |
return; |
532 |
} |
492 |
} |
533 |
|
493 |
|
534 |
$schema->storage->txn_rollback(); |
494 |
sub is_admin_bind { |
|
|
495 |
my @args = @_; |
496 |
|
497 |
if ($#args <= 1 || $args[1] eq 'cn=Manager,dc=metavore,dc=com') { |
498 |
return 1; |
499 |
} |
500 |
|
501 |
return 0; |
502 |
} |
503 |
|
504 |
$schema->storage->txn_rollback; |
535 |
|
505 |
|
536 |
1; |
506 |
1; |
537 |
- |
|
|