From 0744d5fe9e99807f584d5519dcf92ee6801077f0 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 28 Oct 2019 10:06:11 +0000 Subject: [PATCH] Bug 21190: Add tests for authentication success and failure Content-Type: text/plain; charset=utf-8 Test plan: Run t/db_dependent/Log.t Signed-off-by: Marcel de Rooy --- t/db_dependent/Log.t | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Log.t b/t/db_dependent/Log.t index f84fb14265..2665ead03a 100644 --- a/t/db_dependent/Log.t +++ b/t/db_dependent/Log.t @@ -21,6 +21,7 @@ use Test::More tests => 5; use C4::Context; use C4::Log; +use C4::Auth qw/checkpw/; use Koha::Database; use Koha::DateUtils; @@ -164,7 +165,7 @@ subtest 'GetLogs() respects interface filters' => sub { }; subtest 'GDPR logging' => sub { - plan tests => 1; + plan tests => 6; my $builder = t::lib::TestBuilder->new; my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); @@ -172,8 +173,26 @@ subtest 'GDPR logging' => sub { t::lib::Mocks::mock_userenv({ patron => $patron }); logaction( 'AUTH', 'FAILURE', $patron->id, '', 'opac' ); my $logs = GetLogs( undef, undef, $patron->id, ['AUTH'], ['FAILURE'], $patron->id ); - is( @$logs, 1, 'We should find one auth failure for this patron' ); - + is( @$logs, 1, 'We should find one auth failure' ); + + t::lib::Mocks::mock_preference('AuthFailureLog', 1); + my $strong_password = 'N0tStr0ngAnyM0reN0w:)'; + $patron->set_password({ password => $strong_password }); + my @ret = checkpw( $dbh, $patron->userid, 'WrongPassword', undef, undef, 1); + is( $ret[0], 0, 'Authentication failed' ); + # Look for auth failure but NOT on patron id, pass userid in info parameter + $logs = GetLogs( undef, undef, 0, ['AUTH'], ['FAILURE'], undef, $patron->userid ); + is( @$logs, 1, 'We should find one auth failure with this userid' ); + t::lib::Mocks::mock_preference('AuthFailureLog', 0); + @ret = checkpw( $dbh, $patron->userid, 'WrongPassword', undef, undef, 1); + $logs = GetLogs( undef, undef, 0, ['AUTH'], ['FAILURE'], undef, $patron->userid ); + is( @$logs, 1, 'Still only one failure with this userid' ); + t::lib::Mocks::mock_preference('AuthSuccessLog', 1); + @ret = checkpw( $dbh, $patron->userid, $strong_password, undef, undef, 1); + is( $ret[0], 1, 'Authentication succeeded' ); + # Now we can look for patron id + $logs = GetLogs( undef, undef, $patron->id, ['AUTH'], ['SUCCESS'], $patron->id ); + is( @$logs, 1, 'We expect only one auth success line for this patron' ); }; $schema->storage->txn_rollback; -- 2.11.0