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 <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomas Cohen Arazi 2021-02-25 09:43:11 -03:00 committed by Jonathan Druart
parent c2cc6b401a
commit 91ce8a098c
2 changed files with 41 additions and 1 deletions

View File

@ -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'};

View File

@ -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;