|
Lines 1788-1817
subtest '->set_password' => sub {
Link Here
|
| 1788 |
t::lib::Mocks::mock_preference( 'minPasswordLength', undef ); |
1788 |
t::lib::Mocks::mock_preference( 'minPasswordLength', undef ); |
| 1789 |
throws_ok { $patron->set_password({ password => 'ab' }); } |
1789 |
throws_ok { $patron->set_password({ password => 'ab' }); } |
| 1790 |
'Koha::Exceptions::Password::TooShort', |
1790 |
'Koha::Exceptions::Password::TooShort', |
| 1791 |
'minPasswordLength is undef, fall back to 3, fail test'; |
1791 |
'minPasswordLength is undef, fall back to 8, fail test'; |
| 1792 |
is( "$@", |
1792 |
is( "$@", |
| 1793 |
'Password length (2) is shorter than required (3)', |
1793 |
'Password length (2) is shorter than required (8)', |
| 1794 |
'Exception parameters passed correctly' |
1794 |
'Exception parameters passed correctly' |
| 1795 |
); |
1795 |
); |
| 1796 |
|
1796 |
|
| 1797 |
t::lib::Mocks::mock_preference( 'minPasswordLength', 2 ); |
1797 |
t::lib::Mocks::mock_preference( 'minPasswordLength', 2 ); |
| 1798 |
throws_ok { $patron->set_password({ password => 'ab' }); } |
1798 |
throws_ok { $patron->set_password({ password => 'ab' }); } |
| 1799 |
'Koha::Exceptions::Password::TooShort', |
1799 |
'Koha::Exceptions::Password::TooShort', |
| 1800 |
'minPasswordLength is 2, fall back to 3, fail test'; |
1800 |
'minPasswordLength is 2, fall back to 8, fail test'; |
| 1801 |
|
1801 |
|
| 1802 |
t::lib::Mocks::mock_preference( 'minPasswordLength', 5 ); |
1802 |
t::lib::Mocks::mock_preference( 'minPasswordLength', 10 ); |
| 1803 |
throws_ok { $patron->set_password({ password => 'abcb' }); } |
1803 |
throws_ok { $patron->set_password({ password => 'abcdefghi' }); } |
| 1804 |
'Koha::Exceptions::Password::TooShort', |
1804 |
'Koha::Exceptions::Password::TooShort', |
| 1805 |
'minPasswordLength is 5, fail test'; |
1805 |
'minPasswordLength is 10, fail test'; |
| 1806 |
|
1806 |
|
| 1807 |
# Trailing spaces tests |
1807 |
# Trailing spaces tests |
| 1808 |
throws_ok { $patron->set_password({ password => 'abcD12d ' }); } |
1808 |
throws_ok { $patron->set_password({ password => 'abcDef12d ' }); } |
| 1809 |
'Koha::Exceptions::Password::WhitespaceCharacters', |
1809 |
'Koha::Exceptions::Password::WhitespaceCharacters', |
| 1810 |
'Password contains trailing spaces, exception is thrown'; |
1810 |
'Password contains trailing spaces, exception is thrown'; |
| 1811 |
|
1811 |
|
| 1812 |
# Require strong password tests |
1812 |
# Require strong password tests |
| 1813 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 1 ); |
1813 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 1 ); |
| 1814 |
throws_ok { $patron->set_password({ password => 'abcd a' }); } |
1814 |
throws_ok { $patron->set_password({ password => 'abcdef a' }); } |
| 1815 |
'Koha::Exceptions::Password::TooWeak', |
1815 |
'Koha::Exceptions::Password::TooWeak', |
| 1816 |
'Password is too weak, exception is thrown'; |
1816 |
'Password is too weak, exception is thrown'; |
| 1817 |
|
1817 |
|
|
Lines 1819-1825
subtest '->set_password' => sub {
Link Here
|
| 1819 |
$patron->discard_changes; |
1819 |
$patron->discard_changes; |
| 1820 |
is( $patron->login_attempts, 3, 'Previous tests kept login attemps count' ); |
1820 |
is( $patron->login_attempts, 3, 'Previous tests kept login attemps count' ); |
| 1821 |
|
1821 |
|
| 1822 |
$patron->set_password({ password => 'abcD12 34' }); |
1822 |
$patron->set_password({ password => 'abcD12345e' }); |
| 1823 |
$patron->discard_changes; |
1823 |
$patron->discard_changes; |
| 1824 |
|
1824 |
|
| 1825 |
is( $patron->login_attempts, 0, 'Changing the password resets the login attempts count' ); |
1825 |
is( $patron->login_attempts, 0, 'Changing the password resets the login attempts count' ); |
|
Lines 1831-1841
subtest '->set_password' => sub {
Link Here
|
| 1831 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
1831 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
| 1832 |
$patron->login_attempts(3)->store; |
1832 |
$patron->login_attempts(3)->store; |
| 1833 |
my $old_digest = $patron->password; |
1833 |
my $old_digest = $patron->password; |
| 1834 |
$patron->set_password({ password => 'abcd a' }); |
1834 |
$patron->set_password({ password => 'abcd abc' }); |
| 1835 |
$patron->discard_changes; |
1835 |
$patron->discard_changes; |
| 1836 |
|
1836 |
|
| 1837 |
isnt( $patron->password, $old_digest, 'Password has been updated' ); |
1837 |
isnt( $patron->password, $old_digest, 'Password has been updated' ); |
| 1838 |
ok( checkpw_hash('abcd a', $patron->password), 'Password hash is correct' ); |
1838 |
ok( checkpw_hash('abcd abc', $patron->password), 'Password hash is correct' ); |
| 1839 |
is( $patron->login_attempts, 0, 'Login attemps have been reset' ); |
1839 |
is( $patron->login_attempts, 0, 'Login attemps have been reset' ); |
| 1840 |
|
1840 |
|
| 1841 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count; |
1841 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count; |
|
Lines 1843-1849
subtest '->set_password' => sub {
Link Here
|
| 1843 |
|
1843 |
|
| 1844 |
# Enable logging password changes |
1844 |
# Enable logging password changes |
| 1845 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
1845 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
| 1846 |
$patron->set_password({ password => 'abcd b' }); |
1846 |
$patron->set_password({ password => 'abcd babc' }); |
| 1847 |
|
1847 |
|
| 1848 |
$number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count; |
1848 |
$number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count; |
| 1849 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->set_password does log password changes' ); |
1849 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->set_password does log password changes' ); |