|
Lines 28-34
BEGIN {
Link Here
|
| 28 |
|
28 |
|
| 29 |
my $schema = Koha::Database->schema; |
29 |
my $schema = Koha::Database->schema; |
| 30 |
my $builder = t::lib::TestBuilder->new; |
30 |
my $builder = t::lib::TestBuilder->new; |
| 31 |
my $dbh = C4::Context->dbh; |
|
|
| 32 |
|
31 |
|
| 33 |
# FIXME: SessionStorage defaults to mysql, but it seems to break transaction |
32 |
# FIXME: SessionStorage defaults to mysql, but it seems to break transaction |
| 34 |
# handling |
33 |
# handling |
|
Lines 258-271
subtest 'no_set_userenv parameter tests' => sub {
Link Here
|
| 258 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
257 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
| 259 |
$patron->set_password({ password => $password }); |
258 |
$patron->set_password({ password => $password }); |
| 260 |
|
259 |
|
| 261 |
ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
260 |
ok( checkpw( $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
| 262 |
is( C4::Context->userenv, undef, 'Userenv should be undef as required' ); |
261 |
is( C4::Context->userenv, undef, 'Userenv should be undef as required' ); |
| 263 |
C4::Context->_new_userenv('DUMMY SESSION'); |
262 |
C4::Context->_new_userenv('DUMMY SESSION'); |
| 264 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Library 1', 0, '', ''); |
263 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Library 1', 0, '', ''); |
| 265 |
is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv gives correct branch' ); |
264 |
is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv gives correct branch' ); |
| 266 |
ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
265 |
ok( checkpw( $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
| 267 |
is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is preserved if no_set_userenv is true' ); |
266 |
is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is preserved if no_set_userenv is true' ); |
| 268 |
ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 0 ), 'checkpw still returns true' ); |
267 |
ok( checkpw( $patron->userid, $password, undef, undef, 0 ), 'checkpw still returns true' ); |
| 269 |
isnt( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is overwritten if no_set_userenv is false' ); |
268 |
isnt( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is overwritten if no_set_userenv is false' ); |
| 270 |
}; |
269 |
}; |
| 271 |
|
270 |
|
|
Lines 280-294
subtest 'checkpw lockout tests' => sub {
Link Here
|
| 280 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 1 ); |
279 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 1 ); |
| 281 |
$patron->set_password({ password => $password }); |
280 |
$patron->set_password({ password => $password }); |
| 282 |
|
281 |
|
| 283 |
my ( $checkpw, undef, undef ) = checkpw( $dbh, $patron->cardnumber, $password, undef, undef, 1 ); |
282 |
my ( $checkpw, undef, undef ) = checkpw( $patron->cardnumber, $password, undef, undef, 1 ); |
| 284 |
ok( $checkpw, 'checkpw returns true with right password when logging in via cardnumber' ); |
283 |
ok( $checkpw, 'checkpw returns true with right password when logging in via cardnumber' ); |
| 285 |
( $checkpw, undef, undef ) = checkpw( $dbh, $patron->userid, "wrong_password", undef, undef, 1 ); |
284 |
( $checkpw, undef, undef ) = checkpw( $patron->userid, "wrong_password", undef, undef, 1 ); |
| 286 |
is( $checkpw, 0, 'checkpw returns false when given wrong password' ); |
285 |
is( $checkpw, 0, 'checkpw returns false when given wrong password' ); |
| 287 |
$patron = $patron->get_from_storage; |
286 |
$patron = $patron->get_from_storage; |
| 288 |
is( $patron->account_locked, 1, "Account is locked from failed login"); |
287 |
is( $patron->account_locked, 1, "Account is locked from failed login"); |
| 289 |
( $checkpw, undef, undef ) = checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ); |
288 |
( $checkpw, undef, undef ) = checkpw( $patron->userid, $password, undef, undef, 1 ); |
| 290 |
is( $checkpw, undef, 'checkpw returns undef with right password when account locked' ); |
289 |
is( $checkpw, undef, 'checkpw returns undef with right password when account locked' ); |
| 291 |
( $checkpw, undef, undef ) = checkpw( $dbh, $patron->cardnumber, $password, undef, undef, 1 ); |
290 |
( $checkpw, undef, undef ) = checkpw( $patron->cardnumber, $password, undef, undef, 1 ); |
| 292 |
is( $checkpw, undef, 'checkpw returns undefwith right password when logging in via cardnumber if account locked' ); |
291 |
is( $checkpw, undef, 'checkpw returns undefwith right password when logging in via cardnumber if account locked' ); |
| 293 |
|
292 |
|
| 294 |
}; |
293 |
}; |
|
Lines 488-494
subtest 'Check value of login_attempts in checkpw' => sub {
Link Here
|
| 488 |
$patron->password('123')->store; # yes, deliberately not hashed |
487 |
$patron->password('123')->store; # yes, deliberately not hashed |
| 489 |
|
488 |
|
| 490 |
is( $patron->account_locked, 0, 'Patron not locked' ); |
489 |
is( $patron->account_locked, 0, 'Patron not locked' ); |
| 491 |
my @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); |
490 |
my @test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); |
| 492 |
# Note: 123 will not be hashed to 123 ! |
491 |
# Note: 123 will not be hashed to 123 ! |
| 493 |
is( $test[0], 0, 'checkpw should have failed' ); |
492 |
is( $test[0], 0, 'checkpw should have failed' ); |
| 494 |
$patron->discard_changes; # refresh |
493 |
$patron->discard_changes; # refresh |
|
Lines 496-502
subtest 'Check value of login_attempts in checkpw' => sub {
Link Here
|
| 496 |
is( $patron->account_locked, 1, 'Check locked status' ); |
495 |
is( $patron->account_locked, 1, 'Check locked status' ); |
| 497 |
|
496 |
|
| 498 |
# And another try to go over the limit: different return value! |
497 |
# And another try to go over the limit: different return value! |
| 499 |
@test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); |
498 |
@test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); |
| 500 |
is( @test, 0, 'checkpw failed again and returns nothing now' ); |
499 |
is( @test, 0, 'checkpw failed again and returns nothing now' ); |
| 501 |
$patron->discard_changes; # refresh |
500 |
$patron->discard_changes; # refresh |
| 502 |
is( $patron->login_attempts, 3, 'Login attempts not increased anymore' ); |
501 |
is( $patron->login_attempts, 3, 'Login attempts not increased anymore' ); |
|
Lines 506-516
subtest 'Check value of login_attempts in checkpw' => sub {
Link Here
|
| 506 |
my $auth = Test::MockModule->new( 'C4::Auth' ); |
505 |
my $auth = Test::MockModule->new( 'C4::Auth' ); |
| 507 |
$auth->mock( 'checkpw_hash', sub { return 1; } ); # not for production :) |
506 |
$auth->mock( 'checkpw_hash', sub { return 1; } ); # not for production :) |
| 508 |
$patron->login_attempts(0)->store; |
507 |
$patron->login_attempts(0)->store; |
| 509 |
@test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); |
508 |
@test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); |
| 510 |
is( $test[0], 1, 'Build confidence in the mock' ); |
509 |
is( $test[0], 1, 'Build confidence in the mock' ); |
| 511 |
$patron->login_attempts(-1)->store; |
510 |
$patron->login_attempts(-1)->store; |
| 512 |
is( $patron->account_locked, 1, 'Check administrative lockout' ); |
511 |
is( $patron->account_locked, 1, 'Check administrative lockout' ); |
| 513 |
@test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); |
512 |
@test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); |
| 514 |
is( @test, 0, 'checkpw gave red' ); |
513 |
is( @test, 0, 'checkpw gave red' ); |
| 515 |
$patron->discard_changes; # refresh |
514 |
$patron->discard_changes; # refresh |
| 516 |
is( $patron->login_attempts, -1, 'Still locked out' ); |
515 |
is( $patron->login_attempts, -1, 'Still locked out' ); |