Skip to content

Commit 74acb5a

Browse files
defanatorFelipe Zimmerle
authored and
Felipe Zimmerle
committed
tests: update request body test with more RFC2616 methods
1 parent 335c086 commit 74acb5a

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

tests/modsecurity-request-body.t

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,19 @@ EOF
9090
$t->run_daemon(\&http_daemon);
9191
$t->run()->waitforsocket('127.0.0.1:' . port(8081));
9292

93-
$t->plan(7);
93+
$t->plan(28);
9494

9595
###############################################################################
9696

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+
}
104106

105107
###############################################################################
106108

@@ -140,17 +142,18 @@ EOF
140142
}
141143
}
142144

143-
sub http_get_body {
145+
sub http_req_body {
146+
my $method = shift;
144147
my $uri = shift;
145148
my $last = pop;
146149
return http( join '', (map {
147150
my $body = $_;
148-
"GET $uri HTTP/1.1" . CRLF
151+
"$method $uri HTTP/1.1" . CRLF
149152
. "Host: localhost" . CRLF
150153
. "Content-Length: " . (length $body) . CRLF . CRLF
151154
. $body
152155
} @_),
153-
"GET $uri HTTP/1.1" . CRLF
156+
"$method $uri HTTP/1.1" . CRLF
154157
. "Host: localhost" . CRLF
155158
. "Connection: close" . CRLF
156159
. "Content-Length: " . (length $last) . CRLF . CRLF

0 commit comments

Comments
 (0)