From 4b0db676f803b376b9a6c32a6aac9cc5aa6f59ca Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 13 Apr 2020 11:40:44 -0300 Subject: [PATCH] Bug 25045: Unit tests Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- .../api/v1/auth_authenticate_api_request.t | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/auth_authenticate_api_request.t b/t/db_dependent/api/v1/auth_authenticate_api_request.t index 75348b90f5..de8578bfe0 100755 --- a/t/db_dependent/api/v1/auth_authenticate_api_request.t +++ b/t/db_dependent/api/v1/auth_authenticate_api_request.t @@ -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); @@ -141,6 +141,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; -- 2.20.1