From b39b3ea1974f4741402df19822c8d7eff02c54fd Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 11 Apr 2024 12:18:30 +0200 Subject: [PATCH] Bug 36575: (QA follow-up) Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Marcel de Rooy Signed-off-by: Wainui Witika-Park --- C4/Auth.pm | 19 +++++++++---------- t/db_dependent/Auth.t | 14 +++++++------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 1a8b9bf798..e87ff940d3 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -1935,9 +1935,8 @@ sub checkpw { my $ticket = $query->param('ticket'); $query->delete('ticket'); # remove ticket to come back to original URL my ( $retval, $retcard, $retuserid, $cas_ticket ); - ( $retval, $retcard, $retuserid, $cas_ticket, $patron ) = - checkpw_cas( $ticket, $query, $type ); # EXTERNAL AUTH - if ( $retval ) { + ( $retval, $retcard, $retuserid, $cas_ticket, $patron ) = checkpw_cas( $ticket, $query, $type ); # EXTERNAL AUTH + if ($retval) { @return = ( $retval, $retcard, $retuserid, $patron, $cas_ticket ); } else { @return = (0); @@ -1968,22 +1967,22 @@ sub checkpw { $check_internal_as_fallback = 1; } - if ( $check_internal_as_fallback ){ - # INTERNAL AUTH - @return = checkpw_internal( $userid, $password, $no_set_userenv); - $passwd_ok = 1 if $return[0] > 0; # 1 or 2 - $patron = Koha::Patrons->find({ cardnumber => $return[1] }) if $passwd_ok; + if ($check_internal_as_fallback) { + # INTERNAL AUTH + @return = checkpw_internal( $userid, $password, $no_set_userenv ); + $passwd_ok = 1 if $return[0] > 0; # 1 or 2 + $patron = Koha::Patrons->find( { cardnumber => $return[1] } ) if $passwd_ok; push @return, $patron if $patron; } - if ( defined $userid && !$patron ) { + if ( defined $userid && !$patron ) { $patron = Koha::Patrons->find( { userid => $userid } ); $patron = Koha::Patrons->find( { cardnumber => $userid } ) unless $patron; push @return, $patron if $check_internal_as_fallback; } if ($patron) { - if( $patron->account_locked ){ + if ( $patron->account_locked ) { @return = (); } elsif ($passwd_ok) { $patron->update( { login_attempts => 0 } ); diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t index 15218545f1..5acfb3d5e3 100755 --- a/t/db_dependent/Auth.t +++ b/t/db_dependent/Auth.t @@ -1199,23 +1199,23 @@ subtest 'checkpw for users with shared cardnumber / userid ' => sub { plan tests => 8; t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); - my $library = $builder->build_object( { class => 'Koha::Libraries' } ); - my $patron_1 = $builder->build_object( { class => 'Koha::Patrons' } ); + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $patron_1 = $builder->build_object( { class => 'Koha::Patrons' } ); $patron_1->set_password( { password => "OnePassword" } ); - my $patron_2 = $builder->build_object( { class => 'Koha::Patrons', value => { userid => $patron_1->cardnumber } } ); + my $patron_2 = $builder->build_object( { class => 'Koha::Patrons', value => { userid => $patron_1->cardnumber } } ); $patron_2->set_password( { password => "PasswordTwo" } ); my ( $checkpw, $cardnumber, $userid, $patron ) = checkpw( $patron_1->cardnumber, "OnePassword", undef, undef, 1 ); ok( $checkpw, 'checkpw returns true for right password when logging in via cardnumber' ); is( $cardnumber, $patron_1->cardnumber, 'checkpw returns correct cardnumber' ); - is( $userid, $patron_1->userid, 'checkpw returns correct userid' ); - is( $patron->id, $patron_1->id, 'checkpw returns correct patron' ); + is( $userid, $patron_1->userid, 'checkpw returns correct userid' ); + is( $patron->id, $patron_1->id, 'checkpw returns correct patron' ); ( $checkpw, $cardnumber, $userid, $patron ) = checkpw( $patron_2->userid, "PasswordTwo", undef, undef, 1 ); ok( $checkpw, 'checkpw returns true for right password when logging in via userid' ); is( $cardnumber, $patron_2->cardnumber, 'checkpw returns correct cardnumber' ); - is( $userid, $patron_2->userid, 'checkpw returns correct userid' ); - is( $patron->id, $patron_2->id, 'checkpw returns correct patron' ); + is( $userid, $patron_2->userid, 'checkpw returns correct userid' ); + is( $patron->id, $patron_2->id, 'checkpw returns correct patron' ); }; -- 2.39.5