Bugzilla – Attachment 132092 Details for
Bug 29924
Introduce password expiration to patron categories
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29924: Update ILSDI to be aware of expired passwords
Bug-29924-Update-ILSDI-to-be-aware-of-expired-pass.patch (text/plain), 5.02 KB, created by
Andrew Fuerste-Henry
on 2022-03-23 21:03:06 UTC
(
hide
)
Description:
Bug 29924: Update ILSDI to be aware of expired passwords
Filename:
MIME Type:
Creator:
Andrew Fuerste-Henry
Created:
2022-03-23 21:03:06 UTC
Size:
5.02 KB
patch
obsolete
>From c98c71db3793d8c381483a9d4cfd8fbf8b91527c Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 23 Mar 2022 15:58:30 +0000 >Subject: [PATCH] Bug 29924: Update ILSDI to be aware of expired passwords > >To test: >1 - Enable ILSDI >2 - Set a patron password with expired password >3 - http://localhost:8080/cgi-bin/koha/ilsdi.pl?service=AuthenticatePatron&username=usernam&password=password >4 - Confirm 'PasswordExpired' returned > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> >--- > C4/Auth.pm | 9 ++++++--- > C4/ILSDI/Services.pm | 5 ++++- > t/db_dependent/Auth.t | 18 +++++++++++++++++- > t/db_dependent/ILSDI_Services.t | 9 ++++++++- > 4 files changed, 35 insertions(+), 6 deletions(-) > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index 80f9514a38..cc2f6fa840 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -1102,7 +1102,7 @@ sub checkauth { > } > > # $return: 1 = valid user >- if ($return) { >+ if ($return > 0) { > > if ( $flags = haspermission( $userid, $flagsrequired ) ) { > $loggedin = 1; >@@ -1830,8 +1830,8 @@ sub checkpw { > # 0 if auth is nok > # -1 if user bind failed (LDAP only) > >- if ( $patron and ( $patron->account_locked || $patron->password_expired ) ) { >- # Nothing to check, account is locked or password expired >+ if ( $patron and ( $patron->account_locked ) ) { >+ # Nothing to check, account is locked > } elsif ($ldap && defined($password)) { > my ( $retval, $retcard, $retuserid ) = checkpw_ldap(@_); # EXTERNAL AUTH > if ( $retval == 1 ) { >@@ -1884,6 +1884,9 @@ sub checkpw { > if( $patron ) { > if ( $passwd_ok ) { > $patron->update({ login_attempts => 0 }); >+ if( $patron->password_expired ){ >+ @return = (-2); >+ } > } elsif( !$patron->account_locked ) { > $patron->update({ login_attempts => $patron->login_attempts + 1 }); > } >diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm >index 52585ac2dd..4e8288ed14 100644 >--- a/C4/ILSDI/Services.pm >+++ b/C4/ILSDI/Services.pm >@@ -398,13 +398,16 @@ sub AuthenticatePatron { > my $username = $cgi->param('username'); > my $password = $cgi->param('password'); > my ($status, $cardnumber, $userid) = C4::Auth::checkpw( C4::Context->dbh, $username, $password ); >- if ( $status ) { >+ if ( $status == 1 ) { > # Track the login > C4::Auth::track_login_daily( $userid ); > # Get the borrower > my $patron = Koha::Patrons->find( { userid => $userid } ); > return { id => $patron->borrowernumber }; > } >+ elsif ( $status == -2 ){ >+ return { code => 'PasswordExpired' }; >+ } > else { > return { code => 'PatronNotFound' }; > } >diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t >index 199637f08c..c47ad18e30 100755 >--- a/t/db_dependent/Auth.t >+++ b/t/db_dependent/Auth.t >@@ -10,7 +10,7 @@ use CGI qw ( -utf8 ); > use Test::MockObject; > use Test::MockModule; > use List::MoreUtils qw/all any none/; >-use Test::More tests => 15; >+use Test::More tests => 16; > use Test::Warn; > use t::lib::Mocks; > use t::lib::TestBuilder; >@@ -425,6 +425,22 @@ subtest 'Check value of login_attempts in checkpw' => sub { > is( $patron->account_locked, 1, 'Check administrative lockout without pref' ); > }; > >+subtest 'Check value of login_attempts in checkpw' => sub { >+ plan tests => 2; >+ >+ t::lib::Mocks::mock_preference('FailedLoginAttempts', 3); >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ $patron->set_password({ password => '123', skip_validation => 1 }); >+ >+ my @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); >+ is( $test[0], 1, 'Patron authenticated correctly' ); >+ >+ $patron->password_expiration_date('2020-01-01')->store; >+ @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 ); >+ is( $test[0], -2, 'Patron returned as expired correctly' ); >+ >+}; >+ > subtest '_timeout_syspref' => sub { > plan tests => 5; > >diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t >index 4e525899eb..2063ee07c8 100755 >--- a/t/db_dependent/ILSDI_Services.t >+++ b/t/db_dependent/ILSDI_Services.t >@@ -42,7 +42,7 @@ my $builder = t::lib::TestBuilder->new; > > subtest 'AuthenticatePatron test' => sub { > >- plan tests => 16; >+ plan tests => 18; > > $schema->storage->txn_begin; > >@@ -111,6 +111,13 @@ subtest 'AuthenticatePatron test' => sub { > is( $reply->{code}, 'PatronNotFound', "non-existing cardnumer/userid - PatronNotFound" ); > is( $reply->{id}, undef, "id undef"); > >+ $query->param( 'username', $borrower->{userid} ); >+ $query->param( 'password', $plain_password ); >+ $seen_patron->password_expiration_date('2020-01-01')->store; >+ $reply = C4::ILSDI::Services::AuthenticatePatron($query); >+ is( $reply->{code}, 'PasswordExpired', "correct credentials, expired password not authenticated" ); >+ is( $reply->{id}, undef, "id undef"); >+ > $schema->storage->txn_rollback; > }; > >-- >2.30.2
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 29924
:
129705
|
129706
|
129707
|
129708
|
129762
|
129763
|
129764
|
129765
|
129766
|
129823
|
129953
|
129954
|
129955
|
129956
|
129957
|
130116
|
130117
|
130118
|
130119
|
130120
|
130495
|
130500
|
130501
|
130502
|
130503
|
130504
|
130505
|
130557
|
130558
|
130559
|
130560
|
130561
|
130562
|
130563
|
130677
|
130678
|
130679
|
130680
|
130681
|
130682
|
130683
|
131128
|
132059
|
132060
|
132061
|
132062
|
132063
|
132064
|
132065
|
132066
|
132084
|
132085
|
132086
|
132087
|
132088
|
132089
|
132090
|
132091
|
132092
|
133741
|
133742
|
133743
|
133744
|
133745
|
133746
|
133747
|
133748
|
133801
|
133802
|
133803
|
133804
|
133805
|
133806
|
133807
|
133808
|
133809
|
133810
|
133989
|
134758