From 5f4903c3d18f28416b90bd07e1a82f4adb4a1286 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 25 Feb 2021 09:43:11 -0300 Subject: [PATCH] Bug 27760: Make authenticate_api_request call stash_overrides By making this method call the helper, we make sure the overrides hashref is available to any controller to make us of it. To test: 1. Apply this patches 2. Run: $ kshell k$ prove t/db_dependent/api/v1/auth_authenticate_api_request.t \ t/Koha/REST/Plugin/Query.t => SUCCESS: Tests pass! The helper works as expected and the authenticate_api_request method invokes it! 3. Sign off :-D Signed-off-by: David Nind Signed-off-by: Kyle M Hall --- Koha/REST/V1/Auth.pm | 2 + .../api/v1/auth_authenticate_api_request.t | 40 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm index 3b5ab4c9a22..ea29bd69291 100644 --- a/Koha/REST/V1/Auth.pm +++ b/Koha/REST/V1/Auth.pm @@ -155,6 +155,8 @@ sub authenticate_api_request { my $spec = $c->openapi->spec || $c->match->endpoint->pattern->defaults->{'openapi.op_spec'}; $c->stash_embed({ spec => $spec }); + $c->stash_overrides(); + my $cookie_auth = 0; my $authorization = $spec->{'x-koha-authorization'}; diff --git a/t/db_dependent/api/v1/auth_authenticate_api_request.t b/t/db_dependent/api/v1/auth_authenticate_api_request.t index dddf93ca4a6..016aa9866d5 100755 --- a/t/db_dependent/api/v1/auth_authenticate_api_request.t +++ b/t/db_dependent/api/v1/auth_authenticate_api_request.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::Mojo; use Module::Load::Conditional qw(can_load); @@ -258,6 +258,44 @@ subtest 'x-koha-library tests' => sub { $schema->storage->txn_rollback; }; +subtest 'x-koha-override stash tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object({ + class => 'Koha::Patrons', + value => { flags => 1 } + }); + my $password = 'thePassword123'; + $patron->set_password({ password => $password, skip_validation => 1 }); + my $userid = $patron->userid; + + my $item = $builder->build_sample_item(); + + my $hold_data = { + patron_id => $patron->id, + biblio_id => $item->biblionumber, + item_id => $item->id, + pickup_library_id => $patron->branchcode, + }; + + my $stash; + + $t->app->hook(after_dispatch => sub { + $stash = shift->stash; + }); + + $t->post_ok( "//$userid:$password@/api/v1/holds" => { 'x-koha-override' => "any" } => json => $hold_data ); + + my $overrides = $stash->{'koha.overrides'}; + is( ref($overrides), 'HASH', 'arrayref returned' ); + ok( $overrides->{'any'}, "The value 'any' is found" ); + + $schema->storage->txn_rollback; +}; + sub create_user_and_session { my $args = shift; -- 2.31.1