From de72db2b594d60e45796aab1090e6b239685a607 Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Fri, 20 Dec 2019 18:01:42 +0100 Subject: [PATCH] Bug 23011: Add new tests (AuthenticatePatron error codes) This bug add new tests to the AuthenticatePatron ILS-DI service. It tests new error codes patron might get when successfully connecting but with a password which doesn't match Koha security rules. --- t/db_dependent/ILSDI_Services.t | 52 ++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t index 430d900c77..865cd5f402 100644 --- a/t/db_dependent/ILSDI_Services.t +++ b/t/db_dependent/ILSDI_Services.t @@ -19,7 +19,7 @@ use Modern::Perl; use CGI qw ( -utf8 ); -use Test::More tests => 9; +use Test::More tests => 10; use Test::MockModule; use t::lib::Mocks; use t::lib::TestBuilder; @@ -104,6 +104,56 @@ subtest 'AuthenticatePatron test' => sub { }; +subtest 'AuthenticatePatron Secure Password test' => sub { + + plan tests => 10; + + $schema->storage->txn_begin; + + my $plain_password = 'tomasito'; + + $builder->build({ + source => 'Borrower', + value => { + cardnumber => undef, + } + }); + + my $borrower = $builder->build({ + source => 'Borrower', + value => { + cardnumber => undef, + password => Koha::AuthUtils::hash_password( $plain_password ) + } + }); + + my $query = new CGI; + $query->param( 'username', $borrower->{userid}); + $query->param( 'password', $plain_password); + + my $reply = C4::ILSDI::Services::AuthenticatePatron( $query ); + is( $reply->{id}, $borrower->{borrowernumber}, "userid and password - Patron authenticated" ); + is( $reply->{code}, undef, "Error code undef"); + + t::lib::Mocks::mock_preference( 'minPasswordLength', 10 ); + $reply = C4::ILSDI::Services::AuthenticatePatron( $query ); + is( $reply->{id}, $borrower->{borrowernumber}, "existing user"); + is( $reply->{code}, 'PatronPasswordNotSecure', "PasswordNotSecure" ); + is( $reply->{securePasswordLabel}, 'too_short', "PasswordTooShort" ); + is( $reply->{securePasswordPattern}, '.{10}', "Password must be at least 10 char" ); + + t::lib::Mocks::mock_preference( 'RequireStrongPassword', 1 ); + t::lib::Mocks::mock_preference( 'minPasswordLength', 5 ); + $reply = C4::ILSDI::Services::AuthenticatePatron( $query ); + is( $reply->{id}, $borrower->{borrowernumber}, "existing user"); + is( $reply->{code}, 'PatronPasswordNotSecure', "PasswordNotSecure" ); + is( $reply->{securePasswordLabel}, 'too_weak', "PasswordTooWeak" ); + is( $reply->{securePasswordPattern}, '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{5}', "Password must be strong (pattern match)" ); + + $schema->storage->txn_rollback; +}; + + subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes' => sub { plan tests => 5; -- 2.20.1