Skip to content

Commit 52bef20

Browse files
author
Felipe Zimmerle
committed
Adds unit test to the JSON parser
Unit test to test whenever the JSON parser is enabled
1 parent a95f371 commit 52bef20

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/regression/rule/15-json.t

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
### Test for JSON parser
2+
3+
###
4+
# OK
5+
{
6+
type => "rule",
7+
comment => "json parser",
8+
conf => qq(
9+
SecRuleEngine On
10+
SecRequestBodyAccess On
11+
SecDebugLog $ENV{DEBUG_LOG}
12+
SecDebugLogLevel 9
13+
SecRule REQUEST_HEADERS:Content-Type "application/json" \\
14+
"id:'200001',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON"
15+
SecRule ARGS:foo "bar" "id:'200441',phase:3,log"
16+
),
17+
match_log => {
18+
error => [ qr/ModSecurity: Warning. Pattern match "bar" at ARGS:foo.|ModSecurity: JSON support was not enabled/s, 1 ],
19+
debug => [ qr/Adding JSON argument 'foo' with value 'bar'|JSON support was not enabled/, 1 ],
20+
},
21+
match_response => {
22+
status => qr/^200$/,
23+
},
24+
request => new HTTP::Request(
25+
POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
26+
[
27+
"Content-Type" => "application/json",
28+
],
29+
normalize_raw_request_data(
30+
q(
31+
{
32+
"foo":"bar",
33+
"mod":"sec"
34+
}
35+
),
36+
),
37+
),
38+
}
39+

0 commit comments

Comments
 (0)