use Koha::Patrons;
-my $dbh = '';
-
# Start transaction
-my $database = Koha::Database->new();
-my $schema = $database->schema();
+my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin();
my $builder = t::lib::TestBuilder->new();
my $replicate = 0;
my $auth_by_bind = 1;
my $anonymous_bind = 1;
+my $user = 'cn=Manager,dc=metavore,dc=com';
+my $pass = 'metavore';
# Variables controlling LDAP behaviour
my $desired_authentication_result = 'success';
}
);
+my $patron = Koha::Patrons->find($borrower->{borrowernumber});
+
# C4::Auth_with_ldap needs several stuff set first ^^^
-use_ok('C4::Auth_with_ldap');
+use_ok('C4::Auth_with_ldap', qw( checkpw_ldap ));
can_ok(
'C4::Auth_with_ldap', qw/
checkpw_ldap
plan tests => 4;
- my $dbh = C4::Context->dbh;
## Connection fail tests
$desired_connection_result = 'error';
warning_is {
$ret =
- C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola', password => 'hey' );
+ C4::Auth_with_ldap::checkpw_ldap( 'hola', password => 'hey' );
}
'LDAP connexion failed',
'checkpw_ldap prints correct warning if LDAP conexion fails';
subtest 'auth_by_bind = 1 tests' => sub {
- plan tests => 9;
+ plan tests => 11;
$auth_by_bind = 1;
reload_ldap_module();
warning_like {
- $ret = C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola',
+ $ret = C4::Auth_with_ldap::checkpw_ldap( 'hola',
password => 'hey' );
}
qr/Anonymous LDAP bind failed: LDAP error #1: error_name/,
'checkpw_ldap prints correct warning if LDAP anonymous bind fails';
is( $ret, 0, 'checkpw_ldap returns 0 if LDAP anonymous bind fails' );
+ $anonymous_bind = 0;
+ $user = undef;
+ $pass = undef;
+ reload_ldap_module();
+
+ warning_like {
+ $ret = C4::Auth_with_ldap::checkpw_ldap( 'hola',
+ password => 'hey' );
+ }
+ qr/LDAP bind failed as kohauser hola: LDAP error #1: error_name/,
+ 'checkpw_ldap prints correct warning if LDAP bind_by_auth fails';
+ is( $ret, 0, 'checkpw_ldap returns 0 if LDAP bind_by_auth fails' );
+
$desired_authentication_result = 'success';
$anonymous_bind = 1;
$desired_admin_bind_result = 'success';
}
);
- C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola', password => 'hey' );
+ C4::Auth_with_ldap::checkpw_ldap( 'hola', password => 'hey' );
ok(
- @{
- C4::Members::Attributes::GetBorrowerAttributes(
- $borrower->{borrowernumber}
- )
- },
+ Koha::Patrons->find($borrower->{borrowernumber})->extended_attributes->count,
'Extended attributes are not deleted'
);
- is( C4::Members::Attributes::GetBorrowerAttributeValue($borrower->{borrowernumber}, $attr_type2->{code}), 'BAR', 'Mapped attribute is BAR' );
+ is( $patron->get_extended_attribute( $attr_type2->{code} )->attribute, 'BAR', 'Mapped attribute is BAR' );
$auth->unmock('update_local');
$auth->unmock('ldap_entry_2_hash');
$update = 0;
$desired_count_result = 0; # user auth problem
- Koha::Patrons->find( $borrower->{borrowernumber} )->delete;
+ $patron->delete;
reload_ldap_module();
is(
- C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola', password => 'hey' ),
+ C4::Auth_with_ldap::checkpw_ldap( 'hola', password => 'hey' ),
0,
'checkpw_ldap returns 0 if user lookup returns 0'
);
reload_ldap_module();
warning_like {
- $ret = C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola',
+ $ret = C4::Auth_with_ldap::checkpw_ldap( 'hola',
password => 'hey' );
}
qr/LDAP bind failed as kohauser hola: LDAP error #1: error_name/,
reload_ldap_module();
warning_like {
- $ret = C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola',
+ $ret = C4::Auth_with_ldap::checkpw_ldap( 'hola',
password => 'hey' );
}
qr/LDAP bind failed as kohauser hola: LDAP error #1: error_name/,
# Anonymous bind
$anonymous_bind = 1;
+ $user = 'cn=Manager,dc=metavore,dc=com';
+ $pass = 'metavore';
$desired_admin_bind_result = 'error';
- $desired_bind_result = 'error';
+ $desired_bind_result = 'error';
reload_ldap_module();
warning_like {
- $ret = C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola',
+ $ret = C4::Auth_with_ldap::checkpw_ldap( 'hola',
password => 'hey' );
}
qr/LDAP bind failed as ldapuser cn=Manager,dc=metavore,dc=com: LDAP error #1: error_name/,
reload_ldap_module();
warning_like {
- $ret = C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola',
+ $ret = C4::Auth_with_ldap::checkpw_ldap( 'hola',
password => 'hey' );
}
qr/LDAP Auth rejected : invalid password for user 'hola'./,
reload_ldap_module();
warning_like {
- $ret = C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola',
+ $ret = C4::Auth_with_ldap::checkpw_ldap( 'hola',
password => 'hey' );
}
qr/LDAP bind failed as ldapuser cn=Manager,dc=metavore,dc=com: LDAP error #1: error_name/,
reload_ldap_module();
warning_like {
- $ret = C4::Auth_with_ldap::checkpw_ldap( $dbh, 'hola',
+ $ret = C4::Auth_with_ldap::checkpw_ldap( 'hola',
password => 'hey' );
}
qr/LDAP Auth rejected : invalid password for user 'hola'./,
base => 'dc=metavore,dc=com',
hostname => 'localhost',
mapping => \%ldap_mapping,
- pass => 'metavore',
+ pass => $pass,
principal_name => '%s@my_domain.com',
replicate => $replicate,
update => $update,
- user => 'cn=Manager,dc=metavore,dc=com',
+ user => $user,
);
return \%ldap_config;
}
if ( ref $class eq 'HASH' ) {
return $class->{$param};
}
- return;
+
+ return C4::Context::_common_config($param, 'config');
}
# Function that mocks the call to Net::LDAP
'search',
sub {
- $remaining_entry = 1
+ $remaining_entry = 1;
return mock_net_ldap_search(
{
return 0;
}
-$schema->storage->txn_rollback;
+$schema->storage->txn_rollback();
-1;