Bug 30646: Unit tests for Auth_with_ldap
This patch adds a unit test to the Auth_with_ldap.t to confirm welcome notices are send when replace + welcome are enabled in the configuration. We also add a snippet to hide 'Subroutine redefined' warnings in this test as it makes the test output rather challenging to read and the way the test is written these warning are expected. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
157bb786c1
commit
762fa03432
1 changed files with 57 additions and 2 deletions
|
@ -28,6 +28,15 @@ use C4::Context;
|
||||||
|
|
||||||
use Koha::Patrons;
|
use Koha::Patrons;
|
||||||
|
|
||||||
|
# Hide all the subrouteine redefined warnings when running this test..
|
||||||
|
# We reload the ldap module lots in the test and each reload triggers the
|
||||||
|
# 'Subroutine X redefined at' warning.. disable that to make the test output
|
||||||
|
# readable.
|
||||||
|
$SIG{__WARN__} = sub {
|
||||||
|
my $warning = shift;
|
||||||
|
warn $warning unless $warning =~ /Subroutine .* redefined at/;
|
||||||
|
};
|
||||||
|
|
||||||
# Start transaction
|
# Start transaction
|
||||||
my $schema = Koha::Database->new->schema;
|
my $schema = Koha::Database->new->schema;
|
||||||
$schema->storage->txn_begin();
|
$schema->storage->txn_begin();
|
||||||
|
@ -37,6 +46,7 @@ my $builder = t::lib::TestBuilder->new();
|
||||||
# Variables controlling LDAP server config
|
# Variables controlling LDAP server config
|
||||||
my $update = 0;
|
my $update = 0;
|
||||||
my $replicate = 0;
|
my $replicate = 0;
|
||||||
|
my $welcome = 0;
|
||||||
my $auth_by_bind = 1;
|
my $auth_by_bind = 1;
|
||||||
my $anonymous_bind = 1;
|
my $anonymous_bind = 1;
|
||||||
my $user = 'cn=Manager,dc=metavore,dc=com';
|
my $user = 'cn=Manager,dc=metavore,dc=com';
|
||||||
|
@ -144,7 +154,7 @@ subtest 'checkpw_ldap tests' => sub {
|
||||||
|
|
||||||
subtest 'auth_by_bind = 1 tests' => sub {
|
subtest 'auth_by_bind = 1 tests' => sub {
|
||||||
|
|
||||||
plan tests => 11;
|
plan tests => 14;
|
||||||
|
|
||||||
$auth_by_bind = 1;
|
$auth_by_bind = 1;
|
||||||
|
|
||||||
|
@ -221,6 +231,50 @@ subtest 'checkpw_ldap tests' => sub {
|
||||||
'checkpw_ldap returns 0 if user lookup returns 0'
|
'checkpw_ldap returns 0 if user lookup returns 0'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# test replicate functionality and welcome notice
|
||||||
|
$desired_authentication_result = 'success';
|
||||||
|
$anonymous_bind = 1;
|
||||||
|
$desired_admin_bind_result = 'success';
|
||||||
|
$desired_search_result = 'success';
|
||||||
|
$desired_count_result = 1;
|
||||||
|
$desired_bind_result = 'success';
|
||||||
|
$replicate = 1;
|
||||||
|
$welcome = 1;
|
||||||
|
reload_ldap_module();
|
||||||
|
|
||||||
|
$auth->mock(
|
||||||
|
'ldap_entry_2_hash',
|
||||||
|
sub {
|
||||||
|
return (
|
||||||
|
userid => 'hola',
|
||||||
|
branchcode => $branchcode,
|
||||||
|
categorycode => $categorycode,
|
||||||
|
email => 'me@myemail.com',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
C4::Auth_with_ldap::checkpw_ldap( 'hola', password => 'hey' );
|
||||||
|
my $patrons = Koha::Patrons->search( { userid => 'hola' } );
|
||||||
|
is( $patrons->count, 1, 'New patron added with "replicate"' );
|
||||||
|
|
||||||
|
$patron = $patrons->next;
|
||||||
|
my $queued_notices = Koha::Notice::Messages->search(
|
||||||
|
{ borrowernumber => $patron->borrowernumber } );
|
||||||
|
is( $queued_notices->count, 1,
|
||||||
|
"One notice queued when `welcome` is set" );
|
||||||
|
|
||||||
|
my $THE_notice = $queued_notices->next;
|
||||||
|
is( $THE_notice->status, 'failed', "The notice was sent immediately" );
|
||||||
|
|
||||||
|
# clean up
|
||||||
|
$patron->delete;
|
||||||
|
$replicate = 0;
|
||||||
|
$welcome = 0;
|
||||||
|
$auth->unmock('ldap_entry_2_hash');
|
||||||
|
# end replicate testing
|
||||||
|
|
||||||
|
$desired_count_result = 0;
|
||||||
$desired_bind_result = 'error';
|
$desired_bind_result = 'error';
|
||||||
reload_ldap_module();
|
reload_ldap_module();
|
||||||
|
|
||||||
|
@ -376,6 +430,7 @@ sub mockedC4Config {
|
||||||
pass => $pass,
|
pass => $pass,
|
||||||
principal_name => '%s@my_domain.com',
|
principal_name => '%s@my_domain.com',
|
||||||
replicate => $replicate,
|
replicate => $replicate,
|
||||||
|
welcome => $welcome,
|
||||||
update => $update,
|
update => $update,
|
||||||
user => $user,
|
user => $user,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue