summaryrefslogtreecommitdiffstats
path: root/plugins/tests
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/tests')
-rwxr-xr-xplugins/tests/check_http.t69
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
65if (-x "./check_http") { 75if (-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 );
119is( $result->return_code, 2, $cmd); 129is( $result->return_code, 2, $cmd);
120like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information/', "Output correct: ".$result->output ); 130like( $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 );
134is( $result->return_code, 0, $cmd);
135like( $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 );
139is( $result->return_code, 0, $cmd);
140like( $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 );
144is( $result->return_code, 0, $cmd);
145like( $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 );
149is( $result->return_code, 0, $cmd);
150like( $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 );
154is( $result->return_code, 0, $cmd);
155like( $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 );
159is( $result->return_code, 1, $cmd);
160like( $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 );
164is( $result->return_code, 2, $cmd);
165like( $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 );
169is( $result->return_code, 0, $cmd);
170like( $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 );
174is( $result->return_code, 0, $cmd);
175like( $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 );
180is( $result->return_code, 0, $cmd);
181like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output );
182