Bugzilla – Attachment 83994 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: Unit tests
Bug-22132-Unit-tests.patch (text/plain), 4.03 KB, created by
Tomás Cohen Arazi (tcohen)
on 2019-01-15 17:47:20 UTC
(
hide
)
Description:
Bug 22132: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2019-01-15 17:47:20 UTC
Size:
4.03 KB
patch
obsolete
>From 0ba96ef5ac779b445b7ece8998a1c36e75b46147 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 15 Jan 2019 13:23:09 -0300 >Subject: [PATCH] Bug 22132: Unit tests > >--- > t/db_dependent/api/v1/auth_basic.t | 107 +++++++++++++++++++++++++++++ > 1 file changed, 107 insertions(+) > create mode 100644 t/db_dependent/api/v1/auth_basic.t > >diff --git a/t/db_dependent/api/v1/auth_basic.t b/t/db_dependent/api/v1/auth_basic.t >new file mode 100644 >index 0000000000..d689678cce >--- /dev/null >+++ b/t/db_dependent/api/v1/auth_basic.t >@@ -0,0 +1,107 @@ >+#!/usr/bin/env perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+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 { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+ my $password = 'AbcdEFG123'; >+ >+ my $patron = $builder->build_object( >+ { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4 } } ); >+ $patron->set_password($password); >+ >+ 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' ); >+ >+ $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( >+ '/error' => 'Authorization failure. Missing required permission(s).', >+ 'Error message returned' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'failure tests' => sub { >+ >+ plan tests => 8; >+ >+ $schema->storage->txn_begin; >+ >+ my $password = 'AbcdEFG123'; >+ my $bad_password = '123456789'; >+ >+ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+ my $patron = $builder->build_object( >+ { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4 } } ); >+ $patron->set_password($password); >+ >+ $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::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) >+ ->status_is( 401, 'Basic authentication is disabled' ) >+ ->json_is( '/error' => 'Basic authentication disabled', 'Expected error message rendered' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+1; >-- >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