From 6323e08ed7af6fa1cf76f93fc6ec8ae31aed2c8c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 28 Feb 2024 10:01:25 +0100 Subject: [PATCH] Bug 36084: Fix file upload and www/batch.t Signed-off-by: Jonathan Druart --- koha-tmpl/intranet-tmpl/prog/js/file-upload.js | 1 + t/db_dependent/www/batch.t | 4 ++-- t/lib/Mocks/Zebra.pm | 15 ++++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/file-upload.js b/koha-tmpl/intranet-tmpl/prog/js/file-upload.js index f6817cb823..b00bdb4a1f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/file-upload.js +++ b/koha-tmpl/intranet-tmpl/prog/js/file-upload.js @@ -5,6 +5,7 @@ function AjaxUpload ( input, progressbar, xtra, callback ) { $.each( input.prop('files'), function( dx, file ) { formData.append( "uploadfile", file ); }); + formData.append( "csrf_token", $('meta[name="csrf-token"]').attr('content') ); var xhr= new XMLHttpRequest(); var url= '/cgi-bin/koha/tools/upload-file.pl?' + xtra; progressbar.val( 0 ); diff --git a/t/db_dependent/www/batch.t b/t/db_dependent/www/batch.t index b902e58160..103d043323 100755 --- a/t/db_dependent/www/batch.t +++ b/t/db_dependent/www/batch.t @@ -79,8 +79,8 @@ else { my $agent = Test::WWW::Mechanize->new( autocheck => 1 ); $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' ); $agent->form_name('loginform'); -$agent->field( 'password', $password ); -$agent->field( 'userid', $user ); +$agent->field( 'login_password', $password ); +$agent->field( 'login_userid', $user ); $agent->field( 'branch', '' ); $agent->click_ok( '', 'login to staff interface' ); diff --git a/t/lib/Mocks/Zebra.pm b/t/lib/Mocks/Zebra.pm index 00c76ccf82..a82750a2de 100644 --- a/t/lib/Mocks/Zebra.pm +++ b/t/lib/Mocks/Zebra.pm @@ -23,6 +23,7 @@ use File::Path qw( rmtree ); use JSON qw( decode_json ); use C4::ImportBatch; use Koha::BackgroundJobs; +use Koha::Token; =head1 NAME @@ -130,8 +131,8 @@ sub load_records_ui { our $agent = Test::WWW::Mechanize->new( autocheck => 1 ); $agent->get_ok( "$cgi_root/mainpage.pl", 'connect to intranet' ); $agent->form_name('loginform'); - $agent->field( 'userid', $ENV{KOHA_PASS} ); - $agent->field( 'password', $ENV{KOHA_USER} ); + $agent->field( 'login_userid', $ENV{KOHA_PASS} ); + $agent->field( 'login_password', $ENV{KOHA_USER} ); $agent->field( 'branch', '' ); $agent->click_ok( '', 'login to staff interface' ); @@ -141,9 +142,11 @@ sub load_records_ui { $agent->follow_link_ok( { text => 'Stage records for import' }, 'go to stage MARC' ); + my $session_id = $agent->cookie_jar->get_cookies('koha.local')->{CGISESSID}; + my $csrf_token = Koha::Token->new->generate_csrf({session_id => $session_id}); $agent->post( "$cgi_root/tools/upload-file.pl?temp=1", - [ 'fileToUpload' => [$file], ], + [ 'fileToUpload' => [$file], csrf_token => $csrf_token ], 'Content_Type' => 'form-data', ); ok( $agent->success, 'uploaded file' ); @@ -156,7 +159,7 @@ sub load_records_ui { 'reopen stage MARC page' ); $agent->submit_form_ok( { - form_number => 5, + form_id => 'processfile', fields => { 'uploadedfileid' => $fileid, 'nomatch_action' => 'create_new', @@ -166,7 +169,9 @@ sub load_records_ui { 'comments' => '', 'encoding' => 'utf8', 'parse_items' => '1', - 'record_type' => 'biblio' + 'record_type' => 'biblio', + op => 'cud-stage', + csrf_token => $csrf_token, # TODO May need to retrieve another token if we invalid them at some point } }, 'stage MARC' -- 2.39.5