Skip to content

Commit 539eaa7

Browse files
defanatorFelipe Zimmerle
authored and
Felipe Zimmerle
committed
Tests: extend request body tests with case for issue owasp-modsecurity#142
While here, adjusted request body tests for flawless parallel execution.
1 parent 5fb6fa0 commit 539eaa7

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

Diff for: tests/modsecurity-request-body.t

+35-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use Test::Nginx;
2222
select STDERR; $| = 1;
2323
select STDOUT; $| = 1;
2424

25-
my $t = Test::Nginx->new()->has(qw/http auth_request/);
25+
my $t = Test::Nginx->new()->has(qw/http proxy auth_request/);
2626

2727
$t->write_file_expand('nginx.conf', <<'EOF');
2828
@@ -49,7 +49,7 @@ http {
4949
SecRequestBodyAccess On
5050
SecRule REQUEST_BODY "@rx BAD BODY" "id:11,phase:request,deny,log,status:403"
5151
';
52-
proxy_pass http://127.0.0.1:8081;
52+
proxy_pass http://127.0.0.1:%%PORT_8081%%;
5353
}
5454
5555
location /nobodyaccess {
@@ -59,7 +59,7 @@ http {
5959
SecRule REQUEST_BODY "@rx BAD BODY" "id:21,phase:request,deny,log,status:403"
6060
SecRule ARGS_POST|ARGS_POST_NAMES "@rx BAD ARG" "id:22,phase:request,deny,log,status:403"
6161
';
62-
proxy_pass http://127.0.0.1:8081;
62+
proxy_pass http://127.0.0.1:%%PORT_8081%%;
6363
}
6464
6565
location /bodylimitreject {
@@ -70,7 +70,12 @@ http {
7070
SecRequestBodyLimitAction Reject
7171
SecRule REQUEST_BODY "@rx BAD BODY" "id:31,phase:request,deny,log,status:403"
7272
';
73-
proxy_pass http://127.0.0.1:8081;
73+
proxy_pass http://127.0.0.1:%%PORT_8081%%;
74+
}
75+
76+
location /bodylimitrejectserver {
77+
modsecurity off;
78+
proxy_pass http://127.0.0.1:%%PORT_8082%%;
7479
}
7580
7681
location /bodylimitprocesspartial {
@@ -81,7 +86,7 @@ http {
8186
SecRequestBodyLimitAction ProcessPartial
8287
SecRule REQUEST_BODY "@rx BAD BODY" "id:41,phase:request,deny,log,status:403"
8388
';
84-
proxy_pass http://127.0.0.1:8081;
89+
proxy_pass http://127.0.0.1:%%PORT_8081%%;
8590
}
8691
8792
location = /auth {
@@ -95,7 +100,22 @@ http {
95100
SecRequestBodyAccess On
96101
';
97102
auth_request /auth;
98-
proxy_pass http://127.0.0.1:8081;
103+
proxy_pass http://127.0.0.1:%%PORT_8081%%;
104+
}
105+
}
106+
107+
server {
108+
listen 127.0.0.1:%%PORT_8082%%;
109+
modsecurity on;
110+
modsecurity_rules '
111+
SecRuleEngine On
112+
SecRequestBodyAccess On
113+
SecRequestBodyLimit 128
114+
SecRequestBodyLimitAction Reject
115+
SecRule REQUEST_BODY "@rx BAD BODY" "id:31,phase:request,deny,log,status:403"
116+
';
117+
location / {
118+
proxy_pass http://127.0.0.1:%%PORT_8081%%;
99119
}
100120
}
101121
}
@@ -104,7 +124,7 @@ EOF
104124
$t->run_daemon(\&http_daemon);
105125
$t->run()->waitforsocket('127.0.0.1:' . port(8081));
106126

107-
$t->plan(36);
127+
$t->plan(40);
108128

109129
###############################################################################
110130

@@ -146,6 +166,14 @@ like(
146166
'POST with auth_request (request size < client_header_buffer_size), no preread'
147167
);
148168

169+
TODO: {
170+
local $TODO = 'not yet';
171+
172+
foreach my $method (('GET', 'POST', 'PUT', 'DELETE')) {
173+
like(http_req_body($method, '/bodylimitrejectserver', 'BODY' x 33), qr/403 Forbidden/, "$method request body limit reject, block (inherited SecRequestBodyLimit)");
174+
}
175+
}
176+
149177
###############################################################################
150178

151179
sub http_daemon {

0 commit comments

Comments
 (0)