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