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 1453-1458
subtest '->store' => sub {
Link Here
|
1453 |
}; |
1453 |
}; |
1454 |
|
1454 |
|
1455 |
|
1455 |
|
|
|
1456 |
subtest '->set_password' => sub { |
1457 |
|
1458 |
plan tests => 9; |
1459 |
|
1460 |
$schema->storage->txn_begin; |
1461 |
|
1462 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { login_attempts => 3 } } ); |
1463 |
|
1464 |
# Disable logging password changes for this tests |
1465 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); |
1466 |
|
1467 |
# Password-length tests |
1468 |
t::lib::Mocks::mock_preference( 'minPasswordLength', undef ); |
1469 |
throws_ok { $patron->set_password('ab'); } |
1470 |
'Koha::Exceptions::Password::TooShort', |
1471 |
'minPasswordLength is undef, fall back to 3, fail test'; |
1472 |
|
1473 |
t::lib::Mocks::mock_preference( 'minPasswordLength', 2 ); |
1474 |
throws_ok { $patron->set_password('ab'); } |
1475 |
'Koha::Exceptions::Password::TooShort', |
1476 |
'minPasswordLength is 2, fall back to 3, fail test'; |
1477 |
|
1478 |
t::lib::Mocks::mock_preference( 'minPasswordLength', 5 ); |
1479 |
throws_ok { $patron->set_password('abcb'); } |
1480 |
'Koha::Exceptions::Password::TooShort', |
1481 |
'minPasswordLength is 5, fail test'; |
1482 |
|
1483 |
# Trailing spaces tests |
1484 |
throws_ok { $patron->set_password('abcd '); } |
1485 |
'Koha::Exceptions::Password::TrailingWhitespaces', |
1486 |
'Password contains trailing spaces, exception is thrown'; |
1487 |
|
1488 |
# Require strong password tests |
1489 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 1 ); |
1490 |
throws_ok { $patron->set_password('abcd a'); } |
1491 |
'Koha::Exceptions::Password::TooWeak', |
1492 |
'Password is too weak, exception is thrown'; |
1493 |
|
1494 |
# Refresh patron from DB, just to make sure |
1495 |
$patron->discard_changes; |
1496 |
is( $patron->login_attempts, 3, 'Previous tests kept login attemps count' ); |
1497 |
|
1498 |
$patron->set_password('abcD12 34'); |
1499 |
$patron->discard_changes; |
1500 |
|
1501 |
is( $patron->login_attempts, 0, 'Changing the password resets the login attempts count' ); |
1502 |
|
1503 |
# Completeness |
1504 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
1505 |
$patron->login_attempts(3)->store; |
1506 |
my $old_digest = $patron->password; |
1507 |
$patron->set_password('abcd a'); |
1508 |
$patron->discard_changes; |
1509 |
|
1510 |
isnt( $patron->password, $old_digest, 'Password has been updated' ); |
1511 |
is( $patron->login_attempts, 0, 'Login attemps have been reset' ); |
1512 |
|
1513 |
$schema->storage->txn_rollback; |
1514 |
}; |
1515 |
|
1516 |
|
1517 |
|
1456 |
# TODO Move to t::lib::Mocks and reuse it! |
1518 |
# TODO Move to t::lib::Mocks and reuse it! |
1457 |
sub set_logged_in_user { |
1519 |
sub set_logged_in_user { |
1458 |
my ($patron) = @_; |
1520 |
my ($patron) = @_; |
1459 |
- |
|
|