Bugzilla – Attachment 132061 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: Unit tests
Bug-29924-Unit-tests.patch (text/plain), 7.15 KB, created by
Nick Clemens (kidclamp)
on 2022-03-23 16:01:06 UTC
(
hide
)
Description:
Bug 29924: Unit tests
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2022-03-23 16:01:06 UTC
Size:
7.15 KB
patch
obsolete
>From c9017eb391f6dadca9920c7311909b5adf12ee29 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 21 Jan 2022 17:11:39 +0000 >Subject: [PATCH] Bug 29924: Unit tests > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> > >Signed-off-by: Bob Bennhoff <bbennhoff@clicweb.org> >--- > Koha/Patron.pm | 6 +- > t/db_dependent/Koha/Patron.t | 95 +++++++++++++++++++++++++++ > t/db_dependent/Koha/Patron/Category.t | 19 +++++- > 3 files changed, 116 insertions(+), 4 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 3e8fa4f585..22cf0d5c58 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -267,7 +267,7 @@ sub store { > $self->plain_text_password( $self->password ); > > $self->password_expiration_date( $self->password >- ? $self->category->get_password_expiry_date >+ ? $self->category->get_password_expiry_date || undef > : undef ); > # Create a disabled account if no password provided > $self->password( $self->password >@@ -793,7 +793,7 @@ Returns 1 if the patron's password is expired or 0; > sub password_expired { > my ($self) = @_; > return 0 unless $self->password_expiration_date; >- return 1 if dt_from_string( $self->password_expiration_date ) < dt_from_string->truncate( to => 'day' ); >+ return 1 if dt_from_string( $self->password_expiration_date ) <= dt_from_string->truncate( to => 'day' ); > return 0; > } > >@@ -896,7 +896,7 @@ sub set_password { > > my $digest = Koha::AuthUtils::hash_password($password); > >- $self->password_expiration_date( $self->category->get_password_expiry_date ); >+ $self->password_expiration_date( $self->category->get_password_expiry_date || undef ); > > # We do not want to call $self->store and retrieve password from DB > $self->password($digest); >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index a1aff0035e..2aa89253e5 100755 >--- a/t/db_dependent/Koha/Patron.t >+++ b/t/db_dependent/Koha/Patron.t >@@ -852,6 +852,101 @@ subtest 'article_requests() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'password expiration tests' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ my $date = dt_from_string(); >+ my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { >+ password_expiry_days => 10, >+ require_strong_password => 0, >+ } >+ }); >+ my $patron = $builder->build_object({ class=> 'Koha::Patrons', value => { >+ categorycode => $category->categorycode, >+ password => 'hats' >+ } >+ }); >+ >+ $patron->delete()->store()->discard_changes(); # Make sure we are storing a 'new' patron >+ >+ is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd() , "Password expiration date set correctly on patron creation"); >+ >+ $patron = $builder->build_object({ class => 'Koha::Patrons', value => { >+ categorycode => $category->categorycode, >+ password => undef >+ } >+ }); >+ $patron->delete()->store()->discard_changes(); >+ >+ is( $patron->password_expiration_date(), undef, "Password expiration date is not set if patron does not have a password"); >+ >+ $category->password_expiry_days(undef)->store(); >+ $patron = $builder->build_object({ class => 'Koha::Patrons', value => { >+ categorycode => $category->categorycode >+ } >+ }); >+ $patron->delete()->store()->discard_changes(); >+ is( $patron->password_expiration_date(), undef, "Password expiration date is not set if category does not have expiry days set"); >+ >+ $schema->storage->txn_rollback; >+ >+ subtest 'password_expired' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ my $date = dt_from_string(); >+ $patron = $builder->build_object({ class => 'Koha::Patrons', value => { >+ password_expiration_date => undef >+ } >+ }); >+ is( $patron->password_expired, 0, "Patron with no password expiration date, password not expired"); >+ $patron->password_expiration_date( $date )->store; >+ $patron->discard_changes(); >+ is( $patron->password_expired, 1, "Patron with password expiration date of today, password expired"); >+ $date->subtract( days => 1 ); >+ $patron->password_expiration_date( $date )->store; >+ $patron->discard_changes(); >+ is( $patron->password_expired, 1, "Patron with password expiration date in past, password expired"); >+ >+ $schema->storage->txn_rollback; >+ }; >+ >+ subtest 'set_password' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $date = dt_from_string(); >+ my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { >+ password_expiry_days => 10 >+ } >+ }); >+ my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { >+ categorycode => $category->categorycode, >+ password_expiration_date => $date->subtract( days => 1 ) >+ } >+ }); >+ is( $patron->password_expired, 1, "Patron password is expired"); >+ >+ $date = dt_from_string(); >+ $patron->set_password({ password => "kitten", skip_validation => 1 })->discard_changes(); >+ is( $patron->password_expired, 0, "Patron password no longer expired when new password set"); >+ is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd(), "Password expiration date set correctly on patron creation"); >+ >+ >+ $category->password_expiry_days( undef )->store(); >+ $patron->set_password({ password => "puppies", skip_validation => 1 })->discard_changes(); >+ is( $patron->password_expiration_date(), undef, "Password expiration date is unset if category does not have expiry days"); >+ >+ $schema->storage->txn_rollback; >+ }; >+ >+}; >+ > subtest 'safe_to_delete() tests' => sub { > > plan tests => 14; >diff --git a/t/db_dependent/Koha/Patron/Category.t b/t/db_dependent/Koha/Patron/Category.t >index 5accf5679e..be7f32b8de 100755 >--- a/t/db_dependent/Koha/Patron/Category.t >+++ b/t/db_dependent/Koha/Patron/Category.t >@@ -19,12 +19,13 @@ > > use Modern::Perl; > >-use Test::More tests => 5; >+use Test::More tests => 6; > > use t::lib::TestBuilder; > use t::lib::Mocks; > > use Koha::Database; >+use Koha::DateUtils qw( dt_from_string ); > > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; >@@ -202,3 +203,19 @@ subtest 'effective_require_strong_password' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'get_password_expiry_date() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $category = $builder->build_object({ class => 'Koha::Patron::Categories' }); >+ $category->password_expiry_days( undef )->store; >+ >+ is( $category->get_password_expiry_date(), undef, "No date returned if expiry days undef" ); >+ >+ $category->password_expiry_days( 32 )->store; >+ is( $category->get_password_expiry_date(), dt_from_string()->add( days => 32 )->ymd, "Date correctly calculated from password_expiry_days when set"); >+ >+}; >-- >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