Bugzilla – Attachment 84365 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.76 KB, created by
Martin Renvoize (ashimema)
on 2019-01-24 16:37:16 UTC
(
hide
)
Description:
Bug 22132: (QA follow-up) Tests - use Mojo builtin for auth
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2019-01-24 16:37:16 UTC
Size:
3.76 KB
patch
obsolete
>From 7c035dd1267eda785e0e06726835c56810a45edd 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 | 41 ++++++++++-------------------- > 1 file changed, 14 insertions(+), 27 deletions(-) > >diff --git a/t/db_dependent/api/v1/auth_basic.t b/t/db_dependent/api/v1/auth_basic.t >index d689678cce..3c29fa9eb2 100644 >--- a/t/db_dependent/api/v1/auth_basic.t >+++ b/t/db_dependent/api/v1/auth_basic.t >@@ -23,8 +23,6 @@ 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; > >@@ -44,22 +42,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 +73,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("//$userid:@/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