Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 32; |
22 |
use Test::More tests => 33; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
use Test::Exception; |
24 |
use Test::Exception; |
25 |
use Time::Fake; |
25 |
use Time::Fake; |
Lines 1501-1506
subtest '->store' => sub {
Link Here
|
1501 |
}; |
1501 |
}; |
1502 |
|
1502 |
|
1503 |
|
1503 |
|
|
|
1504 |
subtest '->set_password' => sub { |
1505 |
|
1506 |
plan tests => 11; |
1507 |
|
1508 |
$schema->storage->txn_begin; |
1509 |
|
1510 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { login_attempts => 3 } } ); |
1511 |
|
1512 |
# Disable logging password changes for this tests |
1513 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); |
1514 |
|
1515 |
# Password-length tests |
1516 |
t::lib::Mocks::mock_preference( 'minPasswordLength', undef ); |
1517 |
throws_ok { $patron->set_password('ab'); } |
1518 |
'Koha::Exceptions::Password::TooShort', |
1519 |
'minPasswordLength is undef, fall back to 3, fail test'; |
1520 |
|
1521 |
t::lib::Mocks::mock_preference( 'minPasswordLength', 2 ); |
1522 |
throws_ok { $patron->set_password('ab'); } |
1523 |
'Koha::Exceptions::Password::TooShort', |
1524 |
'minPasswordLength is 2, fall back to 3, fail test'; |
1525 |
|
1526 |
t::lib::Mocks::mock_preference( 'minPasswordLength', 5 ); |
1527 |
throws_ok { $patron->set_password('abcb'); } |
1528 |
'Koha::Exceptions::Password::TooShort', |
1529 |
'minPasswordLength is 5, fail test'; |
1530 |
|
1531 |
# Trailing spaces tests |
1532 |
throws_ok { $patron->set_password('abcD12d '); } |
1533 |
'Koha::Exceptions::Password::TrailingWhitespaces', |
1534 |
'Password contains trailing spaces, exception is thrown'; |
1535 |
|
1536 |
# Require strong password tests |
1537 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 1 ); |
1538 |
throws_ok { $patron->set_password('abcd a'); } |
1539 |
'Koha::Exceptions::Password::TooWeak', |
1540 |
'Password is too weak, exception is thrown'; |
1541 |
|
1542 |
# Refresh patron from DB, just to make sure |
1543 |
$patron->discard_changes; |
1544 |
is( $patron->login_attempts, 3, 'Previous tests kept login attemps count' ); |
1545 |
|
1546 |
$patron->set_password('abcD12 34'); |
1547 |
$patron->discard_changes; |
1548 |
|
1549 |
is( $patron->login_attempts, 0, 'Changing the password resets the login attempts count' ); |
1550 |
|
1551 |
# Completeness |
1552 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
1553 |
$patron->login_attempts(3)->store; |
1554 |
my $old_digest = $patron->password; |
1555 |
$patron->set_password('abcd a'); |
1556 |
$patron->discard_changes; |
1557 |
|
1558 |
isnt( $patron->password, $old_digest, 'Password has been updated' ); |
1559 |
is( $patron->login_attempts, 0, 'Login attemps have been reset' ); |
1560 |
|
1561 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count; |
1562 |
is( $number_of_logs, 0, 'Without BorrowerLogs, Koha::Patron->set_password doesn\'t log password changes' ); |
1563 |
|
1564 |
# Enable logging password changes |
1565 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
1566 |
$patron->set_password('abcd b'); |
1567 |
|
1568 |
$number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count; |
1569 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->set_password does log password changes' ); |
1570 |
|
1571 |
$schema->storage->txn_rollback; |
1572 |
}; |
1573 |
|
1574 |
|
1575 |
|
1504 |
# TODO Move to t::lib::Mocks and reuse it! |
1576 |
# TODO Move to t::lib::Mocks and reuse it! |
1505 |
sub set_logged_in_user { |
1577 |
sub set_logged_in_user { |
1506 |
my ($patron) = @_; |
1578 |
my ($patron) = @_; |
1507 |
- |
|
|