diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/tests/certs/server-cert.pem | 21 | ||||
-rw-r--r-- | plugins/tests/certs/server-key.pem | 15 | ||||
-rwxr-xr-x | plugins/tests/check_http.t | 322 |
3 files changed, 230 insertions, 128 deletions
diff --git a/plugins/tests/certs/server-cert.pem b/plugins/tests/certs/server-cert.pem new file mode 100644 index 0000000..549e4f7 --- /dev/null +++ b/plugins/tests/certs/server-cert.pem | |||
@@ -0,0 +1,21 @@ | |||
1 | -----BEGIN CERTIFICATE----- | ||
2 | MIIDYzCCAsygAwIBAgIJAL8LkpNwzYdxMA0GCSqGSIb3DQEBBAUAMH8xCzAJBgNV | ||
3 | BAYTAlVLMRMwEQYDVQQIEwpEZXJieXNoaXJlMQ8wDQYDVQQHEwZCZWxwZXIxFzAV | ||
4 | BgNVBAoTDk5hZ2lvcyBQbHVnaW5zMREwDwYDVQQDEwhUb24gVm9vbjEeMBwGCSqG | ||
5 | SIb3DQEJARYPdG9udm9vbkBtYWMuY29tMB4XDTA5MDMwNTIxNDEyOFoXDTE5MDMw | ||
6 | MzIxNDEyOFowfzELMAkGA1UEBhMCVUsxEzARBgNVBAgTCkRlcmJ5c2hpcmUxDzAN | ||
7 | BgNVBAcTBkJlbHBlcjEXMBUGA1UEChMOTmFnaW9zIFBsdWdpbnMxETAPBgNVBAMT | ||
8 | CFRvbiBWb29uMR4wHAYJKoZIhvcNAQkBFg90b252b29uQG1hYy5jb20wgZ8wDQYJ | ||
9 | KoZIhvcNAQEBBQADgY0AMIGJAoGBAKcWMBtNtfY8vZXk0SN6/EYTVN/LOvaOSegy | ||
10 | oVdLoGwuwjagk+XmCzvCqHZRp8lnCLay7AO8AQI7TSN02ihCcSrgGA9OT+HciIJ1 | ||
11 | l5/kEYUAuA1PR6YKK/T713zUAlMzy2tsugx5+xSsSEwsXkmne52jJiG/wuE5CLT0 | ||
12 | 9pF8HQqHAgMBAAGjgeYwgeMwHQYDVR0OBBYEFGioSPQ/rdE19+zaeY2YvHTXlUDI | ||
13 | MIGzBgNVHSMEgaswgaiAFGioSPQ/rdE19+zaeY2YvHTXlUDIoYGEpIGBMH8xCzAJ | ||
14 | BgNVBAYTAlVLMRMwEQYDVQQIEwpEZXJieXNoaXJlMQ8wDQYDVQQHEwZCZWxwZXIx | ||
15 | FzAVBgNVBAoTDk5hZ2lvcyBQbHVnaW5zMREwDwYDVQQDEwhUb24gVm9vbjEeMBwG | ||
16 | CSqGSIb3DQEJARYPdG9udm9vbkBtYWMuY29tggkAvwuSk3DNh3EwDAYDVR0TBAUw | ||
17 | AwEB/zANBgkqhkiG9w0BAQQFAAOBgQCdqasaIO6JiV5ONFG6Tr1++85UfEdZKMUX | ||
18 | N2NHiNNUunolIZEYR+dW99ezKmHlDiQ/tMgoLVYpl2Ubho2pAkLGQR+W0ZASgWQ1 | ||
19 | NjfV27Rv0y6lYQMTA0lVAU93L1x9reo3FMedmL5+H+lIEpLCxEPtAJNISrJOneZB | ||
20 | W5jDadwkoQ== | ||
21 | -----END CERTIFICATE----- | ||
diff --git a/plugins/tests/certs/server-key.pem b/plugins/tests/certs/server-key.pem new file mode 100644 index 0000000..eacaeaa --- /dev/null +++ b/plugins/tests/certs/server-key.pem | |||
@@ -0,0 +1,15 @@ | |||
1 | -----BEGIN RSA PRIVATE KEY----- | ||
2 | MIICWwIBAAKBgQCnFjAbTbX2PL2V5NEjevxGE1Tfyzr2jknoMqFXS6BsLsI2oJPl | ||
3 | 5gs7wqh2UafJZwi2suwDvAECO00jdNooQnEq4BgPTk/h3IiCdZef5BGFALgNT0em | ||
4 | Civ0+9d81AJTM8trbLoMefsUrEhMLF5Jp3udoyYhv8LhOQi09PaRfB0KhwIDAQAB | ||
5 | AoGAfpxclcP8N3vteXErXURrd7pcXT0GECDgNjhvc9PV20RPXM+vYs1AA+fMeeQE | ||
6 | TaRqwO6x016aMRO4rz5ztYArecTBznkds1k59pkN/Ne/nsueU4tvGK8MNyS2o986 | ||
7 | Voohqkaq4Lcy1bcHJb9su1ELjegEr1R76Mz452Hsy+uTbAECQQDcg/tZWKVeh5CQ | ||
8 | dOEB3YWHwfn0NDgfPm/X2i2kAZ7n7URaUy/ffdlfsrr1mBtHCfedLoOxmmlNfEpM | ||
9 | hXAAurSHAkEAwfk7fEb0iN0Sj9gTozO7c6Ky10KwePZyjVzqSQIiJq3NX8BEaIeb | ||
10 | 51TXxE5VxaLjjMLRkA0hWTYXClgERFZ6AQJAN7ChPqwzf08PRFwwIw911JY5cOHr | ||
11 | NoDHMCUql5vNLNdwBruxgGjBB/kUXEfgw60RusFvgt/zLh1wiii844JDawJAGQBF | ||
12 | sYP3urg7zzx7c3qUe5gJ0wLuefjR1PSX4ecbfb7DDMdcSdjIuG1QDiZGmd2f1KG7 | ||
13 | nwSCOtxk5dloW2KGAQJAQh/iBn0QhfKLFAP5eZBVk8E8XlZuw+S2DLy5SnBlIiYJ | ||
14 | GB5I2OClgtudXMv1labFrcST8O9eFrtsrhU1iUGUOw== | ||
15 | -----END RSA PRIVATE KEY----- | ||
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index c5f9080..20078c2 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -12,26 +12,59 @@ use HTTP::Daemon; | |||
12 | use HTTP::Status; | 12 | use HTTP::Status; |
13 | use HTTP::Response; | 13 | use HTTP::Response; |
14 | 14 | ||
15 | my $servers = { http => 0 }; # HTTP::Daemon should always be available | ||
16 | eval { require HTTP::Daemon::SSL }; | ||
17 | if ($@) { | ||
18 | diag "Cannot load HTTP::Daemon::SSL: $@"; | ||
19 | } else { | ||
20 | $servers->{https} = 0; | ||
21 | } | ||
22 | |||
15 | # set a fixed version, so the header size doesn't vary | 23 | # set a fixed version, so the header size doesn't vary |
16 | $HTTP::Daemon::VERSION = "1.00"; | 24 | $HTTP::Daemon::VERSION = "1.00"; |
17 | 25 | ||
18 | my $port = 50000 + int(rand(1000)); | 26 | my $port_http = 50000 + int(rand(1000)); |
27 | my $port_https = $port_http + 1; | ||
19 | 28 | ||
20 | my $pid = fork(); | 29 | # Start up both servers |
21 | if ($pid) { | 30 | my $pid_https; |
31 | my $pid_http = fork(); | ||
32 | if ($pid_http) { | ||
22 | # Parent | 33 | # Parent |
23 | #print "parent\n"; | 34 | if (exists $servers->{https}) { |
24 | # give our webserver some time to startup | 35 | # Fork another server |
36 | $pid_https = fork(); | ||
37 | if ($pid_https) { | ||
38 | # Parent | ||
39 | } else { | ||
40 | my $d = HTTP::Daemon::SSL->new( | ||
41 | LocalPort => $port_https, | ||
42 | LocalAddr => "127.0.0.1", | ||
43 | SSL_cert_file => "$Bin/certs/server-cert.pem", | ||
44 | SSL_key_file => "$Bin/certs/server-key.pem", | ||
45 | ) || die; | ||
46 | print "Please contact https at: <URL:", $d->url, ">\n"; | ||
47 | run_server( $d ); | ||
48 | exit; | ||
49 | } | ||
50 | } | ||
51 | # give our webservers some time to startup | ||
25 | sleep(1); | 52 | sleep(1); |
26 | } else { | 53 | } else { |
27 | # Child | 54 | # Child |
28 | #print "child\n"; | 55 | #print "child\n"; |
29 | |||
30 | my $d = HTTP::Daemon->new( | 56 | my $d = HTTP::Daemon->new( |
31 | LocalPort => $port, | 57 | LocalPort => $port_http, |
32 | LocalAddr => "127.0.0.1", | 58 | LocalAddr => "127.0.0.1", |
33 | ) || die; | 59 | ) || die; |
34 | print "Please contact me at: <URL:", $d->url, ">\n"; | 60 | print "Please contact http at: <URL:", $d->url, ">\n"; |
61 | run_server( $d ); | ||
62 | exit; | ||
63 | } | ||
64 | |||
65 | # Run the same server on http and https | ||
66 | sub run_server { | ||
67 | my $d = shift; | ||
35 | while (my $c = $d->accept ) { | 68 | while (my $c = $d->accept ) { |
36 | while (my $r = $c->get_request) { | 69 | while (my $r = $c->get_request) { |
37 | if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) { | 70 | if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) { |
@@ -70,140 +103,173 @@ if ($pid) { | |||
70 | $c->close; | 103 | $c->close; |
71 | } | 104 | } |
72 | } | 105 | } |
73 | exit; | ||
74 | } | 106 | } |
75 | 107 | ||
76 | END { if ($pid) { print "Killing $pid\n"; kill "INT", $pid } }; | 108 | END { |
109 | foreach my $pid ($pid_http, $pid_https) { | ||
110 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } | ||
111 | } | ||
112 | }; | ||
77 | 113 | ||
78 | if ($ARGV[0] && $ARGV[0] eq "-d") { | 114 | if ($ARGV[0] && $ARGV[0] eq "-d") { |
79 | sleep 1000; | 115 | sleep 1000; |
80 | } | 116 | } |
81 | 117 | ||
118 | my $common_tests = 47; | ||
82 | if (-x "./check_http") { | 119 | if (-x "./check_http") { |
83 | plan tests => 47; | 120 | plan tests => $common_tests * 2; |
84 | } else { | 121 | } else { |
85 | plan skip_all => "No check_http compiled"; | 122 | plan skip_all => "No check_http compiled"; |
86 | } | 123 | } |
87 | 124 | ||
88 | my $result; | 125 | my $result; |
89 | my $command = "./check_http -H 127.0.0.1 -p $port"; | 126 | my $command = "./check_http -H 127.0.0.1"; |
90 | |||
91 | $result = NPTest->testCmd( "$command -u /file/root" ); | ||
92 | is( $result->return_code, 0, "/file/root"); | ||
93 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 274 bytes in [\d\.]+ seconds/', "Output correct" ); | ||
94 | 127 | ||
95 | $result = NPTest->testCmd( "$command -u /file/root -s Root" ); | 128 | run_common_tests( { command => "$command -p $port_http" } ); |
96 | is( $result->return_code, 0, "/file/root search for string"); | 129 | SKIP: { |
97 | TODO: { | 130 | skip "HTTP::Daemon::SSL not installed", $common_tests if ! exists $servers->{https}; |
98 | local $TODO = "Output is different if a string is requested - should this be right?"; | 131 | run_common_tests( { command => "$command -p $port_https", ssl => 1 } ); |
99 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 274 bytes in [\d\.]+ seconds/', "Output correct" ); | ||
100 | } | 132 | } |
101 | 133 | ||
102 | $result = NPTest->testCmd( "$command -u /slow" ); | 134 | sub run_common_tests { |
103 | is( $result->return_code, 0, "/file/root"); | 135 | my ($opts) = @_; |
104 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 177 bytes in ([\d\.]+) seconds/', "Output correct" ); | 136 | my $command = $opts->{command}; |
105 | $result->output =~ /in ([\d\.]+) seconds/; | 137 | my $b; |
106 | cmp_ok( $1, ">", 1, "Time is > 1 second" ); | 138 | my $add = 0; |
107 | 139 | if ($opts->{ssl}) { | |
108 | my $cmd; | 140 | $command .= " --ssl"; |
109 | $cmd = "$command -u /statuscode/200 -e 200"; | 141 | } |
110 | $result = NPTest->testCmd( $cmd ); | ||
111 | is( $result->return_code, 0, $cmd); | ||
112 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 89 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
113 | |||
114 | $cmd = "$command -u /statuscode/201 -e 201"; | ||
115 | $result = NPTest->testCmd( $cmd ); | ||
116 | is( $result->return_code, 0, $cmd); | ||
117 | like( $result->output, '/^HTTP OK HTTP/1.1 201 Created - 94 bytes in ([\d\.]+) seconds /', "Output correct: ".$result->output ); | ||
118 | |||
119 | $cmd = "$command -u /statuscode/201 -e 200"; | ||
120 | $result = NPTest->testCmd( $cmd ); | ||
121 | is( $result->return_code, 2, $cmd); | ||
122 | like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created/', "Output correct: ".$result->output ); | ||
123 | |||
124 | $cmd = "$command -u /statuscode/200 -e 200,201,202"; | ||
125 | $result = NPTest->testCmd( $cmd ); | ||
126 | is( $result->return_code, 0, $cmd); | ||
127 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 89 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
128 | |||
129 | $cmd = "$command -u /statuscode/201 -e 200,201,202"; | ||
130 | $result = NPTest->testCmd( $cmd ); | ||
131 | is( $result->return_code, 0, $cmd); | ||
132 | like( $result->output, '/^HTTP OK HTTP/1.1 201 Created - 94 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
133 | |||
134 | $cmd = "$command -u /statuscode/203 -e 200,201,202"; | ||
135 | $result = NPTest->testCmd( $cmd ); | ||
136 | is( $result->return_code, 2, $cmd); | ||
137 | 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 ); | ||
138 | |||
139 | $cmd = "$command -j HEAD -u /method"; | ||
140 | $result = NPTest->testCmd( $cmd ); | ||
141 | is( $result->return_code, 0, $cmd); | ||
142 | like( $result->output, '/^HTTP OK HTTP/1.1 200 HEAD - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
143 | |||
144 | $cmd = "$command -j POST -u /method"; | ||
145 | $result = NPTest->testCmd( $cmd ); | ||
146 | is( $result->return_code, 0, $cmd); | ||
147 | like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
148 | |||
149 | $cmd = "$command -j GET -u /method"; | ||
150 | $result = NPTest->testCmd( $cmd ); | ||
151 | is( $result->return_code, 0, $cmd); | ||
152 | like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - 18 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
153 | |||
154 | $cmd = "$command -u /method"; | ||
155 | $result = NPTest->testCmd( $cmd ); | ||
156 | is( $result->return_code, 0, $cmd); | ||
157 | like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - 18 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
158 | |||
159 | $cmd = "$command -P foo -u /method"; | ||
160 | $result = NPTest->testCmd( $cmd ); | ||
161 | is( $result->return_code, 0, $cmd); | ||
162 | like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
163 | |||
164 | $cmd = "$command -j DELETE -u /method"; | ||
165 | $result = NPTest->testCmd( $cmd ); | ||
166 | is( $result->return_code, 1, $cmd); | ||
167 | like( $result->output, '/^HTTP WARNING: HTTP/1.1 405 Method Not Allowed/', "Output correct: ".$result->output ); | ||
168 | |||
169 | $cmd = "$command -j foo -u /method"; | ||
170 | $result = NPTest->testCmd( $cmd ); | ||
171 | is( $result->return_code, 2, $cmd); | ||
172 | like( $result->output, '/^HTTP CRITICAL: HTTP/1.1 501 Not Implemented/', "Output correct: ".$result->output ); | ||
173 | |||
174 | $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude"; | ||
175 | $result = NPTest->testCmd( $cmd ); | ||
176 | is( $result->return_code, 0, $cmd); | ||
177 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); | ||
178 | |||
179 | $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude"; | ||
180 | $result = NPTest->testCmd( $cmd ); | ||
181 | is( $result->return_code, 0, $cmd); | ||
182 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); | ||
183 | |||
184 | # To confirm that the free doesn't segfault | ||
185 | $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude"; | ||
186 | $result = NPTest->testCmd( $cmd ); | ||
187 | is( $result->return_code, 0, $cmd); | ||
188 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); | ||
189 | |||
190 | $cmd = "$command -u /redirect"; | ||
191 | $result = NPTest->testCmd( $cmd ); | ||
192 | is( $result->return_code, 0, $cmd); | ||
193 | like( $result->output, '/^HTTP OK - HTTP/1.1 301 Moved Permanently - [\d\.]+ second/', "Output correct: ".$result->output ); | ||
194 | |||
195 | $cmd = "$command -f follow -u /redirect"; | ||
196 | $result = NPTest->testCmd( $cmd ); | ||
197 | is( $result->return_code, 0, $cmd); | ||
198 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 183 bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
199 | |||
200 | $cmd = "$command -u /redirect -k 'follow: me'"; | ||
201 | $result = NPTest->testCmd( $cmd ); | ||
202 | is( $result->return_code, 0, $cmd); | ||
203 | like( $result->output, '/^HTTP OK - HTTP/1.1 301 Moved Permanently - [\d\.]+ second/', "Output correct: ".$result->output ); | ||
204 | |||
205 | $cmd = "$command -f follow -u /redirect -k 'follow: me'"; | ||
206 | $result = NPTest->testCmd( $cmd ); | ||
207 | is( $result->return_code, 0, $cmd); | ||
208 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 183 bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
209 | 142 | ||
143 | $result = NPTest->testCmd( "$command -u /file/root" ); | ||
144 | is( $result->return_code, 0, "/file/root"); | ||
145 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 274 bytes in [\d\.]+ seconds/', "Output correct" ); | ||
146 | |||
147 | $result = NPTest->testCmd( "$command -u /file/root -s Root" ); | ||
148 | is( $result->return_code, 0, "/file/root search for string"); | ||
149 | TODO: { | ||
150 | local $TODO = "Output is different if a string is requested - should this be right?"; | ||
151 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 274 bytes in [\d\.]+ seconds/', "Output correct" ); | ||
152 | } | ||
153 | |||
154 | |||
155 | $b = 177 + $add; | ||
156 | $result = NPTest->testCmd( "$command -u /slow" ); | ||
157 | is( $result->return_code, 0, "/file/root"); | ||
158 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct" ); | ||
159 | $result->output =~ /in ([\d\.]+) seconds/; | ||
160 | cmp_ok( $1, ">", 1, "Time is > 1 second" ); | ||
161 | |||
162 | my $cmd; | ||
163 | $b = 89 + $add; | ||
164 | $cmd = "$command -u /statuscode/200 -e 200"; | ||
165 | $result = NPTest->testCmd( $cmd ); | ||
166 | is( $result->return_code, 0, $cmd); | ||
167 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
168 | |||
169 | $b = 94 + $add; | ||
170 | $cmd = "$command -u /statuscode/201 -e 201"; | ||
171 | $result = NPTest->testCmd( $cmd ); | ||
172 | is( $result->return_code, 0, $cmd); | ||
173 | like( $result->output, '/^HTTP OK HTTP/1.1 201 Created - '.$b.' bytes in ([\d\.]+) seconds /', "Output correct: ".$result->output ); | ||
174 | |||
175 | $cmd = "$command -u /statuscode/201 -e 200"; | ||
176 | $result = NPTest->testCmd( $cmd ); | ||
177 | is( $result->return_code, 2, $cmd); | ||
178 | like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created/', "Output correct: ".$result->output ); | ||
179 | |||
180 | $b = 89 + $add; | ||
181 | $cmd = "$command -u /statuscode/200 -e 200,201,202"; | ||
182 | $result = NPTest->testCmd( $cmd ); | ||
183 | is( $result->return_code, 0, $cmd); | ||
184 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
185 | |||
186 | $b = 94 + $add; | ||
187 | $cmd = "$command -u /statuscode/201 -e 200,201,202"; | ||
188 | $result = NPTest->testCmd( $cmd ); | ||
189 | is( $result->return_code, 0, $cmd); | ||
190 | like( $result->output, '/^HTTP OK HTTP/1.1 201 Created - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
191 | |||
192 | $cmd = "$command -u /statuscode/203 -e 200,201,202"; | ||
193 | $result = NPTest->testCmd( $cmd ); | ||
194 | is( $result->return_code, 2, $cmd); | ||
195 | 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 ); | ||
196 | |||
197 | $b = 19 + $add; | ||
198 | $cmd = "$command -j HEAD -u /method"; | ||
199 | $result = NPTest->testCmd( $cmd ); | ||
200 | is( $result->return_code, 0, $cmd); | ||
201 | like( $result->output, '/^HTTP OK HTTP/1.1 200 HEAD - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
202 | |||
203 | $b = 19 + $add; | ||
204 | $cmd = "$command -j POST -u /method"; | ||
205 | $result = NPTest->testCmd( $cmd ); | ||
206 | is( $result->return_code, 0, $cmd); | ||
207 | like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
208 | |||
209 | $b = 18 + $add; | ||
210 | $cmd = "$command -j GET -u /method"; | ||
211 | $result = NPTest->testCmd( $cmd ); | ||
212 | is( $result->return_code, 0, $cmd); | ||
213 | like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
214 | |||
215 | $b = 18 + $add; | ||
216 | $cmd = "$command -u /method"; | ||
217 | $result = NPTest->testCmd( $cmd ); | ||
218 | is( $result->return_code, 0, $cmd); | ||
219 | like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
220 | |||
221 | $b = 19 + $add; | ||
222 | $cmd = "$command -P foo -u /method"; | ||
223 | $result = NPTest->testCmd( $cmd ); | ||
224 | is( $result->return_code, 0, $cmd); | ||
225 | like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - '.$b.' bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
226 | |||
227 | $cmd = "$command -j DELETE -u /method"; | ||
228 | $result = NPTest->testCmd( $cmd ); | ||
229 | is( $result->return_code, 1, $cmd); | ||
230 | like( $result->output, '/^HTTP WARNING: HTTP/1.1 405 Method Not Allowed/', "Output correct: ".$result->output ); | ||
231 | |||
232 | $cmd = "$command -j foo -u /method"; | ||
233 | $result = NPTest->testCmd( $cmd ); | ||
234 | is( $result->return_code, 2, $cmd); | ||
235 | like( $result->output, '/^HTTP CRITICAL: HTTP/1.1 501 Not Implemented/', "Output correct: ".$result->output ); | ||
236 | |||
237 | $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude"; | ||
238 | $result = NPTest->testCmd( $cmd ); | ||
239 | is( $result->return_code, 0, $cmd); | ||
240 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); | ||
241 | |||
242 | $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude"; | ||
243 | $result = NPTest->testCmd( $cmd ); | ||
244 | is( $result->return_code, 0, $cmd); | ||
245 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); | ||
246 | |||
247 | # To confirm that the free doesn't segfault | ||
248 | $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude"; | ||
249 | $result = NPTest->testCmd( $cmd ); | ||
250 | is( $result->return_code, 0, $cmd); | ||
251 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output ); | ||
252 | |||
253 | $cmd = "$command -u /redirect"; | ||
254 | $result = NPTest->testCmd( $cmd ); | ||
255 | is( $result->return_code, 0, $cmd); | ||
256 | like( $result->output, '/^HTTP OK - HTTP/1.1 301 Moved Permanently - [\d\.]+ second/', "Output correct: ".$result->output ); | ||
257 | |||
258 | $b = 183 + $add; | ||
259 | $cmd = "$command -f follow -u /redirect"; | ||
260 | $result = NPTest->testCmd( $cmd ); | ||
261 | is( $result->return_code, 0, $cmd); | ||
262 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - '.$b.' bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
263 | |||
264 | $cmd = "$command -u /redirect -k 'follow: me'"; | ||
265 | $result = NPTest->testCmd( $cmd ); | ||
266 | is( $result->return_code, 0, $cmd); | ||
267 | like( $result->output, '/^HTTP OK - HTTP/1.1 301 Moved Permanently - [\d\.]+ second/', "Output correct: ".$result->output ); | ||
268 | |||
269 | $b = 183 + $add; | ||
270 | $cmd = "$command -f follow -u /redirect -k 'follow: me'"; | ||
271 | $result = NPTest->testCmd( $cmd ); | ||
272 | is( $result->return_code, 0, $cmd); | ||
273 | like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - '.$b.' bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
274 | |||
275 | } | ||