Bugzilla – Attachment 74521 Details for
Bug 20612
Make OAuth2 use patron's client_id/secret pairs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20612: Unit tests
Bug-20612-Unit-tests.patch (text/plain), 3.10 KB, created by
Benjamin Rokseth
on 2018-04-19 09:19:39 UTC
(
hide
)
Description:
Bug 20612: Unit tests
Filename:
MIME Type:
Creator:
Benjamin Rokseth
Created:
2018-04-19 09:19:39 UTC
Size:
3.10 KB
patch
obsolete
>From 57e37405c4b8e220dab763d767d252a11224f76f Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 18 Apr 2018 13:32:34 -0300 >Subject: [PATCH] Bug 20612: Unit tests > >This patch makes the oauth.t tests leverage on the new Koha::ApiKey(s) >classes. It adds tests for expired tokens too. > >To test: >- Apply this patch >- Run: > $ kshell > k$ prove t/db_dependent/api/v1/oauth.t >=> FAIL: Tests should fail without the rest of the patches. > >Sponsored-by: ByWater Solutions >Signed-off-by: Julian Maurice <julian.maurice@biblibre.com> >Signed-off-by: Benjamin Rokseth <benjamin.rokseth@deichman.no> >--- > t/db_dependent/api/v1/oauth.t | 34 +++++++++++++++++++++------------- > 1 file changed, 21 insertions(+), 13 deletions(-) > >diff --git a/t/db_dependent/api/v1/oauth.t b/t/db_dependent/api/v1/oauth.t >index eb95195..cc56293 100755 >--- a/t/db_dependent/api/v1/oauth.t >+++ b/t/db_dependent/api/v1/oauth.t >@@ -31,15 +31,14 @@ my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new(); > > subtest '/oauth/token tests' => sub { >- plan tests => 19; >+ plan tests => 24; > > $schema->storage->txn_begin; > > my $patron = $builder->build_object({ > class => 'Koha::Patrons', > value => { >- surname => 'Test OAuth', >- flags => 0, >+ flags => 0 # no permissions > }, > }); > >@@ -57,17 +56,12 @@ subtest '/oauth/token tests' => sub { > ->status_is(403) > ->json_is({error => 'unauthorized_client'}); > >- my ($client_id, $client_secret) = ('client1', 'secr3t'); >- t::lib::Mocks::mock_config('api_client', { >- 'client_id' => $client_id, >- 'client_secret' => $client_secret, >- patron_id => $patron->borrowernumber, >- }); >+ my $api_key = Koha::ApiKey->new({ patron_id => $patron->id, description => 'blah' })->store; > > my $formData = { >- grant_type => 'client_credentials', >- client_id => $client_id, >- client_secret => $client_secret, >+ grant_type => 'client_credentials', >+ client_id => $api_key->client_id, >+ client_secret => $api_key->secret > }; > $t->post_ok('/api/v1/oauth/token', form => $formData) > ->status_is(200) >@@ -87,9 +81,23 @@ subtest '/oauth/token tests' => sub { > > # With access token and permissions, it returns 200 > $patron->flags(2**4)->store; >- $tx = $t->ua->build_tx(GET => '/api/v1/patrons'); >+ $tx = $t->ua->build_tx(GET => '/api/v1/patrons/' . $patron->borrowernumber); > $tx->req->headers->authorization("Bearer $access_token"); > $t->request_ok($tx)->status_is(200); > >+ # expire token >+ my $token = Koha::OAuthAccessTokens->find($access_token); >+ $token->expires( time - 1 )->store; >+ $tx = $t->ua->build_tx( GET => '/api/v1/patrons' ); >+ $tx->req->headers->authorization("Bearer $access_token"); >+ $t->request_ok($tx) >+ ->status_is(401); >+ >+ # revoke key >+ $api_key->active(0)->store; >+ $t->post_ok('/api/v1/oauth/token', form => $formData) >+ ->status_is(403) >+ ->json_is({ error => 'unauthorized_client' }); >+ > $schema->storage->txn_rollback; > }; >-- >2.1.4
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 20612
:
74473
|
74474
|
74475
|
74483
|
74484
|
74485
|
74497
|
74498
|
74499
|
74521
|
74522
|
74523
|
74531
|
74532
|
74533
|
74534
|
74550
|
74551
|
74552
|
75024
|
75034
|
75035
|
75036
|
75037