Bugzilla – Attachment 179130 Details for
Bug 37286
Fix REST API authentication when using Mojo apps
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37286: Add tests for REST authentication through Mojo apps
Bug-37286-Add-tests-for-REST-authentication-throug.patch (text/plain), 2.49 KB, created by
Martin Renvoize (ashimema)
on 2025-03-10 17:31:50 UTC
(
hide
)
Description:
Bug 37286: Add tests for REST authentication through Mojo apps
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-03-10 17:31:50 UTC
Size:
2.49 KB
patch
obsolete
>From 776ea02d177d31b6c3461d55bf1cfaae7b9df4aa Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Fri, 24 Jan 2025 10:58:12 +0100 >Subject: [PATCH] Bug 37286: Add tests for REST authentication through Mojo > apps > >Amended-by: Jonathan Druart >Add +x > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/mojo/rest-auth.t | 57 +++++++++++++++++++++++++++++++++ > 1 file changed, 57 insertions(+) > create mode 100755 t/db_dependent/mojo/rest-auth.t > >diff --git a/t/db_dependent/mojo/rest-auth.t b/t/db_dependent/mojo/rest-auth.t >new file mode 100755 >index 00000000000..75384b95f7e >--- /dev/null >+++ b/t/db_dependent/mojo/rest-auth.t >@@ -0,0 +1,57 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+use Test::Mojo; >+ >+use Koha::Database; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->schema; >+my $builder = t::lib::TestBuilder->new(); >+ >+t::lib::Mocks::mock_preference( 'RESTOAuth2ClientCredentials', 1 ); >+ >+subtest 'REST Authentication - Intranet' => rest_auth_subtest('Koha::App::Intranet'); >+subtest 'REST Authentication - OPAC' => rest_auth_subtest('Koha::App::Opac'); >+ >+sub rest_auth_subtest { >+ my $app = shift; >+ >+ return sub { >+ plan tests => 12; >+ >+ $schema->storage->txn_begin; >+ >+ my $t = Test::Mojo->new($app); >+ >+ $t->post_ok('/api/v1/oauth/token')->status_is(400)->json_is( '/errors/0/message', 'Missing property.' ) >+ ->json_is( '/errors/0/path', '/grant_type' ); >+ >+ $t->post_ok( '/api/v1/oauth/token', form => { grant_type => 'client_credentials' } )->status_is(403) >+ ->json_is( '/error', 'unauthorized_client' ); >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { >+ flags => 0 # no permissions >+ }, >+ } >+ ); >+ my $api_key = Koha::ApiKey->new( { patron_id => $patron->id, description => 'blah' } )->store; >+ my $client_id = $api_key->client_id; >+ my $client_secret = $api_key->plain_text_secret; >+ >+ $t->post_ok( >+ '/api/v1/oauth/token', >+ form => { grant_type => 'client_credentials', client_id => $client_id, client_secret => $client_secret } >+ )->status_is(200)->json_is( '/expires_in' => 3600 )->json_is( '/token_type' => 'Bearer' ) >+ ->json_has('/access_token'); >+ >+ $schema->storage->txn_rollback; >+ } >+} >-- >2.48.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 37286
:
168644
|
176544
|
177101
|
179117
|
179118
|
179129
| 179130