Lines 26-32
BEGIN {
Link Here
|
26 |
|
26 |
|
27 |
my $schema = Koha::Database->schema; |
27 |
my $schema = Koha::Database->schema; |
28 |
my $builder = t::lib::TestBuilder->new; |
28 |
my $builder = t::lib::TestBuilder->new; |
29 |
my $dbh = C4::Context->dbh; |
|
|
30 |
|
29 |
|
31 |
# FIXME: SessionStorage defaults to mysql, but it seems to break transaction |
30 |
# FIXME: SessionStorage defaults to mysql, but it seems to break transaction |
32 |
# handling |
31 |
# handling |
Lines 164-177
subtest 'no_set_userenv parameter tests' => sub {
Link Here
|
164 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
163 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
165 |
$patron->set_password({ password => $password }); |
164 |
$patron->set_password({ password => $password }); |
166 |
|
165 |
|
167 |
ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
166 |
ok( checkpw( $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
168 |
is( C4::Context->userenv, undef, 'Userenv should be undef as required' ); |
167 |
is( C4::Context->userenv, undef, 'Userenv should be undef as required' ); |
169 |
C4::Context->_new_userenv('DUMMY SESSION'); |
168 |
C4::Context->_new_userenv('DUMMY SESSION'); |
170 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Library 1', 0, '', ''); |
169 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Library 1', 0, '', ''); |
171 |
is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv gives correct branch' ); |
170 |
is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv gives correct branch' ); |
172 |
ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
171 |
ok( checkpw( $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
173 |
is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is preserved if no_set_userenv is true' ); |
172 |
is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is preserved if no_set_userenv is true' ); |
174 |
ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 0 ), 'checkpw still returns true' ); |
173 |
ok( checkpw( $patron->userid, $password, undef, undef, 0 ), 'checkpw still returns true' ); |
175 |
isnt( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is overwritten if no_set_userenv is false' ); |
174 |
isnt( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is overwritten if no_set_userenv is false' ); |
176 |
}; |
175 |
}; |
177 |
|
176 |
|
Lines 186-200
subtest 'checkpw lockout tests' => sub {
Link Here
|
186 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 1 ); |
185 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 1 ); |
187 |
$patron->set_password({ password => $password }); |
186 |
$patron->set_password({ password => $password }); |
188 |
|
187 |
|
189 |
my ( $checkpw, undef, undef ) = checkpw( $dbh, $patron->cardnumber, $password, undef, undef, 1 ); |
188 |
my ( $checkpw, undef, undef ) = checkpw( $patron->cardnumber, $password, undef, undef, 1 ); |
190 |
ok( $checkpw, 'checkpw returns true with right password when logging in via cardnumber' ); |
189 |
ok( $checkpw, 'checkpw returns true with right password when logging in via cardnumber' ); |
191 |
( $checkpw, undef, undef ) = checkpw( $dbh, $patron->userid, "wrong_password", undef, undef, 1 ); |
190 |
( $checkpw, undef, undef ) = checkpw( $patron->userid, "wrong_password", undef, undef, 1 ); |
192 |
is( $checkpw, 0, 'checkpw returns false when given wrong password' ); |
191 |
is( $checkpw, 0, 'checkpw returns false when given wrong password' ); |
193 |
$patron = $patron->get_from_storage; |
192 |
$patron = $patron->get_from_storage; |
194 |
is( $patron->account_locked, 1, "Account is locked from failed login"); |
193 |
is( $patron->account_locked, 1, "Account is locked from failed login"); |
195 |
( $checkpw, undef, undef ) = checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ); |
194 |
( $checkpw, undef, undef ) = checkpw( $patron->userid, $password, undef, undef, 1 ); |
196 |
is( $checkpw, undef, 'checkpw returns undef with right password when account locked' ); |
195 |
is( $checkpw, undef, 'checkpw returns undef with right password when account locked' ); |
197 |
( $checkpw, undef, undef ) = checkpw( $dbh, $patron->cardnumber, $password, undef, undef, 1 ); |
196 |
( $checkpw, undef, undef ) = checkpw( $patron->cardnumber, $password, undef, undef, 1 ); |
198 |
is( $checkpw, undef, 'checkpw returns undefwith right password when logging in via cardnumber if account locked' ); |
197 |
is( $checkpw, undef, 'checkpw returns undefwith right password when logging in via cardnumber if account locked' ); |
199 |
|
198 |
|
200 |
}; |
199 |
}; |
Lines 392-398
subtest 'Check value of login_attempts in checkpw' => sub {
Link Here
|
392 |
$patron->password('123')->store; # yes, deliberately not hashed |
391 |
$patron->password('123')->store; # yes, deliberately not hashed |
393 |
|
392 |
|
394 |
is( $patron->account_locked, 0, 'Patron not locked' ); |
393 |
is( $patron->account_locked, 0, 'Patron not locked' ); |
395 |
my @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); |
394 |
my @test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); |
396 |
# Note: 123 will not be hashed to 123 ! |
395 |
# Note: 123 will not be hashed to 123 ! |
397 |
is( $test[0], 0, 'checkpw should have failed' ); |
396 |
is( $test[0], 0, 'checkpw should have failed' ); |
398 |
$patron->discard_changes; # refresh |
397 |
$patron->discard_changes; # refresh |
Lines 400-406
subtest 'Check value of login_attempts in checkpw' => sub {
Link Here
|
400 |
is( $patron->account_locked, 1, 'Check locked status' ); |
399 |
is( $patron->account_locked, 1, 'Check locked status' ); |
401 |
|
400 |
|
402 |
# And another try to go over the limit: different return value! |
401 |
# And another try to go over the limit: different return value! |
403 |
@test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); |
402 |
@test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); |
404 |
is( @test, 0, 'checkpw failed again and returns nothing now' ); |
403 |
is( @test, 0, 'checkpw failed again and returns nothing now' ); |
405 |
$patron->discard_changes; # refresh |
404 |
$patron->discard_changes; # refresh |
406 |
is( $patron->login_attempts, 3, 'Login attempts not increased anymore' ); |
405 |
is( $patron->login_attempts, 3, 'Login attempts not increased anymore' ); |
Lines 410-420
subtest 'Check value of login_attempts in checkpw' => sub {
Link Here
|
410 |
my $auth = Test::MockModule->new( 'C4::Auth' ); |
409 |
my $auth = Test::MockModule->new( 'C4::Auth' ); |
411 |
$auth->mock( 'checkpw_hash', sub { return 1; } ); # not for production :) |
410 |
$auth->mock( 'checkpw_hash', sub { return 1; } ); # not for production :) |
412 |
$patron->login_attempts(0)->store; |
411 |
$patron->login_attempts(0)->store; |
413 |
@test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); |
412 |
@test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); |
414 |
is( $test[0], 1, 'Build confidence in the mock' ); |
413 |
is( $test[0], 1, 'Build confidence in the mock' ); |
415 |
$patron->login_attempts(-1)->store; |
414 |
$patron->login_attempts(-1)->store; |
416 |
is( $patron->account_locked, 1, 'Check administrative lockout' ); |
415 |
is( $patron->account_locked, 1, 'Check administrative lockout' ); |
417 |
@test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); |
416 |
@test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); |
418 |
is( @test, 0, 'checkpw gave red' ); |
417 |
is( @test, 0, 'checkpw gave red' ); |
419 |
$patron->discard_changes; # refresh |
418 |
$patron->discard_changes; # refresh |
420 |
is( $patron->login_attempts, -1, 'Still locked out' ); |
419 |
is( $patron->login_attempts, -1, 'Still locked out' ); |