check_http.t 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # HyperText Transfer Protocol (HTTP) Test via check_http
  4. #
  5. # $Id$
  6. #
  7. use strict;
  8. use Test::More;
  9. use NPTest;
  10. my $successOutput = '/OK.*HTTP.*second/';
  11. my $res;
  12. my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP",
  13. "A host providing the HTTP Service (a web server)",
  14. "localhost" );
  15. my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
  16. "The hostname of system not responsive to network requests",
  17. "10.0.0.1" );
  18. my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
  19. "An invalid (not known to DNS) hostname",
  20. "nosuchhost");
  21. plan tests => 8;
  22. $res = NPTest->testCmd(
  23. "./check_http $host_tcp_http -wt 300 -ct 600"
  24. );
  25. cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" );
  26. like( $res->output, $successOutput, "Output OK" );
  27. $res = NPTest->testCmd(
  28. "./check_http $host_nonresponsive -wt 1 -ct 2"
  29. );
  30. cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" );
  31. cmp_ok( $res->output, 'eq', "CRITICAL - Socket timeout after 10 seconds", "Output OK");
  32. $res = NPTest->testCmd(
  33. "./check_http $hostname_invalid -wt 1 -ct 2"
  34. );
  35. cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" );
  36. like( $res->output, "/Name or service not known.*/", "Output OK");
  37. $res = NPTest->testCmd(
  38. "./check_http --ssl www.verisign.com"
  39. );
  40. cmp_ok( $res->return_code, '==', 0, "Can read https for www.verisign.com" );
  41. $res = NPTest->testCmd(
  42. "./check_http --ssl www.e-paycobalt.com"
  43. );
  44. cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" );