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

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

Return to bug 22047