adding a pre-check for patronimages/ dir, which won't be there by
[koha.git] / t / Auth_with_ldap.t
1 #!/bin/perl
2 #
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8 use vars qw(%cases $dbh $config $ldap);
9
10 BEGIN {
11         %cases = (
12                 # users from example3.ldif
13                 sss => 'password1',
14                 jts => 'password1',
15                 rch => 'password2',
16                 jmf => 'password3',
17         );
18         plan tests => 3 + scalar(keys %cases);
19         use_ok('C4::Context');
20         use_ok('C4::Auth_with_ldap', qw(checkauth));
21 }
22
23 sub do_checkauth (;$$) { 
24         my ($user,$pass) = (shift,shift);
25         diag "($user,$pass)";
26         my $ret;
27         return ($ret = checkauth($dbh,$user,$pass), sprintf("(%s,%s) returns '%s'",$user,$pass,$ret));
28 }
29
30 ok($dbh    = C4::Context->dbh(),                "Getting dbh from C4::Context");
31 ok($config = C4::Context->config(),     "Getting config (hashref) from C4::Context");
32 ok($ldap   = $config->{ldap},                   "Getting LDAP info from config");
33
34 diag("The basis of Authenticaiton is that we don't auth everybody.");
35 diag("Let's make sure we reject on bad calls.");
36 my $ret;
37 ok(!($ret = checkauth($dbh)),       "should reject (  no  arguments) returns '$ret'");
38 ok(!($ret = checkauth($dbh,'','')), "should reject (empty arguments) returns '$ret'");
39 print "\n";
40 diag("Now let's check " . scalar(keys %cases) . " test cases: ");
41 foreach (sort keys %cases) {
42         ok do_checkauth($_, $cases{$_});
43 }
44
45 1;