From 963a7e25d0db4e1ca89de27e217e2bb9476d8f25 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 8 Jun 2020 13:11:50 +0100 Subject: [PATCH] Bug 22522: Add support for current Mojolicious in 19.11 This patch allows tests to succeed with the following versions: JSON::Validator 3.18 Mojolicious 8.32 Mojolicious::Plugin::OpenAPI 2.21 Also Mojolicious::Plugin::OpenAPI version 1.17 and later 1.x versions now work. Calling valid_input in under() would cause ' Use of uninitialized value $_[2] ' in more recent OpenAPI plugins, so that was changed too. As far as I can see this does not affect authorization. --- Koha/REST/V1/Auth.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm index 8bffc977da..b20b9c8823 100644 --- a/Koha/REST/V1/Auth.pm +++ b/Koha/REST/V1/Auth.pm @@ -55,14 +55,14 @@ This subroutine is called before every request to API. =cut sub under { - my $c = shift->openapi->valid_input or return;; + my ( $c ) = @_; my $status = 0; try { # /api/v1/{namespace} - my $namespace = $c->req->url->to_abs->path->[2]; + my $namespace = $c->req->url->to_abs->path->[2] // ''; if ( $namespace eq 'public' and !C4::Context->preference('RESTPublicAPI') ) @@ -136,7 +136,10 @@ sub authenticate_api_request { my $user; - my $spec = $c->match->endpoint->pattern->defaults->{'openapi.op_spec'}; + # The following supports retrieval of spec with Mojolicious::Plugin::OpenAPI@1.17 and later (first one) + # and older versions (second one). + # TODO: remove the latter 'openapi.op_spec' if minimum version is bumped to at least 1.17. + my $spec = $c->openapi->spec || $c->match->endpoint->pattern->defaults->{'openapi.op_spec'}; my $authorization = $spec->{'x-koha-authorization'}; my $authorization_header = $c->req->headers->authorization; -- 2.20.1