Bugzilla – Attachment 77632 Details for
Bug 21178
Add Koha::Patron::set_password method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21178: (QA follow-up) Rely on is_password_valid
Bug-21178-QA-follow-up-Rely-on-ispasswordvalid.patch (text/plain), 3.02 KB, created by
Tomás Cohen Arazi
on 2018-08-09 16:21:46 UTC
(
hide
)
Description:
Bug 21178: (QA follow-up) Rely on is_password_valid
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi
Created:
2018-08-09 16:21:46 UTC
Size:
3.02 KB
patch
obsolete
>From c0064e00f23e6c5e706291a14a48fe2412bcb506 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 9 Aug 2018 13:20:20 -0300 >Subject: [PATCH] Bug 21178: (QA follow-up) Rely on is_password_valid > >This patch makes set_password still rely on Koha::AuthUtils' >is_password_valid method as the only source for truth regarding password >validity. > >To test: >- Run: > $ kshell > k$ prove t/db_dependent/Koha/Patrons.t >=> SUCCESS: Tests still pass! > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Patron.pm | 29 ++++++++++++++++------------- > t/db_dependent/Koha/Patrons.t | 2 +- > 2 files changed, 17 insertions(+), 14 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index b0568d154e..1984b500ea 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -729,21 +729,24 @@ Exceptions are thrown if the password is not good enough. > sub set_password { > my ( $self, $password ) = @_; > >- my $min_length = C4::Context->preference('minPasswordLength'); >- $min_length = 3 if not $min_length or $min_length < 3; >+ my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password ); > >- my $password_length = length($password); >- Koha::Exceptions::Password::TooShort->throw( >- { length => $password_length, min_length => $min_length } ) >- if $password_length < $min_length; >+ if ( !$is_valid ) { >+ if ( $error eq 'too_short' ) { >+ my $min_length = C4::Context->preference('minPasswordLength'); >+ $min_length = 3 if not $min_length or $min_length < 3; > >- Koha::Exceptions::Password::TrailingWhitespaces->throw( >- "Password contains trailing spaces, which is forbidden.") >- if $password =~ m[^\s|\s$]; >- >- if ( C4::Context->preference('RequireStrongPassword') ) { >- Koha::Exceptions::Password::TooWeak->throw() >- if $password !~ m|(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{$min_length,}|; >+ my $password_length = length($password); >+ Koha::Exceptions::Password::TooShort->throw( >+ { length => $password_length, min_length => $min_length } ); >+ } >+ elsif ( $error eq 'has_whitespaces' ) { >+ Koha::Exceptions::Password::TrailingWhitespaces->throw( >+ "Password contains trailing spaces, which is forbidden."); >+ } >+ elsif ( $error eq 'too_weak' ) { >+ Koha::Exceptions::Password::TooWeak->throw(); >+ } > } > > my $digest = Koha::AuthUtils::hash_password($password); >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 7be2b8fcdb..f8c8a8046e 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -1529,7 +1529,7 @@ subtest '->set_password' => sub { > 'minPasswordLength is 5, fail test'; > > # Trailing spaces tests >- throws_ok { $patron->set_password('abcd '); } >+ throws_ok { $patron->set_password('abcD12d '); } > 'Koha::Exceptions::Password::TrailingWhitespaces', > 'Password contains trailing spaces, exception is thrown'; > >-- >2.18.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 21178
:
77575
|
77576
|
77577
|
77578
|
77632
|
77885
|
77886
|
77916
|
77917
|
78833
|
80133
|
80134
|
80135
|
80136