Skip to content

Commit ffaed48

Browse files
defanatorzimmerle
authored andcommitted
Add test for response body
1 parent 59a9871 commit ffaed48

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

tests/modsecurity-response-body.t

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/perl
2+
3+
# (C) Andrei Belov
4+
5+
# Tests for ModSecurity-nginx connector (response body operations).
6+
7+
###############################################################################
8+
9+
use warnings;
10+
use strict;
11+
12+
use Test::More;
13+
14+
BEGIN { use FindBin; chdir($FindBin::Bin); }
15+
16+
use lib 'lib';
17+
use Test::Nginx;
18+
19+
###############################################################################
20+
21+
select STDERR; $| = 1;
22+
select STDOUT; $| = 1;
23+
24+
my $t = Test::Nginx->new()->has(qw/http/);
25+
26+
$t->write_file_expand('nginx.conf', <<'EOF');
27+
28+
%%TEST_GLOBALS%%
29+
30+
daemon off;
31+
32+
events {
33+
}
34+
35+
http {
36+
%%TEST_GLOBALS_HTTP%%
37+
38+
server {
39+
listen 127.0.0.1:8080;
40+
server_name localhost;
41+
42+
modsecurity on;
43+
44+
location /body1 {
45+
default_type text/plain;
46+
modsecurity_rules '
47+
SecRuleEngine On
48+
SecResponseBodyAccess On
49+
SecResponseBodyLimit 128
50+
SecRule RESPONSE_BODY "@rx BAD BODY" "id:11,phase:response,deny,log,status:403"
51+
';
52+
}
53+
}
54+
}
55+
EOF
56+
57+
$t->write_file("/body1", "BAD BODY");
58+
$t->run();
59+
$t->todo_alerts();
60+
$t->plan(1);
61+
62+
###############################################################################
63+
64+
TODO: {
65+
local $TODO = 'not yet';
66+
67+
like(http_get('/body1'), qr/403 Forbidden/, 'response body (block)');
68+
}
69+

0 commit comments

Comments
 (0)