From a947531f09fe7f428fa510817f77f21b231d538c Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 17 Aug 2022 15:40:07 -0300 Subject: [PATCH] Bug 31382: Regression tests Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Auth.t | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t index ad7f9ddc034..50d0f4c79b6 100755 --- a/t/db_dependent/Auth.t +++ b/t/db_dependent/Auth.t @@ -41,7 +41,7 @@ $schema->storage->txn_begin; subtest 'checkauth() tests' => sub { - plan tests => 5; + plan tests => 6; my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } }); @@ -111,6 +111,47 @@ subtest 'checkauth() tests' => sub { is( $userid, undef, 'If librarian user is used and password with GET, they should not be logged in' ); }; + subtest 'Template params tests (password_expired)' => sub { + + plan tests => 1; + + my $password_expired; + + my $patron_class = Test::MockModule->new('Koha::Patron'); + $patron_class->mock( 'password_expired', sub { return $password_expired; } ); + + my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 1 } }); + my $password = 'password'; + t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); + $patron->set_password( { password => $password } ); + + my $cgi_mock = Test::MockModule->new('CGI')->mock( 'request_method', 'POST' ); + my $cgi = CGI->new; + $cgi->param( -name => 'userid', -value => $patron->userid ); + $cgi->param( -name => 'password', -value => $password ); + + my $auth = Test::MockModule->new( 'C4::Auth' ); + # Tests will fail if we hit safe_exit + $auth->mock( 'safe_exit', sub { return } ); + + my ( $userid, $cookie, $sessionID, $flags ); + + { + t::lib::Mocks::mock_preference( 'DumpTemplateVarsOpac', 1 ); + # checkauth will redirect and safe_exit if not authenticated and not authorized + local *STDOUT; + my $stdout; + open STDOUT, '>', \$stdout; + + # Password has expired + $password_expired = 1; + C4::Auth::checkauth( $cgi, 0, { catalogue => 1 } ); + like( $stdout, qr{'password_has_expired' => 1}, 'password_has_expired is set to 1' ); + + close STDOUT; + }; + }; + subtest 'Two-factor authentication' => sub { my $patron = $builder->build_object( -- 2.37.2