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

(-)a/t/db_dependent/Koha/Patrons.t (-10 / +12 lines)
Lines 1529-1535 subtest '->store' => sub { Link Here
1529
1529
1530
subtest '->set_password' => sub {
1530
subtest '->set_password' => sub {
1531
1531
1532
    plan tests => 12;
1532
    plan tests => 13;
1533
1533
1534
    $schema->storage->txn_begin;
1534
    $schema->storage->txn_begin;
1535
1535
Lines 1540-1567 subtest '->set_password' => sub { Link Here
1540
1540
1541
    # Password-length tests
1541
    # Password-length tests
1542
    t::lib::Mocks::mock_preference( 'minPasswordLength', undef );
1542
    t::lib::Mocks::mock_preference( 'minPasswordLength', undef );
1543
    throws_ok { $patron->set_password('ab'); }
1543
    throws_ok { $patron->set_password({ password => 'ab' }); }
1544
        'Koha::Exceptions::Password::TooShort',
1544
        'Koha::Exceptions::Password::TooShort',
1545
        'minPasswordLength is undef, fall back to 3, fail test';
1545
        'minPasswordLength is undef, fall back to 3, fail test';
1546
1546
1547
    t::lib::Mocks::mock_preference( 'minPasswordLength', 2 );
1547
    t::lib::Mocks::mock_preference( 'minPasswordLength', 2 );
1548
    throws_ok { $patron->set_password('ab'); }
1548
    throws_ok { $patron->set_password({ password => 'ab' }); }
1549
        'Koha::Exceptions::Password::TooShort',
1549
        'Koha::Exceptions::Password::TooShort',
1550
        'minPasswordLength is 2, fall back to 3, fail test';
1550
        'minPasswordLength is 2, fall back to 3, fail test';
1551
1551
1552
    t::lib::Mocks::mock_preference( 'minPasswordLength', 5 );
1552
    t::lib::Mocks::mock_preference( 'minPasswordLength', 5 );
1553
    throws_ok { $patron->set_password('abcb'); }
1553
    throws_ok { $patron->set_password({ password => 'abcb' }); }
1554
        'Koha::Exceptions::Password::TooShort',
1554
        'Koha::Exceptions::Password::TooShort',
1555
        'minPasswordLength is 5, fail test';
1555
        'minPasswordLength is 5, fail test';
1556
1556
1557
    # Trailing spaces tests
1557
    # Trailing spaces tests
1558
    throws_ok { $patron->set_password('abcD12d   '); }
1558
    throws_ok { $patron->set_password({ password => 'abcD12d   ' }); }
1559
        'Koha::Exceptions::Password::WhitespaceCharacters',
1559
        'Koha::Exceptions::Password::WhitespaceCharacters',
1560
        'Password contains trailing spaces, exception is thrown';
1560
        'Password contains trailing spaces, exception is thrown';
1561
1561
1562
    # Require strong password tests
1562
    # Require strong password tests
1563
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 1 );
1563
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 1 );
1564
    throws_ok { $patron->set_password('abcd   a'); }
1564
    throws_ok { $patron->set_password({ password => 'abcd   a' }); }
1565
        'Koha::Exceptions::Password::TooWeak',
1565
        'Koha::Exceptions::Password::TooWeak',
1566
        'Password is too weak, exception is thrown';
1566
        'Password is too weak, exception is thrown';
1567
1567
Lines 1569-1584 subtest '->set_password' => sub { Link Here
1569
    $patron->discard_changes;
1569
    $patron->discard_changes;
1570
    is( $patron->login_attempts, 3, 'Previous tests kept login attemps count' );
1570
    is( $patron->login_attempts, 3, 'Previous tests kept login attemps count' );
1571
1571
1572
    $patron->set_password('abcD12 34');
1572
    $patron->set_password({ password => 'abcD12 34' });
1573
    $patron->discard_changes;
1573
    $patron->discard_changes;
1574
1574
1575
    is( $patron->login_attempts, 0, 'Changing the password resets the login attempts count' );
1575
    is( $patron->login_attempts, 0, 'Changing the password resets the login attempts count' );
1576
1576
1577
    lives_ok { $patron->set_password({ password => 'abcd   a', skip_validation => 1 }) }
1578
        'Password is weak, but skip_validation was passed, so no exception thrown';
1579
1577
    # Completeness
1580
    # Completeness
1578
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
1581
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
1579
    $patron->login_attempts(3)->store;
1582
    $patron->login_attempts(3)->store;
1580
    my $old_digest = $patron->password;
1583
    my $old_digest = $patron->password;
1581
    $patron->set_password('abcd   a');
1584
    $patron->set_password({ password => 'abcd   a' });
1582
    $patron->discard_changes;
1585
    $patron->discard_changes;
1583
1586
1584
    isnt( $patron->password, $old_digest, 'Password has been updated' );
1587
    isnt( $patron->password, $old_digest, 'Password has been updated' );
Lines 1590-1596 subtest '->set_password' => sub { Link Here
1590
1593
1591
    # Enable logging password changes
1594
    # Enable logging password changes
1592
    t::lib::Mocks::mock_preference( 'BorrowersLog', 1 );
1595
    t::lib::Mocks::mock_preference( 'BorrowersLog', 1 );
1593
    $patron->set_password('abcd   b');
1596
    $patron->set_password({ password => 'abcd   b' });
1594
1597
1595
    $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count;
1598
    $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count;
1596
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->set_password does log password changes' );
1599
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->set_password does log password changes' );
1597
- 

Return to bug 22047