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

(-)a/Koha/Patron.pm (-4 / +10 lines)
Lines 1088-1105 sub get_enrollable_clubs { Link Here
1088
1088
1089
my $is_locked = $patron->account_locked
1089
my $is_locked = $patron->account_locked
1090
1090
1091
Return true if the patron has reach the maximum number of login attempts (see pref FailedLoginAttempts).
1091
Return true if the patron has reached the maximum number of login attempts
1092
(see pref FailedLoginAttempts). If login_attempts is < 0, this is interpreted
1093
as an administrative lockout (independent of FailedLoginAttempts; see also
1094
Koha::Patron->lock).
1092
Otherwise return false.
1095
Otherwise return false.
1093
If the pref is not set (empty string, null or 0), the feature is considered as disabled.
1096
If the pref is not set (empty string, null or 0), the feature is considered as
1097
disabled.
1094
1098
1095
=cut
1099
=cut
1096
1100
1097
sub account_locked {
1101
sub account_locked {
1098
    my ($self) = @_;
1102
    my ($self) = @_;
1099
    my $FailedLoginAttempts = C4::Context->preference('FailedLoginAttempts');
1103
    my $FailedLoginAttempts = C4::Context->preference('FailedLoginAttempts');
1100
    return ( $FailedLoginAttempts
1104
    return 1 if $FailedLoginAttempts
1101
          and $self->login_attempts
1105
          and $self->login_attempts
1102
          and $self->login_attempts >= $FailedLoginAttempts )? 1 : 0;
1106
          and $self->login_attempts >= $FailedLoginAttempts;
1107
    return 1 if ($self->login_attempts || 0) < 0; # administrative lockout
1108
    return 0;
1103
}
1109
}
1104
1110
1105
=head3 can_see_patron_infos
1111
=head3 can_see_patron_infos
(-)a/t/db_dependent/Auth.t (-2 / +17 lines)
Lines 318-324 ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first ha Link Here
318
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
318
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
319
319
320
subtest 'Check value of login_attempts in checkpw' => sub {
320
subtest 'Check value of login_attempts in checkpw' => sub {
321
    plan tests => 6;
321
    plan tests => 11;
322
322
323
    t::lib::Mocks::mock_preference('FailedLoginAttempts', 3);
323
    t::lib::Mocks::mock_preference('FailedLoginAttempts', 3);
324
324
Lines 343-348 subtest 'Check value of login_attempts in checkpw' => sub { Link Here
343
    is( @test, 0, 'checkpw failed again and returns nothing now' );
343
    is( @test, 0, 'checkpw failed again and returns nothing now' );
344
    $patron->discard_changes; # refresh
344
    $patron->discard_changes; # refresh
345
    is( $patron->login_attempts, 3, 'Login attempts not increased anymore' );
345
    is( $patron->login_attempts, 3, 'Login attempts not increased anymore' );
346
347
    # Administrative lockout cannot be undone?
348
    # Pass the right password now (or: add a nice mock).
349
    my $auth = Test::MockModule->new( 'C4::Auth' );
350
    $auth->mock( 'checkpw_hash', sub { return 1; } ); # not for production :)
351
    $patron->login_attempts(0)->store;
352
    @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 );
353
    is( $test[0], 1, 'Build confidence in the mock' );
354
    $patron->login_attempts(-1)->store;
355
    is( $patron->account_locked, 1, 'Check administrative lockout' );
356
    @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 );
357
    is( @test, 0, 'checkpw gave red' );
358
    $patron->discard_changes; # refresh
359
    is( $patron->login_attempts, -1, 'Still locked out' );
360
    t::lib::Mocks::mock_preference('FailedLoginAttempts', ''); # disable
361
    is( $patron->account_locked, 1, 'Check administrative lockout without pref' );
346
};
362
};
347
363
348
$schema->storage->txn_rollback;
364
$schema->storage->txn_rollback;
349
- 

Return to bug 21336