From 4071924f7f9438c344e878a86d29792f83c06704 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 5 May 2020 14:58:40 +0100 Subject: [PATCH] Bug 18308: (RM follow-up) Clarify intent of tests Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Plugins/Patron.t | 18 +++++++++++++----- t/lib/Koha/Plugin/Test.pm | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/t/db_dependent/Koha/Plugins/Patron.t b/t/db_dependent/Koha/Plugins/Patron.t index e0b98d946b..c8b2e86f25 100644 --- a/t/db_dependent/Koha/Plugins/Patron.t +++ b/t/db_dependent/Koha/Plugins/Patron.t @@ -44,13 +44,14 @@ t::lib::Mocks::mock_config( 'enable_plugins', 1 ); subtest 'check_password hook tests' => sub { - plan tests => 5; + plan tests => 6; $schema->storage->txn_begin; my $plugins = Koha::Plugins->new; $plugins->InstallPlugins; + # Test Plugin enforces a 4 digit numeric pin for passwords my $plugin = Koha::Plugin::Test->new->enable; my $library = $builder->build( { source => 'Branch' } ); @@ -63,17 +64,24 @@ subtest 'check_password hook tests' => sub { surname => 'surname for patron1', firstname => 'firstname for patron1', userid => 'a_nonexistent_userid_1', - password => "exploder", } ); + # store hook (add action) + $patron->password('exploder'); throws_ok { $patron->store } 'Koha::Exceptions::Password::Plugin', - 'Exception raised for adding patron with bad password'; - $patron->password('12345678'); + 'Plugin Exception raised for adding patron with bad password'; + $patron->password('1234'); ok( $patron->store, 'Patron created with good password' ); + $patron->discard_changes; + $patron->password('87654321'); + $patron->store; + isnt($patron->password, '87654321', 'Koha::Patron->store silently drops changes to password'); + + # set_password hook (update action) t::lib::Mocks::mock_preference( 'RequireStrongPassword', '0' ); - t::lib::Mocks::mock_preference( 'minPasswordLength', '3' ); + t::lib::Mocks::mock_preference( 'minPasswordLength', '4' ); # Testing Plugin validation, not internal validation throws_ok { $patron->set_password({ password => 'explosion' }) } 'Koha::Exceptions::Password::Plugin', 'Exception raised for update patron password with bad string'; ok( $patron->set_password({ password => '4321' }), 'Patron password updated with good string' ); diff --git a/t/lib/Koha/Plugin/Test.pm b/t/lib/Koha/Plugin/Test.pm index 39c2bfa364..b7b85d689e 100644 --- a/t/lib/Koha/Plugin/Test.pm +++ b/t/lib/Koha/Plugin/Test.pm @@ -218,7 +218,7 @@ sub check_password { my ( $self, $args ) = @_; my $password = $args->{'password'}; - if ( $password && $password =~ m/^\d{8}$/ ) { + if ( $password && $password =~ m/^\d{4}$/ ) { return { error => 0 }; } else { -- 2.39.5