View | Details | Raw Unified | Return to bug 21336
Collapse All | Expand All

(-)a/Koha/Patron.pm (-4 / +10 lines)
Lines 1047-1064 sub get_enrollable_clubs { Link Here
1047
1047
1048
my $is_locked = $patron->account_locked
1048
my $is_locked = $patron->account_locked
1049
1049
1050
Return true if the patron has reach the maximum number of login attempts (see pref FailedLoginAttempts).
1050
Return true if the patron has reached the maximum number of login attempts
1051
(see pref FailedLoginAttempts). If login_attempts is < 0, this is interpreted
1052
as an administrative lockout (independent of FailedLoginAttempts; see also
1053
Koha::Patron->lock).
1051
Otherwise return false.
1054
Otherwise return false.
1052
If the pref is not set (empty string, null or 0), the feature is considered as disabled.
1055
If the pref is not set (empty string, null or 0), the feature is considered as
1056
disabled.
1053
1057
1054
=cut
1058
=cut
1055
1059
1056
sub account_locked {
1060
sub account_locked {
1057
    my ($self) = @_;
1061
    my ($self) = @_;
1058
    my $FailedLoginAttempts = C4::Context->preference('FailedLoginAttempts');
1062
    my $FailedLoginAttempts = C4::Context->preference('FailedLoginAttempts');
1059
    return ( $FailedLoginAttempts
1063
    return 1 if $FailedLoginAttempts
1060
          and $self->login_attempts
1064
          and $self->login_attempts
1061
          and $self->login_attempts >= $FailedLoginAttempts )? 1 : 0;
1065
          and $self->login_attempts >= $FailedLoginAttempts;
1066
    return 1 if ($self->login_attempts || 0) < 0; # administrative lockout
1067
    return 0;
1062
}
1068
}
1063
1069
1064
=head3 can_see_patron_infos
1070
=head3 can_see_patron_infos
(-)a/t/db_dependent/Auth.t (-2 / +17 lines)
Lines 288-294 ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first ha Link Here
288
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
288
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
289
289
290
subtest 'Check value of login_attempts in checkpw' => sub {
290
subtest 'Check value of login_attempts in checkpw' => sub {
291
    plan tests => 6;
291
    plan tests => 11;
292
292
293
    t::lib::Mocks::mock_preference('FailedLoginAttempts', 3);
293
    t::lib::Mocks::mock_preference('FailedLoginAttempts', 3);
294
294
Lines 314-319 subtest 'Check value of login_attempts in checkpw' => sub { Link Here
314
    is( @test, 0, 'checkpw failed again and returns nothing now' );
314
    is( @test, 0, 'checkpw failed again and returns nothing now' );
315
    $patron->discard_changes; # refresh
315
    $patron->discard_changes; # refresh
316
    is( $patron->login_attempts, 3, 'Login attempts not increased anymore' );
316
    is( $patron->login_attempts, 3, 'Login attempts not increased anymore' );
317
318
    # Administrative lockout cannot be undone?
319
    # Pass the right password now (or: add a nice mock).
320
    my $auth = Test::MockModule->new( 'C4::Auth' );
321
    $auth->mock( 'checkpw_hash', sub { return 1; } ); # not for production :)
322
    $patron->login_attempts(0)->store;
323
    @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 );
324
    is( $test[0], 1, 'Build confidence in the mock' );
325
    $patron->login_attempts(-1)->store;
326
    is( $patron->account_locked, 1, 'Check administrative lockout' );
327
    @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 );
328
    is( @test, 0, 'checkpw gave red' );
329
    $patron->discard_changes; # refresh
330
    is( $patron->login_attempts, -1, 'Still locked out' );
331
    t::lib::Mocks::mock_preference('FailedLoginAttempts', ''); # disable
332
    is( $patron->account_locked, 1, 'Check administrative lockout without pref' );
317
};
333
};
318
334
319
$schema->storage->txn_rollback;
335
$schema->storage->txn_rollback;
320
- 

Return to bug 21336