Imported Upstream version 2.5.11
[libapache-mod-security.git] / apache2 / t / regression / misc / 00-phases.t
1 ### Test the phases
2
3 # Phase 1 (request headers)
4 {
5         type => "misc",
6         comment => "phase 1",
7         conf => qq(
8                 SecRuleEngine On
9                 SecRequestBodyAccess On
10                 SecResponseBodyAccess On
11                 SecResponseBodyMimeType text/plain null
12                 SecRule REQUEST_LINE "^POST" "phase:1,pass,log,auditlog"
13                 SecRule ARGS "val1" "phase:1,pass,log,auditlog"
14                 SecRule RESPONSE_HEADERS:Last-Modified "." "phase:1,pass,log,auditlog"
15                 SecRule RESPONSE_BODY "TEST" "phase:1,pass,log,auditlog"
16         ),
17         match_log => {
18                 error => [ qr/Pattern match "\^POST" at REQUEST_LINE/, 1 ],
19                 -error => [ qr/Pattern match .* (ARGS|RESPONSE)/, 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/x-www-form-urlencoded",
28                 ],
29                 "arg1=val1&arg2=val2",
30         ),
31 },
32
33 # Phase 2 (request body)
34 {
35         type => "misc",
36         comment => "phase 2",
37         conf => qq(
38                 SecRuleEngine On
39                 SecRequestBodyAccess On
40                 SecResponseBodyAccess On
41                 SecResponseBodyMimeType text/plain null
42                 SecRule REQUEST_LINE "^POST" "phase:2,pass,log,auditlog"
43                 SecRule ARGS "val1" "phase:2,pass,log,auditlog"
44                 SecRule RESPONSE_HEADERS:Last-Modified "." "phase:2,pass,log,auditlog"
45                 SecRule RESPONSE_BODY "TEST" "phase:2,pass,log,auditlog"
46         ),
47         match_log => {
48                 error => [ qr/Pattern match "\^POST" at REQUEST_LINE.*Pattern match "val1" at ARGS/s, 1 ],
49                 -error => [ qr/Pattern match .* RESPONSE/, 1 ],
50         },
51         match_response => {
52                 status => qr/^200$/,
53         },
54         request => new HTTP::Request(
55                 POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
56                 [
57                         "Content-Type" => "application/x-www-form-urlencoded",
58                 ],
59                 "arg1=val1&arg2=val2",
60         ),
61 },
62
63 # Phase 3 (response headers)
64 {
65         type => "misc",
66         comment => "phase 3",
67         conf => qq(
68                 SecRuleEngine On
69                 SecRequestBodyAccess On
70                 SecResponseBodyAccess On
71                 SecResponseBodyMimeType text/plain null
72                 SecRule REQUEST_LINE "^POST" "phase:3,pass,log,auditlog"
73                 SecRule ARGS "val1" "phase:3,pass,log,auditlog"
74                 SecRule RESPONSE_HEADERS:Last-Modified "." "phase:3,pass,log,auditlog"
75                 SecRule RESPONSE_BODY "TEST" "phase:3,pass,log,auditlog"
76         ),
77         match_log => {
78                 error => [ qr/Pattern match "\^POST" at REQUEST_LINE.*Pattern match "val1" at ARGS.*Pattern match "\." at RESPONSE_HEADERS/s, 1 ],
79                 -error => [ qr/Pattern match .* RESPONSE_BODY/, 1 ],
80         },
81         match_response => {
82                 status => qr/^200$/,
83         },
84         request => new HTTP::Request(
85                 POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
86                 [
87                         "Content-Type" => "application/x-www-form-urlencoded",
88                 ],
89                 "arg1=val1&arg2=val2",
90         ),
91 },
92
93 # Phase 4 (response body)
94 {
95         type => "misc",
96         comment => "phase 4",
97         conf => qq(
98                 SecRuleEngine On
99                 SecRequestBodyAccess On
100                 SecResponseBodyAccess On
101                 SecResponseBodyMimeType text/plain null
102                 SecDebugLog "$ENV{DEBUG_LOG}"
103                 SecDebugLogLevel 9
104                 SecRule REQUEST_LINE "^POST" "phase:4,pass,log,auditlog"
105                 SecRule ARGS "val1" "phase:4,pass,log,auditlog"
106                 SecRule RESPONSE_HEADERS:Last-Modified "." "phase:4,pass,log,auditlog"
107                 SecRule RESPONSE_BODY "TEST" "phase:4,pass,log,auditlog"
108         ),
109         match_log => {
110                 error => [ qr/Pattern match "\^POST" at REQUEST_LINE.*Pattern match "val1" at ARGS.*Pattern match "\." at RESPONSE_HEADERS.*Pattern match "TEST" at RESPONSE_BODY/s, 1 ],
111         },
112         match_response => {
113                 status => qr/^200$/,
114         },
115         request => new HTTP::Request(
116                 POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
117                 [
118                         "Content-Type" => "application/x-www-form-urlencoded",
119                 ],
120                 "arg1=val1&arg2=val2",
121         ),
122 },
123
124 # Phase 5 (logging)
125 {
126         type => "misc",
127         comment => "phase 5",
128         conf => qq(
129                 SecRuleEngine On
130                 SecRequestBodyAccess On
131                 SecResponseBodyAccess On
132                 SecResponseBodyMimeType text/plain null
133                 SecRule REQUEST_LINE "^POST" "phase:5,pass,log,auditlog"
134                 SecRule ARGS "val1" "phase:5,pass,log,auditlog"
135                 SecRule RESPONSE_HEADERS:Last-Modified "." "phase:5,pass,log,auditlog"
136                 SecRule RESPONSE_BODY "TEST" "phase:5,pass,log,auditlog"
137         ),
138         match_log => {
139                 error => [ qr/Pattern match "\^POST" at REQUEST_LINE.*Pattern match "val1" at ARGS.*Pattern match "\." at RESPONSE_HEADERS.*Pattern match "TEST" at RESPONSE_BODY/s, 1 ],
140         },
141         match_response => {
142                 status => qr/^200$/,
143         },
144         request => new HTTP::Request(
145                 POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
146                 [
147                         "Content-Type" => "application/x-www-form-urlencoded",
148                 ],
149                 "arg1=val1&arg2=val2",
150         ),
151 },