Skip to content

Commit 6a69a4b

Browse files
committed
Try modsecurity-limits.t test
1 parent fd28e6a commit 6a69a4b

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

tests/modsecurity-limits.t

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/perl
2+
3+
# (C) Test for ModSecurity-nginx connector (limit_req ordering).
4+
5+
###############################################################################
6+
7+
use warnings;
8+
use strict;
9+
10+
use Test::More;
11+
12+
BEGIN { use FindBin; chdir($FindBin::Bin); }
13+
14+
use lib 'lib';
15+
use Test::Nginx;
16+
17+
###############################################################################
18+
19+
select STDERR; $| = 1;
20+
select STDOUT; $| = 1;
21+
22+
my $t = Test::Nginx->new()->has(qw/http/);
23+
24+
$t->write_file_expand('nginx.conf', <<'EOF');
25+
26+
%%TEST_GLOBALS%%
27+
28+
daemon off;
29+
30+
events {
31+
}
32+
33+
http {
34+
%%TEST_GLOBALS_HTTP%%
35+
36+
limit_req_zone $binary_remote_addr zone=limitzone:10m rate=2r/s;
37+
limit_req_status 429;
38+
39+
server {
40+
listen 127.0.0.1:8080;
41+
server_name localhost;
42+
43+
modsecurity on;
44+
limit_req zone=limitzone burst=1 nodelay;
45+
46+
location /limit {
47+
modsecurity_rules '
48+
SecRuleEngine On
49+
SecRule REQUEST_URI "@rx .*" "id:1001,phase:1,log,deny,status:555,msg:\'Request reached ModSecurity\'"
50+
';
51+
}
52+
}
53+
}
54+
EOF
55+
56+
$t->write_file("/limit", "limit test endpoint");
57+
$t->run();
58+
$t->plan(4);
59+
60+
###############################################################################
61+
62+
my $uri = '/limit';
63+
64+
my $res1 = http_get($uri);
65+
my $res2 = http_get($uri);
66+
my $res3 = http_get($uri);
67+
my $res4 = http_get($uri);
68+
69+
like($res1, qr/^HTTP.*555/, 'limitreq scoring 1 (Blocked by ModSecurity)');
70+
like($res2, qr/^HTTP.*555/, 'limitreq scoring 2 (Blocked by ModSecurity)');
71+
like($res3, qr/^HTTP.*429/, 'limitreq scoring 3 (limited by nginx)');
72+
like($res4, qr/^HTTP.*429/, 'limitreq scoring 4 (limited by nginx)');

0 commit comments

Comments
 (0)