From 110170760c3ae2b4ec842bca651f767b71dd0701 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 30 Dec 2019 15:34:43 -0300 Subject: [PATCH] Bug 18731: Make authenticate_api_request stash the embed structure Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize --- Koha/REST/V1/Auth.pm | 3 +++ .../api/v1/auth_authenticate_api_request.t | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm index 8bffc977da..57aea11905 100644 --- a/Koha/REST/V1/Auth.pm +++ b/Koha/REST/V1/Auth.pm @@ -137,6 +137,9 @@ sub authenticate_api_request { my $user; my $spec = $c->match->endpoint->pattern->defaults->{'openapi.op_spec'}; + + $c->stash_embed({ spec => $spec }); + my $authorization = $spec->{'x-koha-authorization'}; my $authorization_header = $c->req->headers->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 8583125a9f..f688e209f5 100755 --- a/t/db_dependent/api/v1/auth_authenticate_api_request.t +++ b/t/db_dependent/api/v1/auth_authenticate_api_request.t @@ -44,7 +44,7 @@ t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); subtest 'token-based tests' => sub { if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) { - plan tests => 10; + plan tests => 12; } else { plan skip_all => 'Net::OAuth2::AuthorizationServer not available'; @@ -54,9 +54,7 @@ subtest 'token-based tests' => sub { my $patron = $builder->build_object({ class => 'Koha::Patrons', - value => { - flags => 16 # no permissions - }, + value => { flags => 1 }, }); t::lib::Mocks::mock_preference('RESTOAuth2ClientCredentials', 1); @@ -81,8 +79,9 @@ subtest 'token-based tests' => sub { my $stash; - my $tx = $t->ua->build_tx(GET => '/api/v1/patrons'); + my $tx = $t->ua->build_tx(GET => '/api/v1/acquisitions/orders'); $tx->req->headers->authorization("Bearer $access_token"); + $tx->req->headers->header( 'x-koha-embed' => 'fund' ); $t->app->hook(after_dispatch => sub { $stash = shift->stash }); $t->request_ok($tx)->status_is(200); @@ -92,6 +91,10 @@ subtest 'token-based tests' => sub { is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' ); + my $embed = $stash->{'koha.embed'}; + ok( defined $embed, 'The embed hashref is generated and stashed' ); + is_deeply( $embed, { fund => {} }, 'The embed data structure is correct' ); + $schema->storage->txn_rollback; }; -- 2.39.5