From 6bb486c3838b3f41fb08407a30664550a79a353f Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Wed, 15 Apr 2020 17:13:07 -0300 Subject: [PATCH] Bug 23816: Fix other tests This patch fixes other tests broken by new password length and strength override To test: 1. prove t/db_dependent/Auth.t \ t/db_dependent/Koha/Patron.t \ t/db_dependent/Koha/Patrons.t \ t/db_dependent/Koha/Patrons/Import.t \ t/db_dependent/Koha/Plugins/Patron.t \ t/db_dependent/Search/History.t \ t/db_dependent/api/v1/auth_basic.t \ t/db_dependent/api/v1/checkouts.t \ t/db_dependent/api/v1/patrons_password.t \ t/db_dependent/selenium/authentication.t \ t/db_dependent/selenium/regressions.t 2. Sign off Sponsored-by: Northeast Kansas Library - NEKLS --- t/db_dependent/Auth.t | 6 ++++-- t/db_dependent/Koha/Patron.t | 2 +- t/db_dependent/Koha/Patrons.t | 6 ++++-- t/db_dependent/Koha/Patrons/Import.t | 4 ++-- t/db_dependent/Koha/Plugins/Patron.t | 2 +- t/db_dependent/Search/History.t | 3 ++- t/db_dependent/api/v1/auth_basic.t | 6 ++++-- t/db_dependent/api/v1/checkouts.t | 6 ++++-- t/db_dependent/api/v1/patrons_password.t | 3 ++- t/db_dependent/selenium/authentication.t | 6 ++++-- t/db_dependent/selenium/regressions.t | 6 ++++-- 11 files changed, 32 insertions(+), 18 deletions(-) diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t index e149aec867..67ec699c17 100644 --- a/t/db_dependent/Auth.t +++ b/t/db_dependent/Auth.t @@ -127,7 +127,8 @@ subtest 'no_set_userenv parameter tests' => sub { plan tests => 7; my $library = $builder->build_object( { class => 'Koha::Libraries' } ); - my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {min_password_length => undef, require_strong_password => undef} } ); + my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $category->categorycode } } ); my $password = 'password'; t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); @@ -149,7 +150,8 @@ subtest 'checkpw lockout tests' => sub { plan tests => 5; my $library = $builder->build_object( { class => 'Koha::Libraries' } ); - my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {min_password_length => undef, require_strong_password => undef} } ); + my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $category->categorycode } } ); my $password = 'password'; t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 1 ); diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 63b77c1573..4e5dd41a92 100644 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -191,4 +191,4 @@ subtest 'to_api() tests' => sub { is( $patron_json->{algo}, 'algo' ); $schema->storage->txn_rollback; -}; +}; \ No newline at end of file diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index d4582fcbd9..8536cd5914 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -1723,7 +1723,8 @@ subtest '->store' => sub { my $print_error = $schema->storage->dbh->{PrintError}; $schema->storage->dbh->{PrintError} = 0; ; # FIXME This does not longer work - because of the transaction in Koha::Patron->store? - my $patron_1 = $builder->build_object({class=> 'Koha::Patrons'}); + my $category = $builder->build_object({class=> 'Koha::Patron::Categories', value=>{min_password_length => undef, require_strong_password => undef}}); + my $patron_1 = $builder->build_object({class=> 'Koha::Patrons', value=> { categorycode => $category->categorycode}}); my $patron_2 = $builder->build_object({class=> 'Koha::Patrons'}); throws_ok @@ -1776,7 +1777,8 @@ subtest '->set_password' => sub { $schema->storage->txn_begin; - my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { login_attempts => 3 } } ); + my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => { min_password_length => undef, require_strong_password => undef } } ); + my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { login_attempts => 3, categorycode => $category->categorycode } } ); # Disable logging password changes for this tests t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); diff --git a/t/db_dependent/Koha/Patrons/Import.t b/t/db_dependent/Koha/Patrons/Import.t index dee815a80e..562274e076 100644 --- a/t/db_dependent/Koha/Patrons/Import.t +++ b/t/db_dependent/Koha/Patrons/Import.t @@ -443,8 +443,8 @@ subtest 'test_import_with_password_overwrite' => sub { #Setup our info my $branchcode = $builder->build({ source => "Branch"})->{branchcode}; - my $categorycode = $builder->build({ source => "Category", value => { category_type => 'A' } })->{categorycode}; - my $staff_categorycode = $builder->build({ source => "Category", value => { category_type => 'S' } })->{categorycode}; + my $categorycode = $builder->build({ source => "Category", value => { category_type => 'A', min_password_length => undef, require_strong_password => undef } })->{categorycode}; + my $staff_categorycode = $builder->build({ source => "Category", value => { category_type => 'S', min_password_length => undef, require_strong_password => undef } })->{categorycode}; my $csv_headers = 'surname,userid,branchcode,categorycode,password'; my $csv_password = "Worrell,ErnestP,$branchcode,$categorycode,Ernest1"; my $csv_password_change = "Worrell,ErnestP,$branchcode,$categorycode,Vern1"; diff --git a/t/db_dependent/Koha/Plugins/Patron.t b/t/db_dependent/Koha/Plugins/Patron.t index 22bf9b2210..a0293ea4f8 100644 --- a/t/db_dependent/Koha/Plugins/Patron.t +++ b/t/db_dependent/Koha/Plugins/Patron.t @@ -54,7 +54,7 @@ subtest 'check_password hook tests' => sub { my $plugin = Koha::Plugin::Test->new->enable; my $library = $builder->build( { source => 'Branch' } ); - my $category = $builder->build( { source => 'Category' } ); + my $category = $builder->build( { source => 'Category', value => {min_password_length => undef, require_strong_password => undef} } ); my $patron = Koha::Patron->new( { cardnumber => 'test_cn_1', diff --git a/t/db_dependent/Search/History.t b/t/db_dependent/Search/History.t index 2e3aa1fd1e..051234d1af 100644 --- a/t/db_dependent/Search/History.t +++ b/t/db_dependent/Search/History.t @@ -368,7 +368,8 @@ my $schema = Koha::Database->schema; my $builder = t::lib::TestBuilder->new; # Borrower Creation -our $patron = $builder->build( { source => 'Borrower' } ); +my $category = $builder->build( { source => 'Category', value => {min_password_length => undef, require_strong_password => undef} } ); +our $patron = $builder->build( { source => 'Borrower', value => { categorycode => $category->{categorycode} } } ); t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); Koha::Patrons->find( $patron->{borrowernumber} )->set_password({ password => 'password' }); diff --git a/t/db_dependent/api/v1/auth_basic.t b/t/db_dependent/api/v1/auth_basic.t index ca5bb67214..871c070647 100644 --- a/t/db_dependent/api/v1/auth_basic.t +++ b/t/db_dependent/api/v1/auth_basic.t @@ -38,8 +38,9 @@ subtest 'success tests' => sub { my $password = 'AbcdEFG123'; + my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { min_password_length => undef, require_strong_password => undef }}); my $patron = $builder->build_object( - { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4 } } ); + { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4, categorycode => $category->categorycode } } ); $patron->set_password({ password => $password }); my $userid = $patron->userid; @@ -69,8 +70,9 @@ subtest 'failure tests' => sub { t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); + my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { min_password_length => undef, require_strong_password => undef }}); my $patron = $builder->build_object( - { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4 } } ); + { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4, categorycode => $category->categorycode } } ); $patron->set_password({ password => $password }); my $userid = $patron->userid; diff --git a/t/db_dependent/api/v1/checkouts.t b/t/db_dependent/api/v1/checkouts.t index 5f7f4ed2fe..a9df1152ae 100644 --- a/t/db_dependent/api/v1/checkouts.t +++ b/t/db_dependent/api/v1/checkouts.t @@ -41,17 +41,19 @@ $schema->storage->txn_begin; my $dbh = C4::Context->dbh; +my $category = $builder->build_object({class => 'Koha::Patron::Categories', value => { min_password_length => undef, require_strong_password => undef } }); my $librarian = $builder->build_object({ class => 'Koha::Patrons', - value => { flags => 2 } + value => { flags => 2, categorycode => $category->categorycode } }); my $password = 'thePassword123'; $librarian->set_password({ password => $password, skip_validation => 1 }); my $userid = $librarian->userid; +$category = $builder->build_object({class => 'Koha::Patron::Categories', value => { min_password_length => undef, require_strong_password => undef } }); my $patron = $builder->build_object({ class => 'Koha::Patrons', - value => { flags => 0 } + value => { flags => 0, categorycode => $category->categorycode } }); my $unauth_password = 'thePassword000'; $patron->set_password({ password => $unauth_password, skip_validattion => 1 }); diff --git a/t/db_dependent/api/v1/patrons_password.t b/t/db_dependent/api/v1/patrons_password.t index 2a57516319..9199ce4176 100644 --- a/t/db_dependent/api/v1/patrons_password.t +++ b/t/db_dependent/api/v1/patrons_password.t @@ -237,10 +237,11 @@ sub create_user_and_session { my ( $args ) = @_; my $flags = ( $args->{authorized} ) ? 16 : 0; + my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { min_password_length => undef, require_strong_password => undef}}); my $user = $builder->build_object( { class => 'Koha::Patrons', - value => { flags => $flags } + value => { flags => $flags, categorycode => $category->categorycode } } ); diff --git a/t/db_dependent/selenium/authentication.t b/t/db_dependent/selenium/authentication.t index 359cac1cef..fa719f39f7 100644 --- a/t/db_dependent/selenium/authentication.t +++ b/t/db_dependent/selenium/authentication.t @@ -48,7 +48,8 @@ SKIP: { like( $driver->get_title, qr(Log in to Koha), 'Hitting the main page should redirect to the login form'); my $password = Koha::AuthUtils::generate_password(); - my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 }}); + my $category = $builder->build_object({class => 'Koha::Patron::Categories', value => { min_password_length => undef, require_strong_password => undef } }); + my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0, categorycode => $category->categorycode }}); t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); $patron->set_password({ password => $password }); @@ -82,7 +83,8 @@ SKIP: { like( $driver->get_title, qr(Koha online catalog), 'Hitting the main page should not redirect to the login form'); my $password = Koha::AuthUtils::generate_password(); - my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 }}); + my $category = $builder->build_object({class => 'Koha::Patron::Categories', value => { min_password_length => undef, require_strong_password => undef } }); + my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0, categorycode => $category->categorycode }}); t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); $patron->set_password({ password => $password }); diff --git a/t/db_dependent/selenium/regressions.t b/t/db_dependent/selenium/regressions.t index ed2a68cdd4..37c73042c6 100644 --- a/t/db_dependent/selenium/regressions.t +++ b/t/db_dependent/selenium/regressions.t @@ -52,8 +52,9 @@ our @cleanup; subtest 'OPAC - borrowernumber and branchcode as html attributes' => sub { plan tests => 2; + my $category = $builder->build_object({class => 'Koha::Patron::Categories', value => { min_password_length => undef, require_strong_password => undef } }); my $patron = $builder->build_object( - { class => 'Koha::Patrons', value => { flags => 1 } } ); + { class => 'Koha::Patrons', value => { flags => 1, categorycode => $category->categorycode } } ); my $password = Koha::AuthUtils::generate_password(); t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); $patron->set_password({ password => $password }); @@ -197,7 +198,8 @@ subtest 'Display circulation table correctly' => sub { subtest 'XSS vulnerabilities in pagination' => sub { plan tests => 3; - my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + my $category = $builder->build_object({class => 'Koha::Patron::Categories', value => { min_password_length => undef, require_strong_password => undef } }); + my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category->categorycode } }); for ( 1 .. 30 ) { # We want the pagination to be displayed push @cleanup, $builder->build_object( { -- 2.25.0