Bugzilla – Attachment 77578 Details for
Bug 21178
Add Koha::Patron::set_password method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21178: Unit tests
Bug-21178-Unit-tests.patch (text/plain), 3.73 KB, created by
Tomás Cohen Arazi (tcohen)
on 2018-08-08 14:56:11 UTC
(
hide
)
Description:
Bug 21178: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2018-08-08 14:56:11 UTC
Size:
3.73 KB
patch
obsolete
>From 9eb39aabcb1851e1edd68d01dba27675a40fbacc Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 8 Aug 2018 11:01:31 -0300 >Subject: [PATCH] Bug 21178: Unit tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/Koha/Patrons.t | 74 ++++++++++++++++++++++++++++++++++- > 1 file changed, 73 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 8df1dea320..3b0eaeaefd 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 32; >+use Test::More tests => 33; > use Test::Warn; > use Test::Exception; > use Time::Fake; >@@ -1453,6 +1453,78 @@ subtest '->store' => sub { > }; > > >+subtest '->set_password' => sub { >+ >+ plan tests => 11; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { login_attempts => 3 } } ); >+ >+ # Disable logging password changes for this tests >+ t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); >+ >+ # Password-length tests >+ t::lib::Mocks::mock_preference( 'minPasswordLength', undef ); >+ throws_ok { $patron->set_password('ab'); } >+ 'Koha::Exceptions::Password::TooShort', >+ 'minPasswordLength is undef, fall back to 3, fail test'; >+ >+ t::lib::Mocks::mock_preference( 'minPasswordLength', 2 ); >+ throws_ok { $patron->set_password('ab'); } >+ 'Koha::Exceptions::Password::TooShort', >+ 'minPasswordLength is 2, fall back to 3, fail test'; >+ >+ t::lib::Mocks::mock_preference( 'minPasswordLength', 5 ); >+ throws_ok { $patron->set_password('abcb'); } >+ 'Koha::Exceptions::Password::TooShort', >+ 'minPasswordLength is 5, fail test'; >+ >+ # Trailing spaces tests >+ throws_ok { $patron->set_password('abcd '); } >+ 'Koha::Exceptions::Password::TrailingWhitespaces', >+ 'Password contains trailing spaces, exception is thrown'; >+ >+ # Require strong password tests >+ t::lib::Mocks::mock_preference( 'RequireStrongPassword', 1 ); >+ throws_ok { $patron->set_password('abcd a'); } >+ 'Koha::Exceptions::Password::TooWeak', >+ 'Password is too weak, exception is thrown'; >+ >+ # Refresh patron from DB, just to make sure >+ $patron->discard_changes; >+ is( $patron->login_attempts, 3, 'Previous tests kept login attemps count' ); >+ >+ $patron->set_password('abcD12 34'); >+ $patron->discard_changes; >+ >+ is( $patron->login_attempts, 0, 'Changing the password resets the login attempts count' ); >+ >+ # Completeness >+ t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); >+ $patron->login_attempts(3)->store; >+ my $old_digest = $patron->password; >+ $patron->set_password('abcd a'); >+ $patron->discard_changes; >+ >+ isnt( $patron->password, $old_digest, 'Password has been updated' ); >+ is( $patron->login_attempts, 0, 'Login attemps have been reset' ); >+ >+ my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count; >+ is( $number_of_logs, 0, 'Without BorrowerLogs, Koha::Patron->set_password doesn\'t log password changes' ); >+ >+ # Enable logging password changes >+ t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); >+ $patron->set_password('abcd b'); >+ >+ $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count; >+ is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->set_password does log password changes' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+ >+ > # TODO Move to t::lib::Mocks and reuse it! > sub set_logged_in_user { > my ($patron) = @_; >-- >2.18.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21178
:
77575
|
77576
|
77577
|
77578
|
77632
|
77885
|
77886
|
77916
|
77917
|
78833
|
80133
|
80134
|
80135
|
80136