summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xplugins/tests/check_http.t81
1 files changed, 39 insertions, 42 deletions
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index d221463b..d7f4148c 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -140,10 +140,12 @@ END {
140}; 140};
141 141
142if ($ARGV[0] && $ARGV[0] eq "-d") { 142if ($ARGV[0] && $ARGV[0] eq "-d") {
143 sleep 1000; 143 while (1) {
144 `sleep 100`
145 }
144} 146}
145 147
146my $common_tests = 47; 148my $common_tests = 51;
147my $ssl_only_tests = 6; 149my $ssl_only_tests = 6;
148if (-x "./check_http") { 150if (-x "./check_http") {
149 plan tests => $common_tests * 2 + $ssl_only_tests; 151 plan tests => $common_tests * 2 + $ssl_only_tests;
@@ -180,95 +182,91 @@ SKIP: {
180sub run_common_tests { 182sub run_common_tests {
181 my ($opts) = @_; 183 my ($opts) = @_;
182 my $command = $opts->{command}; 184 my $command = $opts->{command};
183 my $b;
184 my $add = 0;
185 if ($opts->{ssl}) { 185 if ($opts->{ssl}) {
186 $command .= " --ssl"; 186 $command .= " --ssl";
187 } 187 }
188 188
189 $result = NPTest->testCmd( "$command -u /file/root" ); 189 $result = NPTest->testCmd( "$command -u /file/root" );
190 is( $result->return_code, 0, "/file/root"); 190 is( $result->return_code, 0, "/file/root");
191 like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 274 bytes in [\d\.]+ seconds/', "Output correct" ); 191 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" );
192 192
193 $result = NPTest->testCmd( "$command -u /file/root -s Root" ); 193 $result = NPTest->testCmd( "$command -u /file/root -s Root" );
194 is( $result->return_code, 0, "/file/root search for string"); 194 is( $result->return_code, 0, "/file/root search for string");
195 TODO: { 195 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" );
196 local $TODO = "Output is different if a string is requested - should this be right?";
197 like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 274 bytes in [\d\.]+ seconds/', "Output correct" );
198 }
199 196
200 197
201 $b = 177 + $add; 198 my $cmd;
202 $result = NPTest->testCmd( "$command -u /slow" ); 199 $cmd = "$command -u /slow";
203 is( $result->return_code, 0, "/file/root"); 200 $result = NPTest->testCmd( $cmd );
204 like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct" ); 201 is( $result->return_code, 0, "$cmd");
205 $result->output =~ /in ([\d\.]+) seconds/; 202 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
203 $result->output =~ /in ([\d\.]+) second/;
206 cmp_ok( $1, ">", 1, "Time is > 1 second" ); 204 cmp_ok( $1, ">", 1, "Time is > 1 second" );
207 205
208 my $cmd; 206 $cmd = "$command -u /statuscode/200";
209 $b = 89 + $add; 207 $result = NPTest->testCmd( $cmd );
208 is( $result->return_code, 0, $cmd);
209 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
210
210 $cmd = "$command -u /statuscode/200 -e 200"; 211 $cmd = "$command -u /statuscode/200 -e 200";
211 $result = NPTest->testCmd( $cmd ); 212 $result = NPTest->testCmd( $cmd );
212 is( $result->return_code, 0, $cmd); 213 is( $result->return_code, 0, $cmd);
213 like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); 214 like( $result->output, '/^HTTP OK: Status line output matched "200" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
215
216 $cmd = "$command -u /statuscode/201";
217 $result = NPTest->testCmd( $cmd );
218 is( $result->return_code, 0, $cmd);
219 like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output );
214 220
215 $b = 94 + $add;
216 $cmd = "$command -u /statuscode/201 -e 201"; 221 $cmd = "$command -u /statuscode/201 -e 201";
217 $result = NPTest->testCmd( $cmd ); 222 $result = NPTest->testCmd( $cmd );
218 is( $result->return_code, 0, $cmd); 223 is( $result->return_code, 0, $cmd);
219 like( $result->output, '/^HTTP OK HTTP/1.1 201 Created - '.$b.' bytes in ([\d\.]+) seconds /', "Output correct: ".$result->output ); 224 like( $result->output, '/^HTTP OK: Status line output matched "201" - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output );
220 225
221 $cmd = "$command -u /statuscode/201 -e 200"; 226 $cmd = "$command -u /statuscode/201 -e 200";
222 $result = NPTest->testCmd( $cmd ); 227 $result = NPTest->testCmd( $cmd );
223 is( $result->return_code, 2, $cmd); 228 is( $result->return_code, 2, $cmd);
224 like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created/', "Output correct: ".$result->output ); 229 like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created/', "Output correct: ".$result->output );
225 230
226 $b = 89 + $add;
227 $cmd = "$command -u /statuscode/200 -e 200,201,202"; 231 $cmd = "$command -u /statuscode/200 -e 200,201,202";
228 $result = NPTest->testCmd( $cmd ); 232 $result = NPTest->testCmd( $cmd );
229 is( $result->return_code, 0, $cmd); 233 is( $result->return_code, 0, $cmd);
230 like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); 234 like( $result->output, '/^HTTP OK: Status line output matched "200,201,202" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
231 235
232 $b = 94 + $add;
233 $cmd = "$command -u /statuscode/201 -e 200,201,202"; 236 $cmd = "$command -u /statuscode/201 -e 200,201,202";
234 $result = NPTest->testCmd( $cmd ); 237 $result = NPTest->testCmd( $cmd );
235 is( $result->return_code, 0, $cmd); 238 is( $result->return_code, 0, $cmd);
236 like( $result->output, '/^HTTP OK HTTP/1.1 201 Created - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); 239 like( $result->output, '/^HTTP OK: Status line output matched "200,201,202" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
237 240
238 $cmd = "$command -u /statuscode/203 -e 200,201,202"; 241 $cmd = "$command -u /statuscode/203 -e 200,201,202";
239 $result = NPTest->testCmd( $cmd ); 242 $result = NPTest->testCmd( $cmd );
240 is( $result->return_code, 2, $cmd); 243 is( $result->return_code, 2, $cmd);
241 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 ); 244 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 );
242 245
243 $b = 19 + $add;
244 $cmd = "$command -j HEAD -u /method"; 246 $cmd = "$command -j HEAD -u /method";
245 $result = NPTest->testCmd( $cmd ); 247 $result = NPTest->testCmd( $cmd );
246 is( $result->return_code, 0, $cmd); 248 is( $result->return_code, 0, $cmd);
247 like( $result->output, '/^HTTP OK HTTP/1.1 200 HEAD - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); 249 like( $result->output, '/^HTTP OK: HTTP/1.1 200 HEAD - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
248 250
249 $b = 19 + $add;
250 $cmd = "$command -j POST -u /method"; 251 $cmd = "$command -j POST -u /method";
251 $result = NPTest->testCmd( $cmd ); 252 $result = NPTest->testCmd( $cmd );
252 is( $result->return_code, 0, $cmd); 253 is( $result->return_code, 0, $cmd);
253 like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); 254 like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
254 255
255 $b = 18 + $add;
256 $cmd = "$command -j GET -u /method"; 256 $cmd = "$command -j GET -u /method";
257 $result = NPTest->testCmd( $cmd ); 257 $result = NPTest->testCmd( $cmd );
258 is( $result->return_code, 0, $cmd); 258 is( $result->return_code, 0, $cmd);
259 like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); 259 like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
260 260
261 $b = 18 + $add;
262 $cmd = "$command -u /method"; 261 $cmd = "$command -u /method";
263 $result = NPTest->testCmd( $cmd ); 262 $result = NPTest->testCmd( $cmd );
264 is( $result->return_code, 0, $cmd); 263 is( $result->return_code, 0, $cmd);
265 like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); 264 like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
266 265
267 $b = 19 + $add;
268 $cmd = "$command -P foo -u /method"; 266 $cmd = "$command -P foo -u /method";
269 $result = NPTest->testCmd( $cmd ); 267 $result = NPTest->testCmd( $cmd );
270 is( $result->return_code, 0, $cmd); 268 is( $result->return_code, 0, $cmd);
271 like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); 269 like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
272 270
273 $cmd = "$command -j DELETE -u /method"; 271 $cmd = "$command -j DELETE -u /method";
274 $result = NPTest->testCmd( $cmd ); 272 $result = NPTest->testCmd( $cmd );
@@ -283,39 +281,38 @@ sub run_common_tests {
283 $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude"; 281 $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude";
284 $result = NPTest->testCmd( $cmd ); 282 $result = NPTest->testCmd( $cmd );
285 is( $result->return_code, 0, $cmd); 283 is( $result->return_code, 0, $cmd);
286 like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); 284 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
287 285
288 $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude"; 286 $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude";
289 $result = NPTest->testCmd( $cmd ); 287 $result = NPTest->testCmd( $cmd );
290 is( $result->return_code, 0, $cmd); 288 is( $result->return_code, 0, $cmd);
291 like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); 289 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
292 290
293 # To confirm that the free doesn't segfault 291 # To confirm that the free doesn't segfault
294 $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude"; 292 $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude";
295 $result = NPTest->testCmd( $cmd ); 293 $result = NPTest->testCmd( $cmd );
296 is( $result->return_code, 0, $cmd); 294 is( $result->return_code, 0, $cmd);
297 like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); 295 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
298 296
299 $cmd = "$command -u /redirect"; 297 $cmd = "$command -u /redirect";
300 $result = NPTest->testCmd( $cmd ); 298 $result = NPTest->testCmd( $cmd );
301 is( $result->return_code, 0, $cmd); 299 is( $result->return_code, 0, $cmd);
302 like( $result->output, '/^HTTP OK - HTTP/1.1 301 Moved Permanently - [\d\.]+ second/', "Output correct: ".$result->output ); 300 like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
303 301
304 $b = 183 + $add;
305 $cmd = "$command -f follow -u /redirect"; 302 $cmd = "$command -f follow -u /redirect";
306 $result = NPTest->testCmd( $cmd ); 303 $result = NPTest->testCmd( $cmd );
307 is( $result->return_code, 0, $cmd); 304 is( $result->return_code, 0, $cmd);
308 like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - '.$b.' bytes in [\d\.]+ second/', "Output correct: ".$result->output ); 305 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
306
309 307
310 $cmd = "$command -u /redirect -k 'follow: me'"; 308 $cmd = "$command -u /redirect -k 'follow: me'";
311 $result = NPTest->testCmd( $cmd ); 309 $result = NPTest->testCmd( $cmd );
312 is( $result->return_code, 0, $cmd); 310 is( $result->return_code, 0, $cmd);
313 like( $result->output, '/^HTTP OK - HTTP/1.1 301 Moved Permanently - [\d\.]+ second/', "Output correct: ".$result->output ); 311 like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
314 312
315 $b = 183 + $add;
316 $cmd = "$command -f follow -u /redirect -k 'follow: me'"; 313 $cmd = "$command -f follow -u /redirect -k 'follow: me'";
317 $result = NPTest->testCmd( $cmd ); 314 $result = NPTest->testCmd( $cmd );
318 is( $result->return_code, 0, $cmd); 315 is( $result->return_code, 0, $cmd);
319 like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - '.$b.' bytes in [\d\.]+ second/', "Output correct: ".$result->output ); 316 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
320 317
321} 318}