From fd6d58bb4bf1c5628a7bfc7c26e4de66230aa1a5 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 29 Apr 2025 16:26:39 +0000 Subject: [PATCH 1/5] Bug 36867: (follow-up) Don't check IP if ILS-DI disabled When ILS-DI is disabled we still expect to return the correct service name/section in the xml, but just indicate that it is disabled. We should skip the check for authorized IPs in this case, as the IP only matters when service is enabled Signed-off-by: wainuiwitikapark --- opac/ilsdi.pl | 58 ++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/opac/ilsdi.pl b/opac/ilsdi.pl index 422df4ccc7..b5d80f9803 100755 --- a/opac/ilsdi.pl +++ b/opac/ilsdi.pl @@ -159,36 +159,38 @@ my $out; unless ( C4::Context->preference('ILS-DI') ) { $out->{'code'} = "NotAllowed"; $out->{'message'} = "ILS-DI is disabled."; -} - -# If the remote address is not allowed, redirect to 403 -my @AuthorizedIPs = split( /,/, C4::Context->preference('ILS-DI:AuthorizedIPs') ); -if (@AuthorizedIPs) { # If no filter set, allow access to everybody - my $authorized = 0; - foreach my $ip (@AuthorizedIPs) { - my $netmask = Net::Netmask->new2($ip); - if ( $netmask && $netmask->match( $ENV{REMOTE_ADDR} ) ) { - $authorized = 1; - last; - } - } - unless ($authorized) { - $out->{'code'} = "NotAllowed"; - $out->{'message'} = "Unauthorized IP address: $ENV{REMOTE_ADDR}."; - } } else { - $out->{'code'} = "NotAllowed"; - $out->{'message'} = "Unauthorized IP address: $ENV{REMOTE_ADDR}."; - print XMLout( - $out, - noattr => 1, - nosort => 1, - xmldecl => '', - RootName => "ilsdi", - SuppressEmpty => 1 - ); - exit 0; + # If the remote address is not allowed, redirect to 403 + my @AuthorizedIPs = split( /,/, C4::Context->preference('ILS-DI:AuthorizedIPs') ); + if (@AuthorizedIPs) { # If no filter set, allow access to everybody + my $authorized = 0; + foreach my $ip (@AuthorizedIPs) { + my $netmask = Net::Netmask->new2($ip); + if ( $netmask && $netmask->match( $ENV{REMOTE_ADDR} ) ) { + $authorized = 1; + last; + } + } + unless ($authorized) { + $out->{'code'} = "NotAllowed"; + $out->{'message'} = "Unauthorized IP address: $ENV{REMOTE_ADDR}."; + } + } else { + $out->{'code'} = "NotAllowed"; + $out->{'message'} = "Unauthorized IP address: $ENV{REMOTE_ADDR}."; + + print XMLout( + $out, + noattr => 1, + nosort => 1, + xmldecl => '', + RootName => "ilsdi", + SuppressEmpty => 1 + ); + exit 0; + } + } my $service = $cgi->param('service') || "ilsdi"; From b9fbacfe6015c90b3fded082a8db722a9ecd5ff3 Mon Sep 17 00:00:00 2001 From: Wainui Witika-Park Date: Wed, 21 May 2025 13:43:41 +1200 Subject: [PATCH 2/5] Revert "Bug 38782: mock_userenv in API tests" This reverts commit 3b70d648ed1ec5f95c5a1d6194e45d221424de9f. --- t/db_dependent/api/v1/erm_custom_reports.t | 164 ++++++++++----------- 1 file changed, 80 insertions(+), 84 deletions(-) diff --git a/t/db_dependent/api/v1/erm_custom_reports.t b/t/db_dependent/api/v1/erm_custom_reports.t index fcb7eba1b0..1317c61761 100755 --- a/t/db_dependent/api/v1/erm_custom_reports.t +++ b/t/db_dependent/api/v1/erm_custom_reports.t @@ -50,27 +50,6 @@ subtest "monthly_report" => sub { $schema->storage->txn_begin; - my $librarian = $builder->build_object( - { - class => 'Koha::Patrons', - value => { flags => 2**28 } - } - ); - my $password = 'thePassword123'; - $librarian->set_password( { password => $password, skip_validation => 1 } ); - my $userid = $librarian->userid; - t::lib::Mocks::mock_userenv( { number => $userid } ); - - my $patron = $builder->build_object( - { - class => 'Koha::Patrons', - value => { flags => 0 } - } - ); - - $patron->set_password( { password => $password, skip_validation => 1 } ); - my $unauth_userid = $patron->userid; - # Run a harvest to populate the database with data my $usage_data_provider = $builder->build_object( { class => 'Koha::ERM::EUsage::UsageDataProviders' } ); my $counter_file = $sushi_counter_TR_J1->get_COUNTER_from_SUSHI; @@ -85,6 +64,26 @@ subtest "monthly_report" => sub { ] ); + my $librarian = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 2**28 } + } + ); + my $password = 'thePassword123'; + $librarian->set_password( { password => $password, skip_validation => 1 } ); + my $userid = $librarian->userid; + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 0 } + } + ); + + $patron->set_password( { password => $password, skip_validation => 1 } ); + my $unauth_userid = $patron->userid; + # Unauthorized access $t->get_ok("//$unauth_userid:$password@/api/v1/erm/eUsage/monthly_report/title")->status_is(403); @@ -149,27 +148,6 @@ subtest "yearly_report" => sub { $schema->storage->txn_begin; - my $librarian = $builder->build_object( - { - class => 'Koha::Patrons', - value => { flags => 2**28 } - } - ); - my $password = 'thePassword123'; - $librarian->set_password( { password => $password, skip_validation => 1 } ); - my $userid = $librarian->userid; - t::lib::Mocks::mock_userenv( { number => $userid } ); - - my $patron = $builder->build_object( - { - class => 'Koha::Patrons', - value => { flags => 0 } - } - ); - - $patron->set_password( { password => $password, skip_validation => 1 } ); - my $unauth_userid = $patron->userid; - # Run a harvest to populate the database with data my $usage_data_provider = $builder->build_object( { class => 'Koha::ERM::EUsage::UsageDataProviders' } ); my $counter_file = $sushi_counter_TR_J1->get_COUNTER_from_SUSHI; @@ -184,6 +162,26 @@ subtest "yearly_report" => sub { ] ); + my $librarian = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 2**28 } + } + ); + my $password = 'thePassword123'; + $librarian->set_password( { password => $password, skip_validation => 1 } ); + my $userid = $librarian->userid; + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 0 } + } + ); + + $patron->set_password( { password => $password, skip_validation => 1 } ); + my $unauth_userid = $patron->userid; + # Unauthorized access $t->get_ok("//$unauth_userid:$password@/api/v1/erm/eUsage/yearly_report/title")->status_is(403); @@ -239,27 +237,6 @@ subtest "metric_types_report" => sub { $schema->storage->txn_begin; - my $librarian = $builder->build_object( - { - class => 'Koha::Patrons', - value => { flags => 2**28 } - } - ); - my $password = 'thePassword123'; - $librarian->set_password( { password => $password, skip_validation => 1 } ); - my $userid = $librarian->userid; - t::lib::Mocks::mock_userenv( { number => $userid } ); - - my $patron = $builder->build_object( - { - class => 'Koha::Patrons', - value => { flags => 0 } - } - ); - - $patron->set_password( { password => $password, skip_validation => 1 } ); - my $unauth_userid = $patron->userid; - # Run a harvest to populate the database with data my $usage_data_provider = $builder->build_object( { class => 'Koha::ERM::EUsage::UsageDataProviders' } ); my $counter_file = $sushi_counter_TR_J1->get_COUNTER_from_SUSHI; @@ -274,6 +251,26 @@ subtest "metric_types_report" => sub { ] ); + my $librarian = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 2**28 } + } + ); + my $password = 'thePassword123'; + $librarian->set_password( { password => $password, skip_validation => 1 } ); + my $userid = $librarian->userid; + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 0 } + } + ); + + $patron->set_password( { password => $password, skip_validation => 1 } ); + my $unauth_userid = $patron->userid; + # Unauthorized access $t->get_ok("//$unauth_userid:$password@/api/v1/erm/eUsage/metric_types_report/title")->status_is(403); @@ -335,27 +332,6 @@ subtest "provider_rollup_report" => sub { $schema->storage->txn_begin; - my $librarian = $builder->build_object( - { - class => 'Koha::Patrons', - value => { flags => 2**28 } - } - ); - my $password = 'thePassword123'; - $librarian->set_password( { password => $password, skip_validation => 1 } ); - my $userid = $librarian->userid; - t::lib::Mocks::mock_userenv( { number => $userid } ); - - my $patron = $builder->build_object( - { - class => 'Koha::Patrons', - value => { flags => 0 } - } - ); - - $patron->set_password( { password => $password, skip_validation => 1 } ); - my $unauth_userid = $patron->userid; - # Run a harvest to populate the database with data my $usage_data_provider = $builder->build_object( { class => 'Koha::ERM::EUsage::UsageDataProviders' } ); my $counter_file = $sushi_counter_TR_J1->get_COUNTER_from_SUSHI; @@ -370,6 +346,26 @@ subtest "provider_rollup_report" => sub { ] ); + my $librarian = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 2**28 } + } + ); + my $password = 'thePassword123'; + $librarian->set_password( { password => $password, skip_validation => 1 } ); + my $userid = $librarian->userid; + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 0 } + } + ); + + $patron->set_password( { password => $password, skip_validation => 1 } ); + my $unauth_userid = $patron->userid; + # Unauthorized access $t->get_ok("//$unauth_userid:$password@/api/v1/erm/eUsage/provider_rollup_report/title")->status_is(403); From c1bb46670a9bcac12df57d43827f6ec0021c76d7 Mon Sep 17 00:00:00 2001 From: Wainui Witika-Park Date: Wed, 21 May 2025 13:43:48 +1200 Subject: [PATCH 3/5] Revert "Bug 38782: Apply same fix for CounterFile.t" This reverts commit 549031d41b213c1b7441ee52ed032bdd253f1aee. --- t/db_dependent/Koha/ERM/EUsage/CounterFile.t | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/t/db_dependent/Koha/ERM/EUsage/CounterFile.t b/t/db_dependent/Koha/ERM/EUsage/CounterFile.t index 7d36fe82e6..65c363fa52 100755 --- a/t/db_dependent/Koha/ERM/EUsage/CounterFile.t +++ b/t/db_dependent/Koha/ERM/EUsage/CounterFile.t @@ -22,7 +22,7 @@ use Test::More tests => 2; use Koha::Database; use Koha::ERM::EUsage::CounterFile; -use JSON qw( decode_json ); +use JSON qw( decode_json ); use File::Basename qw( dirname ); use File::Slurp; @@ -46,9 +46,6 @@ subtest 'store' => sub { $schema->storage->txn_begin; - my $patron = Koha::Patrons->search()->last; - t::lib::Mocks::mock_userenv( { number => $patron->borrowernumber } ); # Is superlibrarian - my $usage_data_provider = $builder->build_object( { class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } ); $usage_data_provider->{report_type} = 'TR_J1'; From 81963ab4520ce602be7c626cf39ce90d6c999cb1 Mon Sep 17 00:00:00 2001 From: Wainui Witika-Park Date: Wed, 21 May 2025 13:43:54 +1200 Subject: [PATCH 4/5] Revert "Bug 38782: Remove concat in background process" This reverts commit 1013d5b74eca448ccd2fa059a6144d0691e3385b. --- Koha/BackgroundJob/ErmSushiHarvester.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Koha/BackgroundJob/ErmSushiHarvester.pm b/Koha/BackgroundJob/ErmSushiHarvester.pm index da4721952b..5dadc0b60f 100644 --- a/Koha/BackgroundJob/ErmSushiHarvester.pm +++ b/Koha/BackgroundJob/ErmSushiHarvester.pm @@ -92,7 +92,7 @@ sub process { usage_data_provider_id => $ud_provider->erm_usage_data_provider_id, file_content => $args->{file_content}, date_uploaded => POSIX::strftime( "%Y%m%d%H%M%S", localtime ), - filename => $ud_provider->name, + filename => $ud_provider->name . "_" . $ud_provider->{report_type}, } ] ); From 986573c909628ae81da0d0532e8970a4dde85b12 Mon Sep 17 00:00:00 2001 From: Wainui Witika-Park Date: Wed, 21 May 2025 13:44:00 +1200 Subject: [PATCH 5/5] Revert "Bug 38782: Mock userenv->{number}" This reverts commit de3999c6b892459d18aac547d0ca155545f33a76. --- t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t b/t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t index f819e5d995..ace123e7d4 100755 --- a/t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t +++ b/t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t @@ -23,7 +23,7 @@ use Koha::Database; use Koha::BackgroundJobs; use Koha::BackgroundJob::ErmSushiHarvester; -use JSON qw( decode_json ); +use JSON qw( decode_json ); use File::Basename qw( dirname ); use File::Slurp; @@ -86,9 +86,6 @@ subtest 'enqueue_sushi_harvest_jobs' => sub { $schema->storage->txn_begin; - my $patron = Koha::Patrons->search()->last; - t::lib::Mocks::mock_userenv( { number => $patron->borrowernumber } ); # Is superlibrarian - my $usage_data_provider = $builder->build_object( { class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } );