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

(-)a/C4/Auth.pm (-1 / +1 lines)
Lines 1839-1845 sub checkpw { Link Here
1839
    if( $patron ) {
1839
    if( $patron ) {
1840
        if ( $passwd_ok ) {
1840
        if ( $passwd_ok ) {
1841
            $patron->update({ login_attempts => 0 });
1841
            $patron->update({ login_attempts => 0 });
1842
        } else {
1842
        } elsif( !$patron->account_locked ) {
1843
            $patron->update({ login_attempts => $patron->login_attempts + 1 });
1843
            $patron->update({ login_attempts => $patron->login_attempts + 1 });
1844
        }
1844
        }
1845
    }
1845
    }
(-)a/installer/data/mysql/atomicupdate/bug_21336c.perl (+6 lines)
Line 0 Link Here
1
$DBversion = 'XXX';  # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do( "UPDATE borrowers SET login_attempts = ? WHERE login_attempts > ?", undef, C4::Context->preference('FailedLoginAttempts'), C4::Context->preference('FailedLoginAttempts') );
4
    SetVersion( $DBversion );
5
    print "Upgrade to $DBversion done (Bug 21336 - Reset login_attempts)\n";
6
}
(-)a/t/db_dependent/Auth.t (-1 / +32 lines)
Lines 10-16 use CGI qw ( -utf8 ); Link Here
10
use Test::MockObject;
10
use Test::MockObject;
11
use Test::MockModule;
11
use Test::MockModule;
12
use List::MoreUtils qw/all any none/;
12
use List::MoreUtils qw/all any none/;
13
use Test::More tests => 26;
13
use Test::More tests => 27;
14
use Test::Warn;
14
use Test::Warn;
15
use t::lib::Mocks;
15
use t::lib::Mocks;
16
use t::lib::TestBuilder;
16
use t::lib::TestBuilder;
Lines 32-37 my $dbh = C4::Context->dbh; Link Here
32
# FIXME: SessionStorage defaults to mysql, but it seems to break transaction
32
# FIXME: SessionStorage defaults to mysql, but it seems to break transaction
33
# handling
33
# handling
34
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
34
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
35
t::lib::Mocks::mock_preference( 'GDPR_Policy', '' ); # Disabled
35
36
36
$schema->storage->txn_begin;
37
$schema->storage->txn_begin;
37
38
Lines 313-315 ok( ( any { 'OPACBaseURL' eq $_ } keys %{$template2->{VARS}} ), Link Here
313
314
314
ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first hash');
315
ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first hash');
315
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
316
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
317
318
subtest 'Check value of login_attempts in checkpw' => sub {
319
    plan tests => 6;
320
321
    t::lib::Mocks::mock_preference('FailedLoginAttempts', 3);
322
323
    # Only interested here in regular login
324
    $C4::Auth::cas  = 0;
325
    $C4::Auth::ldap = 0;
326
327
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
328
    $patron->login_attempts(2);
329
    $patron->password('123')->store; # yes, deliberately not hashed
330
331
    is( $patron->account_locked, 0, 'Patron not locked' );
332
    my @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 );
333
        # Note: 123 will not be hashed to 123 !
334
    is( $test[0], 0, 'checkpw should have failed' );
335
    $patron->discard_changes; # refresh
336
    is( $patron->login_attempts, 3, 'Login attempts increased' );
337
    is( $patron->account_locked, 1, 'Check locked status' );
338
339
    # And another try to go over the limit: different return value!
340
    @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 );
341
    is( @test, 0, 'checkpw failed again and returns nothing now' );
342
    $patron->discard_changes; # refresh
343
    is( $patron->login_attempts, 3, 'Login attempts not increased anymore' );
344
};
345
346
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +3 lines)
Lines 1156-1162 subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited Link Here
1156
};
1156
};
1157
1157
1158
subtest 'account_locked' => sub {
1158
subtest 'account_locked' => sub {
1159
    plan tests => 8;
1159
    plan tests => 9;
1160
    my $patron = $builder->build({ source => 'Borrower', value => { login_attempts => 0 } });
1160
    my $patron = $builder->build({ source => 'Borrower', value => { login_attempts => 0 } });
1161
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
1161
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
1162
    for my $value ( undef, '', 0 ) {
1162
    for my $value ( undef, '', 0 ) {
Lines 1171-1176 subtest 'account_locked' => sub { Link Here
1171
    is( $patron->account_locked, 0, 'Patron has 2 failed attempts, account should not be considered locked yet' );
1171
    is( $patron->account_locked, 0, 'Patron has 2 failed attempts, account should not be considered locked yet' );
1172
    $patron->login_attempts(3)->store;
1172
    $patron->login_attempts(3)->store;
1173
    is( $patron->account_locked, 1, 'Patron has 3 failed attempts, account should be considered locked yet' );
1173
    is( $patron->account_locked, 1, 'Patron has 3 failed attempts, account should be considered locked yet' );
1174
    $patron->login_attempts(4)->store;
1175
    is( $patron->account_locked, 1, 'Patron could not have 4 failed attempts, but account should still be considered locked' );
1174
1176
1175
    $patron->delete;
1177
    $patron->delete;
1176
};
1178
};
1177
- 

Return to bug 21336