@@ -, +, @@ structure --- Koha/REST/V1/Auth.pm | 3 +++ .../api/v1/auth_authenticate_api_request.t | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) --- a/Koha/REST/V1/Auth.pm +++ a/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; --- a/t/db_dependent/api/v1/auth_authenticate_api_request.t +++ a/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; }; --