Allow LDAP test to bail if LDAP disabled.
authorJoe Atzberger <joe.atzberger@liblime.com>
Fri, 23 Jan 2009 17:57:57 +0000 (11:57 -0600)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Tue, 26 May 2009 19:14:58 +0000 (21:14 +0200)
Also added more feedback and the ability to override KOHA_CONF
"useldapserver" value with ENV variable KOHA_USELDAPSERVER.

This patch should be considered for inclusion to 3.0 stable branch
because it prevents unnecessary failure of test battery.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
Signed-off-by: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
t/db_dependent/Auth_with_ldap.t

index 2f1874c..9615151 100755 (executable)
@@ -15,7 +15,7 @@ BEGIN {
                rch => 'password2',
                jmf => 'password3',
        );
-       plan tests => 7 + scalar(keys %cases);
+       plan tests => 8 + scalar(keys %cases);
        use_ok('C4::Context');
        use_ok('C4::Auth_with_ldap', qw(checkpw_ldap));
 }
@@ -31,15 +31,26 @@ ok($context= C4::Context->new(),    "Getting new C4::Context object");
 ok($dbh    = C4::Context->dbh(),       "Getting dbh from C4::Context");
 ok($dbh    = $context->dbh(),          "Getting dbh from \$context object");
 
-diag("The basis of Authentication is that we don't auth everybody.");
-diag("Let's make sure we reject on bad calls.");
-my $ret;
-ok(!($ret = checkpw_ldap($dbh)),       "should reject (  no  arguments) returns '$ret'");
-ok(!($ret = checkpw_ldap($dbh,'','')), "should reject (empty arguments) returns '$ret'");
-print "\n";
-diag("Now let's check " . scalar(keys %cases) . " test cases: ");
-foreach (sort keys %cases) {
-       ok do_checkpw_ldap($_, $cases{$_});
+$ldap = $ENV{KOHA_USELDAPSERVER};
+if(defined($ldap)) {
+    diag "Overriding KOHA_CONF <useldapserver> with \$ENV{KOHA_USELDAPSERVER} = $ldap";
+} else {
+    diag 'Note: You can use $ENV{KOHA_USELDAPSERVER} to override KOHA_CONF <useldapserver> for this test';
+    $ldap = C4::Context->config('useldapserver');
 }
+ok(defined($ldap), "Checking if \$ENV{KOHA_USELDAPSERVER} or <useldapserver> is defined");
 
+SKIP: {
+    $ldap or skip("LDAP is disabled.", scalar(keys %cases) + 2);
+    diag("The basis of Authentication is that we don't auth everybody.");
+    diag("Let's make sure we reject on bad calls.");
+    my $ret;
+    ok(!($ret = checkpw_ldap($dbh)),       "should reject (  no  arguments) returns '$ret'");
+    ok(!($ret = checkpw_ldap($dbh,'','')), "should reject (empty arguments) returns '$ret'");
+    print "\n";
+    diag("Now let's check " . scalar(keys %cases) . " test cases: ");
+    foreach (sort keys %cases) {
+        ok do_checkpw_ldap($_, $cases{$_});
+    }
+}
 1;