View | Details | Raw Unified | Return to bug 29924
Collapse All | Expand All

(-)a/Koha/Patron.pm (-3 / +3 lines)
Lines 268-274 sub store { Link Here
268
                $self->plain_text_password( $self->password );
268
                $self->plain_text_password( $self->password );
269
269
270
                $self->password_expiration_date( $self->password
270
                $self->password_expiration_date( $self->password
271
                    ? $self->category->get_password_expiry_date
271
                    ? $self->category->get_password_expiry_date || undef
272
                    : undef );
272
                    : undef );
273
                # Create a disabled account if no password provided
273
                # Create a disabled account if no password provided
274
                $self->password( $self->password
274
                $self->password( $self->password
Lines 801-807 Returns 1 if the patron's password is expired or 0; Link Here
801
sub password_expired {
801
sub password_expired {
802
    my ($self) = @_;
802
    my ($self) = @_;
803
    return 0 unless $self->password_expiration_date;
803
    return 0 unless $self->password_expiration_date;
804
    return 1 if dt_from_string( $self->password_expiration_date ) < dt_from_string->truncate( to => 'day' );
804
    return 1 if dt_from_string( $self->password_expiration_date ) <= dt_from_string->truncate( to => 'day' );
805
    return 0;
805
    return 0;
806
}
806
}
807
807
Lines 904-910 sub set_password { Link Here
904
904
905
    my $digest = Koha::AuthUtils::hash_password($password);
905
    my $digest = Koha::AuthUtils::hash_password($password);
906
906
907
    $self->password_expiration_date( $self->category->get_password_expiry_date );
907
    $self->password_expiration_date( $self->category->get_password_expiry_date || undef );
908
908
909
    # We do not want to call $self->store and retrieve password from DB
909
    # We do not want to call $self->store and retrieve password from DB
910
    $self->password($digest);
910
    $self->password($digest);
(-)a/t/db_dependent/Koha/Patron.t (-1 / +96 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 16;
22
use Test::More tests => 17;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 882-887 subtest 'can_patron_change_staff_only_lists() tests' => sub { Link Here
882
    $schema->storage->txn_rollback;
882
    $schema->storage->txn_rollback;
883
};
883
};
884
884
885
subtest 'password expiration tests' => sub {
886
887
    plan tests => 5;
888
889
    $schema->storage->txn_begin;
890
    my $date = dt_from_string();
891
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => {
892
            password_expiry_days => 10,
893
            require_strong_password => 0,
894
        }
895
    });
896
    my $patron = $builder->build_object({ class=> 'Koha::Patrons', value => {
897
            categorycode => $category->categorycode,
898
            password => 'hats'
899
        }
900
    });
901
902
    $patron->delete()->store()->discard_changes(); # Make sure we are storing a 'new' patron
903
904
    is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd() , "Password expiration date set correctly on patron creation");
905
906
    $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
907
            categorycode => $category->categorycode,
908
            password => undef
909
        }
910
    });
911
    $patron->delete()->store()->discard_changes();
912
913
    is( $patron->password_expiration_date(), undef, "Password expiration date is not set if patron does not have a password");
914
915
    $category->password_expiry_days(undef)->store();
916
    $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
917
            categorycode => $category->categorycode
918
        }
919
    });
920
    $patron->delete()->store()->discard_changes();
921
    is( $patron->password_expiration_date(), undef, "Password expiration date is not set if category does not have expiry days set");
922
923
    $schema->storage->txn_rollback;
924
925
    subtest 'password_expired' => sub {
926
927
        plan tests => 3;
928
929
        $schema->storage->txn_begin;
930
        my $date = dt_from_string();
931
        $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
932
                password_expiration_date => undef
933
            }
934
        });
935
        is( $patron->password_expired, 0, "Patron with no password expiration date, password not expired");
936
        $patron->password_expiration_date( $date )->store;
937
        $patron->discard_changes();
938
        is( $patron->password_expired, 1, "Patron with password expiration date of today, password expired");
939
        $date->subtract( days => 1 );
940
        $patron->password_expiration_date( $date )->store;
941
        $patron->discard_changes();
942
        is( $patron->password_expired, 1, "Patron with password expiration date in past, password expired");
943
944
        $schema->storage->txn_rollback;
945
    };
946
947
    subtest 'set_password' => sub {
948
949
        plan tests => 4;
950
951
        $schema->storage->txn_begin;
952
953
        my $date = dt_from_string();
954
        my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => {
955
                password_expiry_days => 10
956
            }
957
        });
958
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
959
                categorycode => $category->categorycode,
960
                password_expiration_date =>  $date->subtract( days => 1 )
961
            }
962
        });
963
        is( $patron->password_expired, 1, "Patron password is expired");
964
965
        $date = dt_from_string();
966
        $patron->set_password({ password => "kitten", skip_validation => 1 })->discard_changes();
967
        is( $patron->password_expired, 0, "Patron password no longer expired when new password set");
968
        is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd(), "Password expiration date set correctly on patron creation");
969
970
971
        $category->password_expiry_days( undef )->store();
972
        $patron->set_password({ password => "puppies", skip_validation => 1 })->discard_changes();
973
        is( $patron->password_expiration_date(), undef, "Password expiration date is unset if category does not have expiry days");
974
975
        $schema->storage->txn_rollback;
976
    };
977
978
};
979
885
subtest 'safe_to_delete() tests' => sub {
980
subtest 'safe_to_delete() tests' => sub {
886
981
887
    plan tests => 14;
982
    plan tests => 14;
(-)a/t/db_dependent/Koha/Patron/Category.t (-2 / +18 lines)
Lines 19-30 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
26
26
27
use Koha::Database;
27
use Koha::Database;
28
use Koha::DateUtils qw( dt_from_string );
28
29
29
my $schema  = Koha::Database->new->schema;
30
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
my $builder = t::lib::TestBuilder->new;
Lines 202-204 subtest 'effective_require_strong_password' => sub { Link Here
202
203
203
  $schema->storage->txn_rollback;
204
  $schema->storage->txn_rollback;
204
};
205
};
205
- 
206
207
subtest 'get_password_expiry_date() tests' => sub {
208
209
    plan tests => 2;
210
211
    $schema->storage->txn_begin;
212
213
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories' });
214
    $category->password_expiry_days( undef )->store;
215
216
    is( $category->get_password_expiry_date(), undef, "No date returned if expiry days undef" );
217
218
    $category->password_expiry_days( 32 )->store;
219
    is( $category->get_password_expiry_date(), dt_from_string()->add( days => 32 )->ymd, "Date correctly calculated from password_expiry_days when set");
220
221
};

Return to bug 29924