View | Details | Raw Unified | Return to bug 10334
Collapse All | Expand All

(-)a/t/db_dependent/needs_user_input/Auth.t (-44 lines)
Lines 1-44 Link Here
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!  
4
# Add more tests here!!!
5
6
use strict;
7
use warnings;
8
9
use Test::More tests => 6;
10
11
BEGIN {
12
	use FindBin;
13
	use lib $FindBin::Bin;
14
	use override_context_prefs;
15
        use_ok('C4::Auth', qw(checkpw));
16
        use_ok('C4::Context');
17
}
18
19
use vars qw($dbh $ldap);
20
can_ok('C4::Context', 'config');
21
can_ok('C4::Context', 'dbh');
22
can_ok('C4::Auth', qw(checkpw));
23
    ok($dbh  = C4::Context->dbh(),  "Getting dbh from C4::Context");
24
$ldap = C4::Context->config('useldapserver') || 0;
25
diag("Using LDAP? $ldap");
26
27
while (1) {		# forever!
28
	print "Do you want to test further accounts? (If not, just hit return.)\n";
29
	my ($user, $pass);
30
	print "Enter username: ";
31
	chomp($user = <>);
32
	($user) or exit;
33
	print "Enter password: ";
34
	chomp($pass = <>);
35
	my ($retval,$retcard) = checkpw($dbh,$user,$pass);
36
	$retval  ||= '';
37
	$retcard ||= '';
38
	diag ("checkpw(\$dbh,$user,$pass) " . ($retval ? 'SUCCEEDS' : ' FAILS  ') . "\treturns ($retval,$retcard)");
39
}
40
41
END {
42
	diag("C4::Auth - end of test");
43
}
44
__END__
(-)a/t/db_dependent/needs_user_input/Auth_with_ldap.t (-57 lines)
Lines 1-56 Link Here
1
#!/bin/perl
2
#
3
4
use strict;
5
use warnings;
6
7
use Test::More;
8
use vars qw(%cases $dbh $config $context $ldap);
9
10
BEGIN {
11
	%cases = (
12
		# users from t/LDAP/example3.ldif
13
		sss => 'password1',
14
		jts => 'password1',
15
		rch => 'password2',
16
		jmf => 'password3',
17
	);
18
	plan tests => 8 + scalar(keys %cases);
19
	use_ok('C4::Context');
20
	use_ok('C4::Auth_with_ldap', qw(checkpw_ldap));
21
}
22
23
sub do_checkpw_ldap (;$$) { 
24
	my ($user,$pass) = (shift,shift);
25
	diag "($user,$pass)";
26
	my $ret;
27
	return ($ret = checkpw_ldap($dbh,$user,$pass), sprintf("(%s,%s) returns '%s'",$user,$pass,$ret));
28
}
29
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");
33
34
$ldap = $ENV{KOHA_USELDAPSERVER};
35
if(defined($ldap)) {
36
    diag "Overriding KOHA_CONF <useldapserver> with \$ENV{KOHA_USELDAPSERVER} = $ldap";
37
} else {
38
    diag 'Note: You can use $ENV{KOHA_USELDAPSERVER} to override KOHA_CONF <useldapserver> for this test';
39
    $ldap = C4::Context->config('useldapserver');
40
}
41
ok(defined($ldap), "Checking if \$ENV{KOHA_USELDAPSERVER} or <useldapserver> is defined");
42
43
SKIP: {
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.");
47
    my $ret;
48
    ok(!($ret = checkpw_ldap($dbh)),       "should reject (  no  arguments) returns '$ret'");
49
    ok(!($ret = checkpw_ldap($dbh,'','')), "should reject (empty arguments) returns '$ret'");
50
    print "\n";
51
    diag("Now let's check " . scalar(keys %cases) . " test cases: ");
52
    foreach (sort keys %cases) {
53
        ok do_checkpw_ldap($_, $cases{$_});
54
    }
55
}
56
1;
57
- 

Return to bug 10334