From 04be28f856455f86109e9154fcfb225b283f76b9 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 29 Nov 2023 17:18:32 +0000 Subject: [PATCH] Bug 34893: Add unit tests Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 29782174570a331c1b9f1ac8196ce06364f8f691) Signed-off-by: Fridolin Somers --- t/db_dependent/ILSDI_Services.t | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t index 65120df27a..70709d93c9 100755 --- a/t/db_dependent/ILSDI_Services.t +++ b/t/db_dependent/ILSDI_Services.t @@ -926,3 +926,50 @@ subtest 'GetAvailability itemcallnumber' => sub { $schema->storage->txn_rollback; }; + +subtest 'Bug 34893: ILS-DI can return the wrong patron for AuthenticatePatron' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $plain_password = 'tomasito'; + + $builder->build({ + source => 'Borrower', + value => { + cardnumber => undef, + } + }); + + my $borrower0 = $builder->build({ + source => 'Borrower', + value => { + cardnumber => "cardnumber1", + userid => undef, + password => Koha::AuthUtils::hash_password( $plain_password ), + lastseen => "2001-01-01 12:34:56" + } + }); + + my $borrower = $builder->build({ + source => 'Borrower', + value => { + cardnumber => "cardnumber2", + userid => undef, + password => Koha::AuthUtils::hash_password( $plain_password ), + lastseen => "2001-01-01 12:34:56" + } + }); + + my $query = CGI->new; + $query->param( 'username', $borrower->{cardnumber}); + $query->param( 'password', $plain_password); + + my $reply = C4::ILSDI::Services::AuthenticatePatron( $query ); + is( $reply->{id}, $borrower->{borrowernumber}, "userid and password - Patron authenticated" ); + is( $reply->{code}, undef, "Error code undef"); + my $seen_patron = Koha::Patrons->find({ borrowernumber => $reply->{id} }); + + $schema->storage->txn_rollback; +}; -- 2.39.5