From 17e8acad70c778a1d544ad2cb22e0fc98ba2f312 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 8 May 2018 14:58:55 -0300 Subject: [PATCH] Bug 20624: Net::OAuth2::AuthorizationServer is not a hard dependency While we get packaging sorted, Net::OAuth2::AuthorizationServer is not a hard dependency for Koha and the feature requiring it is disabled by default. This patch: - Makes the dependency optional - Makes the unit tests for the OAuth2 client credentials flow skip if the dependency is not met. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- C4/Installer/PerlDependencies.pm | 2 +- Koha/REST/V1/Auth.pm | 3 ++- Koha/REST/V1/OAuth.pm | 3 ++- t/db_dependent/api/v1/oauth.t | 13 ++++++++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index ffc8661380..6229742b65 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -890,7 +890,7 @@ our $PERL_DEPS = { }, 'Net::OAuth2::AuthorizationServer' => { usage => 'REST API', - required => '1', + required => '0', min_ver => '0.16', }, }; diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm index b2ccd6b59e..afbe468288 100644 --- a/Koha/REST/V1/Auth.pm +++ b/Koha/REST/V1/Auth.pm @@ -120,7 +120,8 @@ sub authenticate_api_request { if ($authorization_header and $authorization_header =~ /^Bearer /) { # attempt to use OAuth2 authentication - if ( ! Module::Load::Conditional::can_load('Net::OAuth2::AuthorizationServer') ) { + if ( ! Module::Load::Conditional::can_load( + modules => {'Net::OAuth2::AuthorizationServer' => undef} )) { Koha::Exceptions::Authorization::Unauthorized->throw( error => 'Authentication failure.' ); diff --git a/Koha/REST/V1/OAuth.pm b/Koha/REST/V1/OAuth.pm index 3679dbecdc..b75c89243c 100644 --- a/Koha/REST/V1/OAuth.pm +++ b/Koha/REST/V1/OAuth.pm @@ -40,7 +40,8 @@ sub token { my $c = shift->openapi->valid_input or return; - if ( Module::Load::Conditional::can_load('Net::OAuth2::AuthorizationServer') ) { + if ( Module::Load::Conditional::can_load( + modules => {'Net::OAuth2::AuthorizationServer' => undef} )) { require Net::OAuth2::AuthorizationServer; } else { diff --git a/t/db_dependent/api/v1/oauth.t b/t/db_dependent/api/v1/oauth.t index 2748fe25b3..16e273cedd 100755 --- a/t/db_dependent/api/v1/oauth.t +++ b/t/db_dependent/api/v1/oauth.t @@ -17,10 +17,13 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More; use Test::MockModule; use Test::Mojo; +use Module::Load::Conditional qw(can_load); + +use Koha::ApiKeys; use Koha::Database; use Koha::Patrons; @@ -31,7 +34,15 @@ my $t = Test::Mojo->new('Koha::REST::V1'); my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new(); +if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) { + plan tests => 2; +} +else { + plan skip_all => 'Net::OAuth2::AuthorizationServer not available'; +} + subtest '/oauth/token tests' => sub { + plan tests => 27; $schema->storage->txn_begin; -- 2.39.5