Bugzilla – Attachment 84538 Details for
Bug 22132
Add Basic authentication to the REST API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22132: (QA follow-up) Tests - use Mojo builtin for auth
Bug-22132-QA-follow-up-Tests---use-Mojo-builtin-fo.patch (text/plain), 3.84 KB, created by
Tomás Cohen Arazi (tcohen)
on 2019-01-30 18:47:52 UTC
(
hide
)
Description:
Bug 22132: (QA follow-up) Tests - use Mojo builtin for auth
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2019-01-30 18:47:52 UTC
Size:
3.84 KB
patch
obsolete
>From 1f0a8d4ceba3a031485c1dd105b6abd3578f78e1 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 24 Jan 2019 15:54:08 +0000 >Subject: [PATCH] Bug 22132: (QA follow-up) Tests - use Mojo builtin for auth > >Mojolicious has built in handling for encoding/decoding of of basic auth >paramenters. We should use it to simplify our test here. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/api/v1/auth_basic.t | 42 ++++++++++-------------------- > 1 file changed, 14 insertions(+), 28 deletions(-) > >diff --git a/t/db_dependent/api/v1/auth_basic.t b/t/db_dependent/api/v1/auth_basic.t >index d689678cce..eba153a67d 100644 >--- a/t/db_dependent/api/v1/auth_basic.t >+++ b/t/db_dependent/api/v1/auth_basic.t >@@ -23,13 +23,10 @@ use Test::Mojo; > use t::lib::TestBuilder; > use t::lib::Mocks; > >-use MIME::Base64; >- > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > > my $t = Test::Mojo->new('Koha::REST::V1'); >-my $tx; > > subtest 'success tests' => sub { > >@@ -44,22 +41,19 @@ subtest 'success tests' => sub { > my $patron = $builder->build_object( > { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4 } } ); > $patron->set_password($password); >+ my $userid = $patron->userid; > >- my $credentials = encode_base64( $patron->userid . ':' . $password ); >- >- $tx = $t->ua->build_tx( GET => "/api/v1/patrons" ); >- $tx->req->headers->authorization("Basic $credentials"); >- $t->request_ok($tx)->status_is( 200, 'Successful authentication and permissions check' ); >+ $t->get_ok("//$userid:$password@/api/v1/patrons") >+ ->status_is( 200, 'Successful authentication and permissions check' ); > > $patron->flags(undef)->store; > >- $tx = $t->ua->build_tx( GET => "/api/v1/patrons" ); >- $tx->req->headers->authorization("Basic $credentials"); >- $t->request_ok($tx)->status_is( 403, 'Successful authentication and not enough permissions' ) >- ->json_is( >+ $t->get_ok("//$userid:$password@/api/v1/patrons") >+ ->status_is( 403, 'Successful authentication and not enough permissions' ) >+ ->json_is( > '/error' => 'Authorization failure. Missing required permission(s).', > 'Error message returned' >- ); >+ ); > > $schema->storage->txn_rollback; > }; >@@ -78,26 +72,18 @@ subtest 'failure tests' => sub { > my $patron = $builder->build_object( > { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4 } } ); > $patron->set_password($password); >+ my $userid = $patron->userid; > >- $tx = $t->ua->build_tx( GET => "/api/v1/patrons" ); >- $tx->req->headers->authorization("Basic "); >- $t->request_ok($tx)->status_is( 401, 'No credentials passed' ); >- >- $patron->flags(undef)->store; >- >- my $credentials = encode_base64( $patron->userid . ':' . $bad_password ); >- >- $tx = $t->ua->build_tx( GET => "/api/v1/patrons" ); >- $tx->req->headers->authorization("Basic $credentials"); >- $t->request_ok($tx)->status_is( 403, 'Successful authentication and not enough permissions' ) >- ->json_is( '/error' => 'Invalid password', 'Error message returned' ); >+ $t->get_ok("//@/api/v1/patrons") >+ ->status_is( 401, 'No credentials passed' ); > >+ $t->get_ok("//$userid:$bad_password@/api/v1/patrons") >+ ->status_is( 403, 'Failed authentication, invalid password' ) >+ ->json_is( '/error' => 'Invalid password', 'Error message returned' ); > > t::lib::Mocks::mock_preference( 'RESTBasicAuth', 0 ); > >- $tx = $t->ua->build_tx( GET => "/api/v1/patrons" ); >- $tx->req->headers->authorization("Basic $credentials"); >- $t->request_ok($tx) >+ $t->get_ok("//$userid:$password@/api/v1/patrons") > ->status_is( 401, 'Basic authentication is disabled' ) > ->json_is( '/error' => 'Basic authentication disabled', 'Expected error message rendered' ); > >-- >2.20.1
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 22132
:
83989
|
83990
|
83991
|
83993
|
83994
|
83995
|
84353
|
84354
|
84355
|
84361
|
84362
|
84363
|
84364
|
84365
|
84368
|
84369
|
84371
|
84535
|
84536
|
84537
| 84538 |
84539
|
85024