check_ldap.t 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env perl -I ..
  2. #
  3. # Lightweight Directory Access Protocol (LDAP) Test via check_ldap
  4. #
  5. #
  6. use strict;
  7. use warnings;
  8. use Test::More;
  9. use NPTest;
  10. my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP",
  11. "A host providing the LDAP Service",
  12. "localhost" );
  13. my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN",
  14. "A base dn for the LDAP Service",
  15. "cn=admin" );
  16. my $host_nonresponsive = getTestParameter("host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
  17. "The hostname of system not responsive to network requests" );
  18. my $hostname_invalid = getTestParameter("hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
  19. "An invalid (not known to DNS) hostname" );
  20. my($result, $cmd);
  21. my $command = './check_ldap';
  22. plan tests => 16;
  23. SKIP: {
  24. skip "NP_HOST_NONRESPONSIVE not set", 2 if ! $host_nonresponsive;
  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. SKIP: {
  30. skip "NP_HOSTNAME_INVALID not set", 2 if ! $hostname_invalid;
  31. $result = NPTest->testCmd("$command -H $hostname_invalid -b ou=blah -t 5");
  32. is( $result->return_code, 2, "$command -H $hostname_invalid -b ou=blah -t 5" );
  33. is( $result->output, 'Could not bind to the LDAP server', "output ok" );
  34. };
  35. SKIP: {
  36. skip "NP_HOST_TCP_LDAP not set", 12 if ! $host_tcp_ldap;
  37. skip "NP_LDAP_BASE_DN not set", 12 if ! $ldap_base_dn;
  38. $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3";
  39. $result = NPTest->testCmd($cmd);
  40. is( $result->return_code, 0, $cmd );
  41. like( $result->output, '/^LDAP OK - \d+.\d+ seconds response time\|time=\d+\.\d+s;2\.0+;3\.0+;0\.0+$/', "output ok" );
  42. $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000 -C 10000001";
  43. $result = NPTest->testCmd($cmd);
  44. is( $result->return_code, 0, $cmd );
  45. 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" );
  46. $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001:";
  47. $result = NPTest->testCmd($cmd);
  48. is( $result->return_code, 2, $cmd );
  49. 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" );
  50. $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 0 -C 0";
  51. $result = NPTest->testCmd($cmd);
  52. is( $result->return_code, 2, $cmd );
  53. 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" );
  54. $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001";
  55. $result = NPTest->testCmd($cmd);
  56. is( $result->return_code, 1, $cmd );
  57. 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" );
  58. $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -C 10000001";
  59. $result = NPTest->testCmd($cmd);
  60. is( $result->return_code, 0, $cmd );
  61. 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" );
  62. };