diff options
Diffstat (limited to 'plugins/t/check_ldap.t')
-rw-r--r-- | plugins/t/check_ldap.t | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/plugins/t/check_ldap.t b/plugins/t/check_ldap.t new file mode 100644 index 00000000..b8a4a766 --- /dev/null +++ b/plugins/t/check_ldap.t | |||
@@ -0,0 +1,71 @@ | |||
1 | #!/usr/bin/env perl -I .. | ||
2 | # | ||
3 | # Lightweight Directory Access Protocol (LDAP) Test via check_ldap | ||
4 | # | ||
5 | # | ||
6 | |||
7 | use strict; | ||
8 | use warnings; | ||
9 | use Test::More; | ||
10 | use NPTest; | ||
11 | |||
12 | my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP", "A host providing the LDAP Service", "localhost"); | ||
13 | my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN", "A base dn for the LDAP Service", "cn=admin"); | ||
14 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | ||
15 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | ||
16 | |||
17 | my($result, $cmd); | ||
18 | my $command = './check_ldap'; | ||
19 | |||
20 | plan tests => 16; | ||
21 | |||
22 | SKIP: { | ||
23 | skip "NP_HOST_NONRESPONSIVE not set", 2 if ! $host_nonresponsive; | ||
24 | |||
25 | $result = NPTest->testCmd("$command -H $host_nonresponsive -b ou=blah -t 2 -w 1 -c 1"); | ||
26 | is( $result->return_code, 2, "$command -H $host_nonresponsive -b ou=blah -t 5 -w 2 -c 3" ); | ||
27 | is( $result->output, 'CRITICAL - Socket timeout after 2 seconds', "output ok" ); | ||
28 | }; | ||
29 | |||
30 | SKIP: { | ||
31 | skip "NP_HOSTNAME_INVALID not set", 2 if ! $hostname_invalid; | ||
32 | |||
33 | $result = NPTest->testCmd("$command -H $hostname_invalid -b ou=blah -t 5"); | ||
34 | is( $result->return_code, 2, "$command -H $hostname_invalid -b ou=blah -t 5" ); | ||
35 | is( $result->output, 'Could not bind to the LDAP server', "output ok" ); | ||
36 | }; | ||
37 | |||
38 | SKIP: { | ||
39 | skip "NP_HOST_TCP_LDAP not set", 12 if ! $host_tcp_ldap; | ||
40 | skip "NP_LDAP_BASE_DN not set", 12 if ! $ldap_base_dn; | ||
41 | |||
42 | $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3"; | ||
43 | $result = NPTest->testCmd($cmd); | ||
44 | is( $result->return_code, 0, $cmd ); | ||
45 | like( $result->output, '/^LDAP OK - \d+.\d+ seconds response time\|time=\d+\.\d+s;2\.0+;3\.0+;0\.0+$/', "output ok" ); | ||
46 | |||
47 | $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000 -C 10000001"; | ||
48 | $result = NPTest->testCmd($cmd); | ||
49 | is( $result->return_code, 0, $cmd ); | ||
50 | like( $result->output, '/^LDAP OK - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000;10000001;0\.0+$/', "output ok" ); | ||
51 | |||
52 | $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001:"; | ||
53 | $result = NPTest->testCmd($cmd); | ||
54 | is( $result->return_code, 2, $cmd ); | ||
55 | like( $result->output, '/^LDAP CRITICAL - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000:;10000001:;0\.0+$/', "output ok" ); | ||
56 | |||
57 | $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 0 -C 0"; | ||
58 | $result = NPTest->testCmd($cmd); | ||
59 | is( $result->return_code, 2, $cmd ); | ||
60 | like( $result->output, '/^LDAP CRITICAL - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;0;0;0\.0+$/', "output ok" ); | ||
61 | |||
62 | $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001"; | ||
63 | $result = NPTest->testCmd($cmd); | ||
64 | is( $result->return_code, 1, $cmd ); | ||
65 | like( $result->output, '/^LDAP WARNING - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000:;10000001;0\.0+$/', "output ok" ); | ||
66 | |||
67 | $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -C 10000001"; | ||
68 | $result = NPTest->testCmd($cmd); | ||
69 | is( $result->return_code, 0, $cmd ); | ||
70 | like( $result->output, '/^LDAP OK - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;;10000001;0\.0+$/', "output ok" ); | ||
71 | }; | ||