Bugzilla – Attachment 186631 Details for
Bug 33782
OAuth2/OIDC identity providers code is not covered by unit tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33782: (follow-up) Remove code duplication in OAuth client
Bug-33782-follow-up-Remove-code-duplication-in-OAu.patch (text/plain), 2.79 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-09-20 14:32:51 UTC
(
hide
)
Description:
Bug 33782: (follow-up) Remove code duplication in OAuth client
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-09-20 14:32:51 UTC
Size:
2.79 KB
patch
obsolete
>From 97bec8d18fb266792847a9178ac2e739ba69e499 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= <tomascohen@theke.io> >Date: Sat, 20 Sep 2025 11:23:31 -0300 >Subject: [PATCH] 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 >--- > Koha/Auth/Client/OAuth.pm | 35 +++++++++++++++++++++-------------- > 1 file changed, 21 insertions(+), 14 deletions(-) > >diff --git a/Koha/Auth/Client/OAuth.pm b/Koha/Auth/Client/OAuth.pm >index 42d2691f04..bb9583c69d 100644 >--- a/Koha/Auth/Client/OAuth.pm >+++ b/Koha/Auth/Client/OAuth.pm >@@ -72,13 +72,7 @@ sub _get_data_and_patron { > if defined $claim->{$pkey}; > } > >- my $value = $mapped_data->{$matchpoint}; >- >- my $matchpoint_rs = Koha::Patrons->search( { $matchpoint => $value } ); >- >- if ( defined $value and $matchpoint_rs->count ) { >- $patron = $matchpoint_rs->next; >- } >+ $patron = $self->_find_patron_by_matchpoint( $matchpoint, $mapped_data->{$matchpoint} ); > } > > if ( defined $config->{userinfo_url} ) { >@@ -101,13 +95,7 @@ sub _get_data_and_patron { > } > > unless ($patron) { >- my $value = $mapped_data->{$matchpoint}; >- >- my $matchpoint_rs = Koha::Patrons->search( { $matchpoint => $value } ); >- >- if ( defined $value and $matchpoint_rs->count ) { >- $patron = $matchpoint_rs->next; >- } >+ $patron = $self->_find_patron_by_matchpoint( $matchpoint, $mapped_data->{$matchpoint} ); > } > > } >@@ -115,4 +103,23 @@ sub _get_data_and_patron { > return ( $mapped_data, $patron ); > } > >+=head3 _find_patron_by_matchpoint >+ >+ my $patron = $client->_find_patron_by_matchpoint( $matchpoint, $value ); >+ >+Internal method to find a patron by the given matchpoint and value. >+Returns the patron object if found, undef otherwise. >+ >+=cut >+ >+sub _find_patron_by_matchpoint { >+ my ( $self, $matchpoint, $value ) = @_; >+ >+ return unless defined $value; >+ >+ my $matchpoint_rs = Koha::Patrons->search( { $matchpoint => $value } ); >+ >+ return $matchpoint_rs->count ? $matchpoint_rs->next : undef; >+} >+ > 1; >-- >2.51.0
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 33782
:
186630
| 186631