Lines 27-33
BEGIN {
Link Here
|
27 |
|
27 |
|
28 |
my $schema = Koha::Database->schema; |
28 |
my $schema = Koha::Database->schema; |
29 |
my $builder = t::lib::TestBuilder->new; |
29 |
my $builder = t::lib::TestBuilder->new; |
30 |
my $dbh = C4::Context->dbh; |
|
|
31 |
|
30 |
|
32 |
# FIXME: SessionStorage defaults to mysql, but it seems to break transaction |
31 |
# FIXME: SessionStorage defaults to mysql, but it seems to break transaction |
33 |
# handling |
32 |
# handling |
Lines 133-146
subtest 'no_set_userenv parameter tests' => sub {
Link Here
|
133 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
132 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
134 |
$patron->set_password({ password => $password }); |
133 |
$patron->set_password({ password => $password }); |
135 |
|
134 |
|
136 |
ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
135 |
ok( checkpw( $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
137 |
is( C4::Context->userenv, undef, 'Userenv should be undef as required' ); |
136 |
is( C4::Context->userenv, undef, 'Userenv should be undef as required' ); |
138 |
C4::Context->_new_userenv('DUMMY SESSION'); |
137 |
C4::Context->_new_userenv('DUMMY SESSION'); |
139 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Library 1', 0, '', ''); |
138 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Library 1', 0, '', ''); |
140 |
is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv gives correct branch' ); |
139 |
is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv gives correct branch' ); |
141 |
ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
140 |
ok( checkpw( $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
142 |
is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is preserved if no_set_userenv is true' ); |
141 |
is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is preserved if no_set_userenv is true' ); |
143 |
ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 0 ), 'checkpw still returns true' ); |
142 |
ok( checkpw( $patron->userid, $password, undef, undef, 0 ), 'checkpw still returns true' ); |
144 |
isnt( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is overwritten if no_set_userenv is false' ); |
143 |
isnt( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is overwritten if no_set_userenv is false' ); |
145 |
}; |
144 |
}; |
146 |
|
145 |
|
Lines 155-169
subtest 'checkpw lockout tests' => sub {
Link Here
|
155 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 1 ); |
154 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 1 ); |
156 |
$patron->set_password({ password => $password }); |
155 |
$patron->set_password({ password => $password }); |
157 |
|
156 |
|
158 |
my ( $checkpw, undef, undef ) = checkpw( $dbh, $patron->cardnumber, $password, undef, undef, 1 ); |
157 |
my ( $checkpw, undef, undef ) = checkpw( $patron->cardnumber, $password, undef, undef, 1 ); |
159 |
ok( $checkpw, 'checkpw returns true with right password when logging in via cardnumber' ); |
158 |
ok( $checkpw, 'checkpw returns true with right password when logging in via cardnumber' ); |
160 |
( $checkpw, undef, undef ) = checkpw( $dbh, $patron->userid, "wrong_password", undef, undef, 1 ); |
159 |
( $checkpw, undef, undef ) = checkpw( $patron->userid, "wrong_password", undef, undef, 1 ); |
161 |
is( $checkpw, 0, 'checkpw returns false when given wrong password' ); |
160 |
is( $checkpw, 0, 'checkpw returns false when given wrong password' ); |
162 |
$patron = $patron->get_from_storage; |
161 |
$patron = $patron->get_from_storage; |
163 |
is( $patron->account_locked, 1, "Account is locked from failed login"); |
162 |
is( $patron->account_locked, 1, "Account is locked from failed login"); |
164 |
( $checkpw, undef, undef ) = checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ); |
163 |
( $checkpw, undef, undef ) = checkpw( $patron->userid, $password, undef, undef, 1 ); |
165 |
is( $checkpw, undef, 'checkpw returns undef with right password when account locked' ); |
164 |
is( $checkpw, undef, 'checkpw returns undef with right password when account locked' ); |
166 |
( $checkpw, undef, undef ) = checkpw( $dbh, $patron->cardnumber, $password, undef, undef, 1 ); |
165 |
( $checkpw, undef, undef ) = checkpw( $patron->cardnumber, $password, undef, undef, 1 ); |
167 |
is( $checkpw, undef, 'checkpw returns undefwith right password when logging in via cardnumber if account locked' ); |
166 |
is( $checkpw, undef, 'checkpw returns undefwith right password when logging in via cardnumber if account locked' ); |
168 |
|
167 |
|
169 |
}; |
168 |
}; |
Lines 361-367
subtest 'Check value of login_attempts in checkpw' => sub {
Link Here
|
361 |
$patron->password('123')->store; # yes, deliberately not hashed |
360 |
$patron->password('123')->store; # yes, deliberately not hashed |
362 |
|
361 |
|
363 |
is( $patron->account_locked, 0, 'Patron not locked' ); |
362 |
is( $patron->account_locked, 0, 'Patron not locked' ); |
364 |
my @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); |
363 |
my @test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); |
365 |
# Note: 123 will not be hashed to 123 ! |
364 |
# Note: 123 will not be hashed to 123 ! |
366 |
is( $test[0], 0, 'checkpw should have failed' ); |
365 |
is( $test[0], 0, 'checkpw should have failed' ); |
367 |
$patron->discard_changes; # refresh |
366 |
$patron->discard_changes; # refresh |
Lines 369-375
subtest 'Check value of login_attempts in checkpw' => sub {
Link Here
|
369 |
is( $patron->account_locked, 1, 'Check locked status' ); |
368 |
is( $patron->account_locked, 1, 'Check locked status' ); |
370 |
|
369 |
|
371 |
# And another try to go over the limit: different return value! |
370 |
# And another try to go over the limit: different return value! |
372 |
@test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); |
371 |
@test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); |
373 |
is( @test, 0, 'checkpw failed again and returns nothing now' ); |
372 |
is( @test, 0, 'checkpw failed again and returns nothing now' ); |
374 |
$patron->discard_changes; # refresh |
373 |
$patron->discard_changes; # refresh |
375 |
is( $patron->login_attempts, 3, 'Login attempts not increased anymore' ); |
374 |
is( $patron->login_attempts, 3, 'Login attempts not increased anymore' ); |
Lines 379-389
subtest 'Check value of login_attempts in checkpw' => sub {
Link Here
|
379 |
my $auth = Test::MockModule->new( 'C4::Auth' ); |
378 |
my $auth = Test::MockModule->new( 'C4::Auth' ); |
380 |
$auth->mock( 'checkpw_hash', sub { return 1; } ); # not for production :) |
379 |
$auth->mock( 'checkpw_hash', sub { return 1; } ); # not for production :) |
381 |
$patron->login_attempts(0)->store; |
380 |
$patron->login_attempts(0)->store; |
382 |
@test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); |
381 |
@test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); |
383 |
is( $test[0], 1, 'Build confidence in the mock' ); |
382 |
is( $test[0], 1, 'Build confidence in the mock' ); |
384 |
$patron->login_attempts(-1)->store; |
383 |
$patron->login_attempts(-1)->store; |
385 |
is( $patron->account_locked, 1, 'Check administrative lockout' ); |
384 |
is( $patron->account_locked, 1, 'Check administrative lockout' ); |
386 |
@test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); |
385 |
@test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); |
387 |
is( @test, 0, 'checkpw gave red' ); |
386 |
is( @test, 0, 'checkpw gave red' ); |
388 |
$patron->discard_changes; # refresh |
387 |
$patron->discard_changes; # refresh |
389 |
is( $patron->login_attempts, -1, 'Still locked out' ); |
388 |
is( $patron->login_attempts, -1, 'Still locked out' ); |