From 783fb7ea9d0b9c87403446a059a3ae1df017c585 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 4 Nov 2025 09:22:06 +0100 Subject: [PATCH] Bug 40943: Fix Koha/BackgroundJob.t We should not log/leak session_id! Failed test 'Context set from userenv + interface' at t/db_dependent/Koha/BackgroundJob.t line 132. Structures begin differing at: $got->{session_id} = undef $expected->{session_id} = Does not exist Looks like you failed 1 test of 10. Failed test 'enqueue() tests' at t/db_dependent/Koha/BackgroundJob.t line 135. Failed test 'Userenv set from job context on process' at t/db_dependent/Koha/BackgroundJob.t line 240. Structures begin differing at: $got->{session_id} = undef $expected->{session_id} = Does not exist Looks like you failed 1 test of 5. --- Koha/BackgroundJob.pm | 3 +++ t/db_dependent/Koha/BackgroundJob.t | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index 8f44386c3e8..0ff204281d6 100644 --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -125,6 +125,9 @@ sub enqueue { my $job_queue = $params->{job_queue} // 'default'; my $json = $self->json; + # session_id must not be logged + delete $job_context->{session_id}; + my $borrowernumber = ( C4::Context->userenv ) ? C4::Context->userenv->{number} : undef; $job_context->{interface} = C4::Context->interface; my $json_context = $json->encode($job_context); diff --git a/t/db_dependent/Koha/BackgroundJob.t b/t/db_dependent/Koha/BackgroundJob.t index 7caa2b64b28..42d87790d16 100755 --- a/t/db_dependent/Koha/BackgroundJob.t +++ b/t/db_dependent/Koha/BackgroundJob.t @@ -119,7 +119,9 @@ subtest 'enqueue() tests' => sub { shibboleth => undef, desk_id => undef, desk_name => undef, - interface => $interface + interface => $interface, + + # session_id must not be logged! }; $job_id = Koha::BackgroundJob::BatchUpdateItem->new->enqueue( { record_ids => [ 1, 2, 3 ] } ); @@ -218,6 +220,8 @@ subtest 'process tests' => sub { shibboleth => undef, desk_id => undef, desk_name => undef, + + # session_id must not be logged! }; my $background_job_module = Test::MockModule->new('Koha::BackgroundJob'); @@ -237,7 +241,9 @@ subtest 'process tests' => sub { is( C4::Context->interface, 'opac', "Interface set to opac prior to calling process" ); $job->process(); - is_deeply( C4::Context->userenv, $job_context, "Userenv set from job context on process" ); + my $expected_context = C4::Context->userenv; + delete $expected_context->{session_id}; + is_deeply( $expected_context, $job_context, "Userenv set from job context on process" ); is_deeply( C4::Context->interface, 'intranet', "Interface set from job context on process" ); # Manually add a job (->new->store) without context -- 2.34.1