Bugzilla – Attachment 185991 Details for
Bug 29900
API calls should update datelastseen for API patron
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29900: Unit tests
Bug-29900-Unit-tests.patch (text/plain), 5.00 KB, created by
CJ Lynce
on 2025-08-29 21:27:43 UTC
(
hide
)
Description:
Bug 29900: Unit tests
Filename:
MIME Type:
Creator:
CJ Lynce
Created:
2025-08-29 21:27:43 UTC
Size:
5.00 KB
patch
obsolete
>From 58f12efbd4b0d8043a26398294af4549b3ca830c Mon Sep 17 00:00:00 2001 >From: CJ Lynce <cj.lynce@westlakelibrary.org> >Date: Fri, 29 Aug 2025 21:26:53 +0000 >Subject: [PATCH] Bug 29900: Unit tests > >This patch adds unit tests for the feature allowing to update 'lastseen' >for an API service user both through auth_basic and oauth2 > >To test: >1. Apply Patch >2. Run: #> prove t/db_dependent/api/v1/auth_basic.t > Verify all tests PASS >3. Run: #> prove prove t/db_dependent/api/v1/authenticate_api_request.t > Verify all tests PASS >--- > .../api/v1/auth_authenticate_api_request.t | 47 ++++++++++++++++++- > t/db_dependent/api/v1/auth_basic.t | 44 ++++++++++++++++- > 2 files changed, 89 insertions(+), 2 deletions(-) > >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 c314561fb9..ca2900932e 100755 >--- a/t/db_dependent/api/v1/auth_authenticate_api_request.t >+++ b/t/db_dependent/api/v1/auth_authenticate_api_request.t >@@ -45,7 +45,7 @@ t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); > subtest 'token-based tests' => sub { > > if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) { >- plan tests => 15; >+ plan tests => 16; > } else { > plan skip_all => 'Net::OAuth2::AuthorizationServer not available'; > } >@@ -110,6 +110,51 @@ subtest 'token-based tests' => sub { > ok( defined $embed, 'The embed hashref is generated and stashed' ); > is_deeply( $embed, { fund => {} }, 'The embed data structure is correct' ); > >+ subtest 'TrackLastPatronActivityTriggers tests for api_oauth2' => sub { >+ >+ plan tests => 6; >+ >+ $patron->lastseen(undef)->store; >+ >+ my $tx = $t->ua->build_tx( GET => '/api/v1/patrons' ); >+ $tx->req->headers->authorization("Bearer $access_token"); >+ $t->request_ok($tx); >+ >+ is( >+ $patron->lastseen, undef, >+ "'lastseen' is undefined" >+ ); >+ >+ #set login in TrackLastPatronActivity_Triggers >+ t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login' ); >+ >+ $patron->lastseen(undef)->store; >+ $tx = $t->ua->build_tx( GET => '/api/v1/patrons' ); >+ $tx->req->headers->authorization("Bearer $access_token"); >+ $t->request_ok($tx); >+ >+ $patron->discard_changes(); >+ is( >+ $patron->lastseen, undef, >+ "'lastseen' untouched if 'api_oauth2' is not enabled in TrackLastPatronActivityTriggers" >+ ); >+ >+ #set api_oauth2 in in TrackLastPatronActivity_Triggers >+ t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'api_oauth2' ); >+ >+ $patron->lastseen(undef)->store; >+ $tx = $t->ua->build_tx( GET => '/api/v1/patrons' ); >+ $tx->req->headers->authorization("Bearer $access_token"); >+ $t->request_ok($tx); >+ >+ $patron->discard_changes(); >+ ok( >+ $patron->lastseen, >+ "'lastseen' flag updated TrackLastPatronActivityTriggers includes 'api_oauth2'" >+ ); >+ >+ }; >+ > $schema->storage->txn_rollback; > }; > >diff --git a/t/db_dependent/api/v1/auth_basic.t b/t/db_dependent/api/v1/auth_basic.t >index 4d23949b4f..c5da793573 100755 >--- a/t/db_dependent/api/v1/auth_basic.t >+++ b/t/db_dependent/api/v1/auth_basic.t >@@ -33,7 +33,7 @@ my $t = Test::Mojo->new('Koha::REST::V1'); > > subtest 'success tests' => sub { > >- plan tests => 2; >+ plan tests => 3; > > $schema->storage->txn_begin; > >@@ -109,6 +109,48 @@ subtest 'success tests' => sub { > ); > }; > >+ subtest 'TrackLastPatronActivityTriggers tests for api_basic_auth' => sub { >+ >+ plan tests => 7; >+ >+ $patron->flags( 2**4 )->store; >+ >+ #set login in TrackLastPatronActivity_Triggers >+ t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login' ); >+ >+ $patron->lastseen(undef)->store; >+ $t->get_ok("//$cardnumber:$password@/api/v1/patrons"); >+ >+ $patron->discard_changes(); >+ is( >+ $patron->lastseen, undef, >+ "'lastseen' untouched if 'api_basic_auth' is not enabled in TrackLastPatronActivityTriggers" >+ ); >+ >+ #set api_oauth2 in in TrackLastPatronActivity_Triggers >+ t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'api_basic_auth' ); >+ >+ $patron->lastseen(undef)->store; >+ $t->get_ok("//$cardnumber:$password@/api/v1/patrons"); >+ $patron->discard_changes(); >+ >+ ok( >+ $patron->lastseen, >+ "'lastseen' flag updated TrackLastPatronActivityTriggers includes 'api_basic_auth'" >+ ); >+ >+ $patron->lastseen(undef)->store; >+ $t->get_ok("//$cardnumber:basspassword@/api/v1/patrons") >+ ->status_is( 403, 'Basic Auth fails due to bad password' ); >+ $patron->discard_changes(); >+ >+ is( >+ $patron->lastseen, undef, >+ "'lastseen' flag remains untouch due to Basic Auth authentication failure'" >+ ); >+ >+ }; >+ > $schema->storage->txn_rollback; > }; > >-- >2.39.5
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 29900
:
185533
|
185578
|
185579
|
185580
|
185581
|
185966
| 185991