Imported Upstream version 2.5.11
[libapache-mod-security.git] / apache2 / t / regression / misc / 10-tfn-cache.t
1 ### Transformation Caching
2
3 {
4         type => "misc",
5         comment => "tfncache (simple fully cached)",
6         conf => qq(
7                 SecRuleEngine On
8                 SecDebugLog $ENV{DEBUG_LOG}
9                 SecDebugLogLevel 9
10
11                 # We need to make this work no matter what the defaults may change to
12                 SecCacheTransformations On "minlen:1,maxlen:0"
13
14                 # This should cache it
15                 SecRule ARGS_GET "WillNotMatch" "phase:1,t:none,t:removeWhiteSpace,t:lowercase,pass,nolog"
16
17                 # This should use the cached value
18                 SecRule ARGS_GET:test "foobar" "phase:1,t:none,t:removeWhiteSpace,t:lowercase,deny"
19         ),
20         match_log => {
21                 debug => [ qr/removeWhiteSpace,lowercase: "foobar" .*cached/, 1 ],
22                 -debug => [ qr/partially cached/, 1 ],
23         },
24         match_response => {
25                 status => qr/^403$/,
26         },
27         request => new HTTP::Request(
28                 GET => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/index.html?test=Foo+Bar",
29         ),
30 },
31 {
32         type => "misc",
33         comment => "tfncache (simple partially cached)",
34         conf => qq(
35                 SecRuleEngine On
36                 SecDebugLog $ENV{DEBUG_LOG}
37                 SecDebugLogLevel 9
38
39                 # We need to make this work no matter what the defaults may change to
40                 SecCacheTransformations On "minlen:1,maxlen:0,incremental:off,maxitems:0"
41
42                 # This should cache it
43                 SecRule ARGS_GET "WillNotMatch" "phase:1,t:none,t:removeWhiteSpace,pass,nolog"
44
45                 # This should use the partially cached value
46                 SecRule ARGS_GET:test "foobar" "phase:1,t:none,t:removeWhiteSpace,t:lowercase,deny"
47         ),
48         match_log => {
49                 debug => [ qr/removeWhiteSpace: "FooBar" .*partially cached/, 1 ],
50         },
51         match_response => {
52                 status => qr/^403$/,
53         },
54         request => new HTTP::Request(
55                 GET => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/index.html?test=Foo+Bar",
56         ),
57 },
58 {
59         type => "misc",
60         comment => "tfncache (separate phases)",
61         conf => qq(
62                 SecRuleEngine On
63                 SecDebugLog $ENV{DEBUG_LOG}
64                 SecDebugLogLevel 9
65
66                 # We need to make this work no matter what the defaults may change to
67                 SecCacheTransformations On "minlen:1,maxlen:0"
68
69                 # This should cache it
70                 SecRule ARGS_GET "WillNotMatch" "phase:1,t:none,t:removeWhiteSpace,t:lowercase,pass,nolog"
71
72                 # This should use the cached value
73                 SecRule ARGS_GET:test "foobar" "phase:2,t:none,t:removeWhiteSpace,t:lowercase,deny"
74         ),
75         match_log => {
76                 -debug => [ qr/removeWhiteSpace,lowercase: "foobar" .*cached/, 1 ],
77         },
78         match_response => {
79                 status => qr/^403$/,
80         },
81         request => new HTTP::Request(
82                 GET => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/index.html?test=Foo+Bar",
83         ),
84 },
85 {
86         type => "misc",
87         comment => "tfncache (non-modifying tfns cached)",
88         conf => qq(
89                 SecRuleEngine On
90                 SecDebugLog $ENV{DEBUG_LOG}
91                 SecDebugLogLevel 9
92
93                 # We need to make this work no matter what the defaults may change to
94                 SecCacheTransformations On "minlen:1,maxlen:0"
95
96                 # This should cache it
97                 SecRule ARGS_GET "WillNotMatch" "phase:1,t:none,t:removeWhiteSpace,t:lowercase,pass,nolog"
98
99                 # This should use the cached value
100                 SecRule ARGS_GET:test "foobar" "phase:1,t:none,t:removeWhiteSpace,t:lowercase,deny"
101         ),
102         match_log => {
103                 debug => [ qr/removeWhiteSpace,lowercase: "foobar" .*cached/, 1 ],
104         },
105         match_response => {
106                 status => qr/^403$/,
107         },
108         request => new HTTP::Request(
109                 GET => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/index.html?test=foo+bar",
110         ),
111 },
112 {
113         type => "misc",
114         comment => "tfncache (unique keys)",
115         conf => qq(
116                 SecRuleEngine On
117                 SecDebugLog $ENV{DEBUG_LOG}
118                 SecDebugLogLevel 9
119                 SecRequestBodyAccess On
120
121                 # We need to make this work no matter what the defaults may change to
122                 SecCacheTransformations On "minlen:1,maxlen:0"
123
124                 # This should cache it
125                 SecRule ARGS "WillNotMatch" "phase:2,t:none,t:removeWhiteSpace,t:lowercase,pass"
126
127                 # This should see cached versions of *both* ARGS_GET
128                 SecRule ARGS:test "queryval" "phase:2,t:none,t:removeWhiteSpace,t:lowercase,deny,chain"
129                 SecRule ARGS:test "firstval" "t:none,t:removeWhiteSpace,t:lowercase,chain"
130                 SecRule ARGS:test "secondval" "t:none,t:removeWhiteSpace,t:lowercase"
131         ),
132         match_log => {
133                 debug => [ qr/removeWhiteSpace,lowercase: "queryval" .*removeWhiteSpace,lowercase: "firstval" .*cached.*removeWhiteSpace,lowercase: "secondval" .*cached/s, 1 ],
134         },
135         match_response => {
136                 status => qr/^403$/,
137         },
138         request => new HTTP::Request(
139                 POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/index.html?test=Query+Val",
140                 [
141                         "Content-Type" => "application/x-www-form-urlencoded",
142                 ],
143                 #  Args
144                 "test=First+Val&test=Second+Val",
145         ),
146 },
147 {
148         type => "misc",
149         comment => "tfncache (large cache)",
150         conf => qq(
151                 SecRuleEngine On
152                 SecDebugLog $ENV{DEBUG_LOG}
153                 SecDebugLogLevel 9
154                 SecRequestBodyAccess On
155
156                 <IfDefine MODSEC_2.5>
157                         SecRequestBodyNoFilesLimit 1048576
158                 </IfDefine>
159                 SecRequestBodyInMemoryLimit 131072
160                 SecResponseBodyLimit 1048576
161
162                 # We need to make this work no matter what the defaults may change to
163                 SecCacheTransformations On "minlen:1,maxlen:0,maxitems:0"
164
165                 # This should cache it in all phases
166                 SecRule ARGS "WillNotMatch" "phase:1,t:none,t:removeWhiteSpace,t:lowercase,pass,nolog"
167                 SecRule ARGS "WillNotMatch" "phase:2,t:none,t:removeWhiteSpace,t:lowercase,pass,nolog"
168                 SecRule ARGS "WillNotMatch" "phase:3,t:none,t:removeWhiteSpace,t:lowercase,pass,nolog"
169                 SecRule ARGS "WillNotMatch" "phase:4,t:none,t:removeWhiteSpace,t:lowercase,pass,nolog"
170
171                 # This should use the cached value
172                 SecRule ARGS "foobar" "phase:4,t:none,t:removeWhiteSpace,t:lowercase,deny"
173         ),
174         match_log => {
175                 debug => [ qr/Adding request argument \(BODY\): name "test", value "Foo Bar"/, 60, "Waiting for httpd to process request: "],
176                 -error => [ qr/segmentation fault/i, 60 ],
177         },
178         match_response => {
179                 status => qr/^403$/,
180         },
181         request => new HTTP::Request(
182                 POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/index.html",
183                 [
184                         "Content-Type" => "application/x-www-form-urlencoded",
185                 ],
186                 # 1000 Args
187                 join("&", map { sprintf "arg%08d=0123456789abcdef+0123456789ABCDEF+0123456789abcdef", $_ } (1 .. 1000))."&test=Foo+Bar",
188         ),
189 },