Bug 33782 - OAuth2/OIDC identity providers code is not covered by unit tests
Summary: OAuth2/OIDC identity providers code is not covered by unit tests
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Authentication (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Tomás Cohen Arazi (tcohen)
QA Contact: Testopia
URL:
Keywords:
Depends on: 33675
Blocks:
  Show dependency treegraph
 
Reported: 2023-05-19 10:30 UTC by Nick Clemens (kidclamp)
Modified: 2025-12-09 01:04 UTC (History)
4 users (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 33782: Add unit tests for Koha::Auth::Client::OAuth (8.73 KB, patch)
2025-09-20 14:32 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 33782: (follow-up) Remove code duplication in OAuth client (2.79 KB, patch)
2025-09-20 14:32 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 33782: Add unit tests for Koha::Auth::Client::OAuth (8.78 KB, patch)
2025-12-08 19:04 UTC, David Nind
Details | Diff | Splinter Review
Bug 33782: (follow-up) Remove code duplication in OAuth client (2.83 KB, patch)
2025-12-08 19:04 UTC, David Nind
Details | Diff | Splinter Review
Bug 33782: Add unit tests for Koha::Auth::Client::OAuth (8.78 KB, patch)
2025-12-09 01:03 UTC, David Nind
Details | Diff | Splinter Review
Bug 33782: (follow-up) Remove code duplication in OAuth client (2.84 KB, patch)
2025-12-09 01:03 UTC, David Nind
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Clemens (kidclamp) 2023-05-19 10:30:30 UTC
We need to provide tests for this code. It will require mocking, or using the Mojo mocking, but should be done before we add more in this area.
Comment 1 Tomás Cohen Arazi (tcohen) 2025-09-20 14:32:48 UTC
Created attachment 186630 [details] [review]
Bug 33782: Add unit tests for Koha::Auth::Client::OAuth

This patch adds comprehensive unit tests for the OAuth authentication
client, specifically covering the _get_data_and_patron method which
handles JWT token processing and UserInfo endpoint integration.

Test plan:
1. Apply patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/Koha/Auth/Client/OAuth.t
=> SUCCESS: Tests pass!
3. Tests cover:
   - JWT id_token processing and patron matching
   - UserInfo endpoint calls and data merging
   - Non-existent user scenarios
   - Combined JWT + UserInfo data sources
4. Sign off :-D

status: Needs Signoff
Comment 2 Tomás Cohen Arazi (tcohen) 2025-09-20 14:32:51 UTC
Created attachment 186631 [details] [review]
Bug 33782: (follow-up) Remove code duplication in OAuth client

This patch eliminates duplicated patron search logic in the
_get_data_and_patron method by extracting it into a dedicated
helper method _find_patron_by_matchpoint.

Changes:
- Extract duplicated patron search logic (8 lines removed)
- Add _find_patron_by_matchpoint helper method
- Improve code maintainability and readability
- No functional changes - behavior preserved

Test plan:
1. Apply patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/Koha/Auth/Client/OAuth.t
=> SUCCESS: Tests pass! OAuth client tests work correctly
  k$ prove t/db_dependent/api/v1/oauth.t
=> SUCCESS: Tests pass! OAuth API integration works
3. Confirm OAuth authentication still works in browser
4. Sign off :-D
Comment 3 David Nind 2025-12-08 19:04:52 UTC Comment hidden (obsolete)
Comment 4 David Nind 2025-12-08 19:04:55 UTC Comment hidden (obsolete)
Comment 5 David Nind 2025-12-08 19:07:44 UTC
I've signed off as the tests pass (and it has been sitting in the needs sign-off queue for some time).

I have no idea how to test step 3 from the second patch: "Confirm OAuth authentication still works in browser".

Please change back to needs sign off if this is required, and I'll leave for someone who knows how to test.
Comment 6 David Nind 2025-12-09 01:03:49 UTC
Created attachment 190323 [details] [review]
Bug 33782: Add unit tests for Koha::Auth::Client::OAuth

This patch adds comprehensive unit tests for the OAuth authentication
client, specifically covering the _get_data_and_patron method which
handles JWT token processing and UserInfo endpoint integration.

Test plan:
1. Apply patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/Koha/Auth/Client/OAuth.t
=> SUCCESS: Tests pass!
3. Tests cover:
   - JWT id_token processing and patron matching
   - UserInfo endpoint calls and data merging
   - Non-existent user scenarios
   - Combined JWT + UserInfo data sources
4. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Comment 7 David Nind 2025-12-09 01:03:52 UTC
Created attachment 190324 [details] [review]
Bug 33782: (follow-up) Remove code duplication in OAuth client

This patch eliminates duplicated patron search logic in the
_get_data_and_patron method by extracting it into a dedicated
helper method _find_patron_by_matchpoint.

Changes:
- Extract duplicated patron search logic (8 lines removed)
- Add _find_patron_by_matchpoint helper method
- Improve code maintainability and readability
- No functional changes - behavior preserved

Test plan:
1. Apply patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/Koha/Auth/Client/OAuth.t
=> SUCCESS: Tests pass! OAuth client tests work correctly
  k$ prove t/db_dependent/api/v1/oauth.t
=> SUCCESS: Tests pass! OAuth API integration works
3. Confirm OAuth authentication still works in browser
4. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Comment 8 David Nind 2025-12-09 01:04:20 UTC
My sign-off line was incorrect, so have updated.