Bug 36575: (QA follow-up)

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz>
This commit is contained in:
Martin Renvoize 2024-04-11 12:18:30 +02:00 committed by Wainui Witika-Park
parent 9b6f3d0f18
commit b39b3ea197
2 changed files with 16 additions and 17 deletions

View File

@ -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 } );

View File

@ -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' );
};