diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2008-11-08 02:08:56 (GMT) |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2008-11-08 02:08:56 (GMT) |
commit | 288b742ed61bb62a210fdd3614d4e3883aa82407 (patch) | |
tree | df78d3d69fa3b0015cfb59b0b3d75db841f4c603 /plugins/tests/check_http.t | |
parent | c4c897ea96c5592fd45294941d57f672f9361952 (diff) | |
download | monitoring-plugins-288b742ed61bb62a210fdd3614d4e3883aa82407.tar.gz |
check_http now has options to specify the HTTP method (Jan - 2155152)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2075 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/tests/check_http.t')
-rwxr-xr-x | plugins/tests/check_http.t | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index 6b932d9..d54932e 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -33,9 +33,7 @@ if ($pid) { | |||
33 | print "Please contact me at: <URL:", $d->url, ">\n"; | 33 | print "Please contact me at: <URL:", $d->url, ">\n"; |
34 | while (my $c = $d->accept ) { | 34 | while (my $c = $d->accept ) { |
35 | while (my $r = $c->get_request) { | 35 | while (my $r = $c->get_request) { |
36 | if ($r->method eq "GET" and $r->url->path eq "/xyzzy") { | 36 | if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) { |
37 | $c->send_file_response("/etc/passwd"); | ||
38 | } elsif ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) { | ||
39 | $c->send_basic_header($1); | 37 | $c->send_basic_header($1); |
40 | $c->send_crlf; | 38 | $c->send_crlf; |
41 | } elsif ($r->method eq "GET" and $r->url->path =~ m^/file/(.*)^) { | 39 | } elsif ($r->method eq "GET" and $r->url->path =~ m^/file/(.*)^) { |
@@ -47,6 +45,18 @@ if ($pid) { | |||
47 | $c->send_crlf; | 45 | $c->send_crlf; |
48 | sleep 1; | 46 | sleep 1; |
49 | $c->send_response("slow"); | 47 | $c->send_response("slow"); |
48 | } elsif ($r->url->path eq "/method") { | ||
49 | if ($r->method eq "DELETE") { | ||
50 | $c->send_error(RC_METHOD_NOT_ALLOWED); | ||
51 | } elsif ($r->method eq "foo") { | ||
52 | $c->send_error(RC_NOT_IMPLEMENTED); | ||
53 | } else { | ||
54 | $c->send_status_line(200, $r->method); | ||
55 | } | ||
56 | } elsif ($r->url->path eq "/postdata") { | ||
57 | $c->send_basic_header; | ||
58 | $c->send_crlf; | ||
59 | $c->send_response($r->method.":".$r->content); | ||
50 | } else { | 60 | } else { |
51 | $c->send_error(RC_FORBIDDEN); | 61 | $c->send_error(RC_FORBIDDEN); |
52 | } | 62 | } |
@@ -63,7 +73,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { | |||
63 | } | 73 | } |
64 | 74 | ||
65 | if (-x "./check_http") { | 75 | if (-x "./check_http") { |
66 | plan tests => 19; | 76 | plan tests => 39; |
67 | } else { | 77 | } else { |
68 | plan skip_all => "No check_http compiled"; | 78 | plan skip_all => "No check_http compiled"; |
69 | } | 79 | } |
@@ -119,3 +129,54 @@ $result = NPTest->testCmd( $cmd ); | |||
119 | is( $result->return_code, 2, $cmd); | 129 | is( $result->return_code, 2, $cmd); |
120 | like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information/', "Output correct: ".$result->output ); | 130 | like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information/', "Output correct: ".$result->output ); |
121 | 131 | ||
132 | $cmd = "$command -j HEAD -u /method"; | ||
133 | $result = NPTest->testCmd( $cmd ); | ||
134 | is( $result->return_code, 0, $cmd); | ||
135 | like( $result->output, '/^HTTP OK HTTP/1.1 200 HEAD - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
136 | |||
137 | $cmd = "$command -j POST -u /method"; | ||
138 | $result = NPTest->testCmd( $cmd ); | ||
139 | is( $result->return_code, 0, $cmd); | ||
140 | like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
141 | |||
142 | $cmd = "$command -j GET -u /method"; | ||
143 | $result = NPTest->testCmd( $cmd ); | ||
144 | is( $result->return_code, 0, $cmd); | ||
145 | like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - 18 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
146 | |||
147 | $cmd = "$command -u /method"; | ||
148 | $result = NPTest->testCmd( $cmd ); | ||
149 | is( $result->return_code, 0, $cmd); | ||
150 | like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - 18 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
151 | |||
152 | $cmd = "$command -P foo -u /method"; | ||
153 | $result = NPTest->testCmd( $cmd ); | ||
154 | is( $result->return_code, 0, $cmd); | ||
155 | like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
156 | |||
157 | $cmd = "$command -j DELETE -u /method"; | ||
158 | $result = NPTest->testCmd( $cmd ); | ||
159 | is( $result->return_code, 1, $cmd); | ||
160 | like( $result->output, '/^HTTP WARNING: HTTP/1.1 405 Method Not Allowed/', "Output correct: ".$result->output ); | ||
161 | |||
162 | $cmd = "$command -j foo -u /method"; | ||
163 | $result = NPTest->testCmd( $cmd ); | ||
164 | is( $result->return_code, 2, $cmd); | ||
165 | like( $result->output, '/^HTTP CRITICAL: HTTP/1.1 501 Not Implemented/', "Output correct: ".$result->output ); | ||
166 | |||
167 | $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude"; | ||
168 | $result = NPTest->testCmd( $cmd ); | ||
169 | is( $result->return_code, 0, $cmd); | ||
170 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); | ||
171 | |||
172 | $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude"; | ||
173 | $result = NPTest->testCmd( $cmd ); | ||
174 | is( $result->return_code, 0, $cmd); | ||
175 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); | ||
176 | |||
177 | # To confirm that the free doesn't segfault | ||
178 | $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude"; | ||
179 | $result = NPTest->testCmd( $cmd ); | ||
180 | is( $result->return_code, 0, $cmd); | ||
181 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); | ||
182 | |||