Bug 21190: Add tests for authentication success and failure

Test plan:
Run t/db_dependent/Log.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jon Knight <J.P.Knight@lboro.ac.uk>
Signed-off-by: Michal Denar <black23@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Marcel de Rooy 2019-10-28 10:06:11 +00:00 committed by Martin Renvoize
parent 79754df526
commit a2f24f8e58
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 21 additions and 2 deletions

View File

@ -19,6 +19,7 @@ use Test::More tests => 5;
use C4::Context;
use C4::Log;
use C4::Auth qw/checkpw/;
use Koha::Database;
use Koha::DateUtils;
@ -162,7 +163,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' } );
@ -170,8 +171,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;