Bug 25045: Unit tests

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 78cb447c7c)

Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>
This commit is contained in:
Tomas Cohen Arazi 2020-04-13 11:40:44 -03:00 committed by Aleisha Amohia
parent 811d468dc4
commit 554cf13b1b
1 changed files with 34 additions and 1 deletions

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 2;
use Test::More tests => 3;
use Test::Mojo;
use Module::Load::Conditional qw(can_load);
@ -138,6 +138,39 @@ subtest 'cookie-based tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'anonymous requests to public API' => sub {
plan tests => 4;
$schema->storage->txn_begin;
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
my $password = 'AbcdEFG123';
my $userid = 'tomasito';
# Add a patron
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
$patron->set_password({ password => $password });
# Add a biblio
my $biblio_id = $builder->build_sample_biblio()->biblionumber;
# Enable the public API
t::lib::Mocks::mock_preference( 'RESTPublicAPI', 1 );
# Disable anonymous requests on the public namespace
t::lib::Mocks::mock_preference( 'RESTPublicAnonymousRequests', 0 );
$t->get_ok("/api/v1/public/biblios/" . $biblio_id => { Accept => 'application/marc' })
->status_is( 401, 'Unauthorized anonymous attempt to access a resource' );
# Disable anonymous requests on the public namespace
t::lib::Mocks::mock_preference( 'RESTPublicAnonymousRequests', 1 );
$t->get_ok("/api/v1/public/biblios/" . $biblio_id => { Accept => 'application/marc' })
->status_is( 200, 'Successfull anonymous access to a resource' );
$schema->storage->txn_rollback;
};
sub create_user_and_session {
my $args = shift;