Bug 22692: Unit tests
authorNick Clemens <nick@bywatersolutions.com>
Fri, 12 Apr 2019 01:11:19 +0000 (01:11 +0000)
committerLucas Gass <lucas@bywatersolutions.com>
Mon, 29 Apr 2019 01:55:59 +0000 (01:55 +0000)
1 - Apply just this patch
2 - prove -v t/db_dependent/Auth.t
3 - Failure
4 - Apply second patch
5 - prove -v t/db_dependent/Auth.t
6 - Success

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit bc066fea9f855c0fc4e1fbc43736121783d3b77b)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

t/db_dependent/Auth.t

index ecad00c..e9bdf22 100644 (file)
@@ -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 => 26;
+use Test::More tests => 27;
 use Test::Warn;
 use t::lib::Mocks;
 use t::lib::TestBuilder;
@@ -138,6 +138,30 @@ my $hash2 = hash_password('password');
     isnt( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is overwritten if no_set_userenv is false' );
 }
 
+subtest 'checkpw lockout tests' => sub {
+
+    plan tests => 5;
+
+    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
+    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
+    my $password = 'password';
+    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
+    t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 1 );
+    $patron->set_password({ password => $password });
+
+    my ( $checkpw, undef, undef ) = checkpw( $dbh, $patron->cardnumber, $password, undef, undef, 1 );
+    ok( $checkpw, 'checkpw returns true with right password when logging in via cardnumber' );
+    ( $checkpw, undef, undef ) = checkpw( $dbh, $patron->userid, "wrong_password", undef, undef, 1 );
+    is( $checkpw, 0, 'checkpw returns false when given wrong password' );
+    $patron = $patron->get_from_storage;
+    is( $patron->account_locked, 1, "Account is locked from failed login");
+    ( $checkpw, undef, undef ) = checkpw( $dbh, $patron->userid, $password, undef, undef, 1 );
+    is( $checkpw, undef, 'checkpw returns undef with right password when account locked' );
+    ( $checkpw, undef, undef ) = checkpw( $dbh, $patron->cardnumber, $password, undef, undef, 1 );
+    is( $checkpw, undef, 'checkpw returns undefwith right password when logging in via cardnumber if account locked' );
+
+};
+
 # get_template_and_user tests
 
 {   # Tests for the language URL parameter