Bugzilla – Attachment 75020 Details for
Bug 20624
Disable the OAuth2 client credentials grant by default
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20624: (QA follow-up) Unit tests for missing deps situation
Bug-20624-QA-follow-up-Unit-tests-for-missing-deps.patch (text/plain), 2.71 KB, created by
Tomás Cohen Arazi (tcohen)
on 2018-05-03 18:32:52 UTC
(
hide
)
Description:
Bug 20624: (QA follow-up) Unit tests for missing deps situation
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2018-05-03 18:32:52 UTC
Size:
2.71 KB
patch
obsolete
>From 31279334bbf64bfe7598815eae71aa326dd0464a Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 3 May 2018 15:24:56 -0300 >Subject: [PATCH] Bug 20624: (QA follow-up) Unit tests for missing deps > situation > >This patch tests the situation in which Net::OAuth2::AuthorizationServer >is missing. It mocks Module::Load::Conditional::can_load and expects the >/token endpoint answers 'Unimplemented grant type' to all requests, and >the 'authenticate_api_request' in 'under' exit with unauthorized (403) >to requests in which the Authorization header is passed containing a >Bearer token, but OAuth2 is not really available. > >To test: >- Apply this patch >- Run: > $ kshell > k$ prove t/db_dependent/api/v1/oauth.t >=> FAIL: Tests fail because our REST endpoints don't support this >behaviour. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/api/v1/oauth.t | 40 ++++++++++++++++++++++++++++++++++- > 1 file changed, 39 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/api/v1/oauth.t b/t/db_dependent/api/v1/oauth.t >index e5762a2933..2748fe25b3 100755 >--- a/t/db_dependent/api/v1/oauth.t >+++ b/t/db_dependent/api/v1/oauth.t >@@ -17,7 +17,8 @@ > > use Modern::Perl; > >-use Test::More tests => 1; >+use Test::More tests => 2; >+use Test::MockModule; > use Test::Mojo; > > use Koha::Database; >@@ -113,3 +114,40 @@ subtest '/oauth/token tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'Net::OAuth2::AuthorizationServer missing tests' => sub { >+ >+ plan tests => 10; >+ >+ my $load_conditional = Test::MockModule->new('Module::Load::Conditional'); >+ >+ # Enable the client credentials grant syspref >+ t::lib::Mocks::mock_preference( 'RESTOAuth2ClientCredentials', 1 ); >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 2**4 } }); >+ my $api_key = Koha::ApiKey->new({ patron_id => $patron->id, description => 'blah' })->store; >+ >+ my $form_data = { >+ grant_type => 'client_credentials', >+ client_id => $api_key->client_id, >+ client_secret => $api_key->secret >+ }; >+ >+ $t->post_ok( '/api/v1/oauth/token', form => $form_data )->status_is(200) >+ ->json_is( '/expires_in' => 3600 )->json_is( '/token_type' => 'Bearer' ) >+ ->json_has('/access_token'); >+ >+ my $access_token = $t->tx->res->json->{access_token}; >+ >+ $load_conditional->mock( 'can_load', sub { return 0; } ); >+ >+ my $tx = $t->ua->build_tx( GET => '/api/v1/patrons' ); >+ $tx->req->headers->authorization("Bearer $access_token"); >+ $t->request_ok($tx) >+ ->status_is(403); >+ >+ $t->post_ok( '/api/v1/oauth/token', form => $form_data ) >+ ->status_is(400) >+ ->json_is( { error => 'Unimplemented grant type' } ); >+ >+}; >-- >2.17.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20624
:
74986
|
74987
|
74988
|
74989
|
75020
|
75021
|
75060
|
75061
|
75062
|
75063
|
75064
|
75065
|
75132
|
75184
|
75206