From 449b0ea3630c65522e0cb38b77bbcece07393313 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 25 Oct 2024 14:35:39 +0000 Subject: [PATCH] Bug 36822: Shibboleth - Add tests prove t/db_dependent/Auth_with_shibboleth.t Signed-off-by: David Nind --- t/db_dependent/Auth_with_shibboleth.t | 33 +++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Auth_with_shibboleth.t b/t/db_dependent/Auth_with_shibboleth.t index 440eef2a1f..886efbe685 100755 --- a/t/db_dependent/Auth_with_shibboleth.t +++ b/t/db_dependent/Auth_with_shibboleth.t @@ -20,7 +20,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 5; +use Test::More tests => 6; use Test::MockModule; use Test::Warn; use CGI qw(-utf8 ); @@ -32,6 +32,14 @@ use t::lib::TestBuilder; use C4::Auth_with_shibboleth qw( shib_ok login_shib_url get_login_shib checkpw_shib ); use Koha::Database; +use Koha::DateUtils qw( dt_from_string ); + +BEGIN { + use_ok( + 'C4::Auth', + qw( checkpw ) + ); +} my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; @@ -156,7 +164,7 @@ subtest "get_login_shib tests" => sub { subtest "checkpw_shib tests" => sub { - plan tests => 52; + plan tests => 54; # Test borrower data my $test_borrowers = [ @@ -288,6 +296,27 @@ subtest "checkpw_shib tests" => sub { is( $retuserid, undef ); is( $retpatron, undef ); $logger->info_is("No users with userid of martin found and autocreate is disabled", "Missing matchpoint warned to info"); + + # autocreate user from checkpw) + change_config({ autocreate => 1, welcome => 1 }); + $shib_login = 'test43210'; + $ENV{'uid'} = 'test43210'; + $ENV{'sn'} = "pika"; + $ENV{'exp'} = "2017-01-01"; + $ENV{'cat'} = $category->categorycode; + $ENV{'add'} = 'Address'; + $ENV{'city'} = 'City'; + $ENV{'emailpro'} = 'me@myemail.com'; + $ENV{branchcode} = $library->branchcode; # needed since T::D::C does no longer hides the FK constraint + + checkpw($shib_login); + ok my $new_user_autocreated = $schema->resultset('Borrower') + ->search( { 'userid' => 'test43210' }, { rows => 1 } ), "new user found"; + + my $rec_autocreated = $new_user_autocreated->next; + is_deeply( [ map { $rec_autocreated->$_ } qw/updated_on/ ], + [dt_from_string()->ymd.' '.dt_from_string()->hms], + 'updated_on correctly saved on newly created user' ); }; subtest 'get_uri' => sub { -- 2.39.5