|
90 | 90 | $t->run_daemon(\&http_daemon);
|
91 | 91 | $t->run()->waitforsocket('127.0.0.1:' . port(8081));
|
92 | 92 |
|
93 |
| -$t->plan(7); |
| 93 | +$t->plan(28); |
94 | 94 |
|
95 | 95 | ###############################################################################
|
96 | 96 |
|
97 |
| -like(http_get_body('/bodyaccess', 'GOOD BODY'), qr/TEST-OK-IF-YOU-SEE-THIS/, 'request body access on, pass'); |
98 |
| -like(http_get_body('/bodyaccess', 'VERY BAD BODY'), qr/403 Forbidden/, 'request body access on, block'); |
99 |
| -like(http_get_body('/nobodyaccess', 'VERY BAD BODY'), qr/TEST-OK-IF-YOU-SEE-THIS/, 'request body access off, pass'); |
100 |
| -like(http_get_body('/bodylimitreject', 'BODY' x 32), qr/TEST-OK-IF-YOU-SEE-THIS/, 'request body limit reject, pass'); |
101 |
| -like(http_get_body('/bodylimitreject', 'BODY' x 33), qr/403 Forbidden/, 'request body limit reject, block'); |
102 |
| -like(http_get_body('/bodylimitprocesspartial', 'BODY' x 32 . 'BAD BODY'), qr/TEST-OK-IF-YOU-SEE-THIS/, 'request body limit process partial, pass'); |
103 |
| -like(http_get_body('/bodylimitprocesspartial', 'BODY' x 30 . 'BAD BODY' x 32), qr/403 Forbidden/, 'request body limit process partial, block'); |
| 97 | +foreach my $method (('GET', 'POST', 'PUT', 'DELETE')) { |
| 98 | +like(http_req_body($method, '/bodyaccess', 'GOOD BODY'), qr/TEST-OK-IF-YOU-SEE-THIS/, "$method request body access on, pass"); |
| 99 | +like(http_req_body($method, '/bodyaccess', 'VERY BAD BODY'), qr/403 Forbidden/, "$method request body access on, block"); |
| 100 | +like(http_req_body($method, '/nobodyaccess', 'VERY BAD BODY'), qr/TEST-OK-IF-YOU-SEE-THIS/, "$method request body access off, pass"); |
| 101 | +like(http_req_body($method, '/bodylimitreject', 'BODY' x 32), qr/TEST-OK-IF-YOU-SEE-THIS/, "$method request body limit reject, pass"); |
| 102 | +like(http_req_body($method, '/bodylimitreject', 'BODY' x 33), qr/403 Forbidden/, "$method request body limit reject, block"); |
| 103 | +like(http_req_body($method, '/bodylimitprocesspartial', 'BODY' x 32 . 'BAD BODY'), qr/TEST-OK-IF-YOU-SEE-THIS/, "$method request body limit process partial, pass"); |
| 104 | +like(http_req_body($method, '/bodylimitprocesspartial', 'BODY' x 30 . 'BAD BODY' x 32), qr/403 Forbidden/, "$method request body limit process partial, block"); |
| 105 | +} |
104 | 106 |
|
105 | 107 | ###############################################################################
|
106 | 108 |
|
@@ -140,17 +142,18 @@ EOF
|
140 | 142 | }
|
141 | 143 | }
|
142 | 144 |
|
143 |
| -sub http_get_body { |
| 145 | +sub http_req_body { |
| 146 | + my $method = shift; |
144 | 147 | my $uri = shift;
|
145 | 148 | my $last = pop;
|
146 | 149 | return http( join '', (map {
|
147 | 150 | my $body = $_;
|
148 |
| - "GET $uri HTTP/1.1" . CRLF |
| 151 | + "$method $uri HTTP/1.1" . CRLF |
149 | 152 | . "Host: localhost" . CRLF
|
150 | 153 | . "Content-Length: " . (length $body) . CRLF . CRLF
|
151 | 154 | . $body
|
152 | 155 | } @_),
|
153 |
| - "GET $uri HTTP/1.1" . CRLF |
| 156 | + "$method $uri HTTP/1.1" . CRLF |
154 | 157 | . "Host: localhost" . CRLF
|
155 | 158 | . "Connection: close" . CRLF
|
156 | 159 | . "Content-Length: " . (length $last) . CRLF . CRLF
|
|
0 commit comments