From fcb590282a3e98191e2fdc175f05b20517846197 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 2 May 2018 15:21:53 -0300 Subject: [PATCH] Bug 20624: Unit tests This patch adds tests to verify that disabling the RESTOAuth2ClientCredentials syspref makes any request on the /api/v1/oauth/token using the 'client_credentials' grant fail with 'grant not implemented'. To test: - Apply this patch - Run: $ kshell k$ prove t/db_dependent/api/v1/oauth.t => FAIL: Tests fail because the change is not implemented! Signed-off-by: Kyle M Hall --- t/db_dependent/api/v1/oauth.t | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/oauth.t b/t/db_dependent/api/v1/oauth.t index a07a2dba5d..e5762a2933 100755 --- a/t/db_dependent/api/v1/oauth.t +++ b/t/db_dependent/api/v1/oauth.t @@ -31,7 +31,7 @@ my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new(); subtest '/oauth/token tests' => sub { - plan tests => 24; + plan tests => 27; $schema->storage->txn_begin; @@ -51,6 +51,8 @@ subtest '/oauth/token tests' => sub { ->status_is(400) ->json_is({error => 'Unimplemented grant type'}); + t::lib::Mocks::mock_preference('RESTOAuth2ClientCredentials', 1); + # No client_id/client_secret $t->post_ok('/api/v1/oauth/token', form => { grant_type => 'client_credentials' }) ->status_is(403) @@ -99,5 +101,15 @@ subtest '/oauth/token tests' => sub { ->status_is(403) ->json_is({ error => 'unauthorized_client' }); + # disable client credentials grant + t::lib::Mocks::mock_preference('RESTOAuth2ClientCredentials', 0); + + # enable API key + $api_key->active(1)->store; + # Wrong grant type + $t->post_ok('/api/v1/oauth/token', form => $formData ) + ->status_is(400) + ->json_is({ error => 'Unimplemented grant type' }); + $schema->storage->txn_rollback; }; -- 2.15.1 (Apple Git-101)