8 use vars
qw(%cases $dbh $config $context $ldap);
12 # users from t/LDAP/example3.ldif
18 plan tests => 8 + scalar(keys %cases);
19 use_ok('C4::Context');
20 use_ok('C4::Auth_with_ldap', qw(checkpw_ldap));
23 sub do_checkpw_ldap
(;$$) {
24 my ($user,$pass) = (shift,shift);
27 return ($ret = checkpw_ldap
($dbh,$user,$pass), sprintf("(%s,%s) returns '%s'",$user,$pass,$ret));
30 ok
($context= C4
::Context
->new(), "Getting new C4::Context object");
31 ok
($dbh = C4
::Context
->dbh(), "Getting dbh from C4::Context");
32 ok
($dbh = $context->dbh(), "Getting dbh from \$context object");
34 $ldap = $ENV{KOHA_USELDAPSERVER
};
36 diag
"Overriding KOHA_CONF <useldapserver> with \$ENV{KOHA_USELDAPSERVER} = $ldap";
38 diag
'Note: You can use $ENV{KOHA_USELDAPSERVER} to override KOHA_CONF <useldapserver> for this test';
39 $ldap = C4
::Context
->config('useldapserver');
41 ok
(defined($ldap), "Checking if \$ENV{KOHA_USELDAPSERVER} or <useldapserver> is defined");
44 $ldap or skip
("LDAP is disabled.", scalar(keys %cases) + 2);
45 diag
("The basis of Authentication is that we don't auth everybody.");
46 diag
("Let's make sure we reject on bad calls.");
48 ok
(!($ret = checkpw_ldap
($dbh)), "should reject ( no arguments) returns '$ret'");
49 ok
(!($ret = checkpw_ldap
($dbh,'','')), "should reject (empty arguments) returns '$ret'");
51 diag
("Now let's check " . scalar(keys %cases) . " test cases: ");
52 foreach (sort keys %cases) {
53 ok do_checkpw_ldap
($_, $cases{$_});