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

(-)a/Koha/Patron.pm (-3 / +3 lines)
Lines 265-271 sub store { Link Here
265
                $self->plain_text_password( $self->password );
265
                $self->plain_text_password( $self->password );
266
266
267
                $self->password_expiration_date( $self->password
267
                $self->password_expiration_date( $self->password
268
                    ? $self->category->get_password_expiry_date
268
                    ? $self->category->get_password_expiry_date || undef
269
                    : undef );
269
                    : undef );
270
                # Create a disabled account if no password provided
270
                # Create a disabled account if no password provided
271
                $self->password( $self->password
271
                $self->password( $self->password
Lines 791-797 Returns 1 if the patron's password is expired or 0; Link Here
791
sub password_expired {
791
sub password_expired {
792
    my ($self) = @_;
792
    my ($self) = @_;
793
    return 0 unless $self->password_expiration_date;
793
    return 0 unless $self->password_expiration_date;
794
    return 1 if dt_from_string( $self->password_expiration_date ) < dt_from_string->truncate( to => 'day' );
794
    return 1 if dt_from_string( $self->password_expiration_date ) <= dt_from_string->truncate( to => 'day' );
795
    return 0;
795
    return 0;
796
}
796
}
797
797
Lines 894-900 sub set_password { Link Here
894
894
895
    my $digest = Koha::AuthUtils::hash_password($password);
895
    my $digest = Koha::AuthUtils::hash_password($password);
896
896
897
    $self->password_expiration_date( $self->category->get_password_expiry_date );
897
    $self->password_expiration_date( $self->category->get_password_expiry_date || undef );
898
898
899
    # We do not want to call $self->store and retrieve password from DB
899
    # We do not want to call $self->store and retrieve password from DB
900
    $self->password($digest);
900
    $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 => 13;
22
use Test::More tests => 14;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 851-856 subtest 'article_requests() tests' => sub { Link Here
851
    $schema->storage->txn_rollback;
851
    $schema->storage->txn_rollback;
852
};
852
};
853
853
854
subtest 'password expiration tests' => sub {
855
856
    plan tests => 5;
857
858
    $schema->storage->txn_begin;
859
    my $date = dt_from_string();
860
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => {
861
            password_expiry_days => 10,
862
            require_strong_password => 0,
863
        }
864
    });
865
    my $patron = $builder->build_object({ class=> 'Koha::Patrons', value => {
866
            categorycode => $category->categorycode,
867
            password => 'hats'
868
        }
869
    });
870
871
    $patron->delete()->store()->discard_changes(); # Make sure we are storing a 'new' patron
872
873
    is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd() , "Password expiration date set correctly on patron creation");
874
875
    $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
876
            categorycode => $category->categorycode,
877
            password => undef
878
        }
879
    });
880
    $patron->delete()->store()->discard_changes();
881
882
    is( $patron->password_expiration_date(), undef, "Password expiration date is not set if patron does not have a password");
883
884
    $category->password_expiry_days(undef)->store();
885
    $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
886
            categorycode => $category->categorycode
887
        }
888
    });
889
    $patron->delete()->store()->discard_changes();
890
    is( $patron->password_expiration_date(), undef, "Password expiration date is not set if category does not have expiry days set");
891
892
    $schema->storage->txn_rollback;
893
894
    subtest 'password_expired' => sub {
895
896
        plan tests => 3;
897
898
        $schema->storage->txn_begin;
899
        my $date = dt_from_string();
900
        $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
901
                password_expiration_date => undef
902
            }
903
        });
904
        is( $patron->password_expired, 0, "Patron with no password expiration date, password not expired");
905
        $patron->password_expiration_date( $date )->store;
906
        $patron->discard_changes();
907
        is( $patron->password_expired, 1, "Patron with password expiration date of today, password expired");
908
        $date->subtract( days => 1 );
909
        $patron->password_expiration_date( $date )->store;
910
        $patron->discard_changes();
911
        is( $patron->password_expired, 1, "Patron with password expiration date in past, password expired");
912
913
        $schema->storage->txn_rollback;
914
    };
915
916
    subtest 'set_password' => sub {
917
918
        plan tests => 4;
919
920
        $schema->storage->txn_begin;
921
922
        my $date = dt_from_string();
923
        my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => {
924
                password_expiry_days => 10
925
            }
926
        });
927
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => {
928
                categorycode => $category->categorycode,
929
                password_expiration_date =>  $date->subtract( days => 1 )
930
            }
931
        });
932
        is( $patron->password_expired, 1, "Patron password is expired");
933
934
        $date = dt_from_string();
935
        $patron->set_password({ password => "kitten", skip_validation => 1 })->discard_changes();
936
        is( $patron->password_expired, 0, "Patron password no longer expired when new password set");
937
        is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd(), "Password expiration date set correctly on patron creation");
938
939
940
        $category->password_expiry_days( undef )->store();
941
        $patron->set_password({ password => "puppies", skip_validation => 1 })->discard_changes();
942
        is( $patron->password_expiration_date(), undef, "Password expiration date is unset if category does not have expiry days");
943
944
        $schema->storage->txn_rollback;
945
    };
946
947
};
948
854
subtest 'safe_to_delete() tests' => sub {
949
subtest 'safe_to_delete() tests' => sub {
855
950
856
    plan tests => 14;
951
    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