File: 00-phases.t

package info (click to toggle)
modsecurity-apache 2.8.0-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,492 kB
  • ctags: 2,899
  • sloc: ansic: 48,034; sh: 11,506; perl: 2,038; cpp: 1,929; makefile: 530; xml: 6
file content (151 lines) | stat: -rw-r--r-- 4,585 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
### Test the phases

# Phase 1 (request headers)
{
	type => "misc",
	comment => "phase 1",
	conf => qq(
		SecRuleEngine On
		SecRequestBodyAccess On
		SecResponseBodyAccess On
		SecResponseBodyMimeType text/plain null
		SecRule REQUEST_LINE "^POST" "phase:1,pass,log,auditlog,id:500169"
		SecRule ARGS "val1" "phase:1,pass,log,auditlog,id:500170"
		SecRule RESPONSE_HEADERS:Last-Modified "." "phase:1,pass,log,auditlog,id:500171"
		SecRule RESPONSE_BODY "TEST" "phase:1,pass,log,auditlog,id:500172"
	),
	match_log => {
		error => [ qr/Pattern match "\^POST" at REQUEST_LINE/, 1 ],
		-error => [ qr/Pattern match .* (ARGS|RESPONSE)/, 1 ],
	},
	match_response => {
		status => qr/^200$/,
	},
	request => new HTTP::Request(
		POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
		[
			"Content-Type" => "application/x-www-form-urlencoded",
		],
		"arg1=val1&arg2=val2",
	),
},

# Phase 2 (request body)
{
	type => "misc",
	comment => "phase 2",
	conf => qq(
		SecRuleEngine On
		SecRequestBodyAccess On
		SecResponseBodyAccess On
		SecResponseBodyMimeType text/plain null
		SecRule REQUEST_LINE "^POST" "phase:2,pass,log,auditlog,id:500173"
		SecRule ARGS "val1" "phase:2,pass,log,auditlog,id:500174"
		SecRule RESPONSE_HEADERS:Last-Modified "." "phase:2,pass,log,auditlog,id:500175"
		SecRule RESPONSE_BODY "TEST" "phase:2,pass,log,auditlog,id:500176"
	),
	match_log => {
		error => [ qr/Pattern match "\^POST" at REQUEST_LINE.*Pattern match "val1" at ARGS/s, 1 ],
		-error => [ qr/Pattern match .* RESPONSE/, 1 ],
	},
	match_response => {
		status => qr/^200$/,
	},
	request => new HTTP::Request(
		POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
		[
			"Content-Type" => "application/x-www-form-urlencoded",
		],
		"arg1=val1&arg2=val2",
	),
},

# Phase 3 (response headers)
{
	type => "misc",
	comment => "phase 3",
	conf => qq(
		SecRuleEngine On
		SecRequestBodyAccess On
		SecResponseBodyAccess On
		SecResponseBodyMimeType text/plain null
		SecRule REQUEST_LINE "^POST" "phase:3,pass,log,auditlog,id:500177"
		SecRule ARGS "val1" "phase:3,pass,log,auditlog,id:500178"
		SecRule RESPONSE_HEADERS:Last-Modified "." "phase:3,pass,log,auditlog,id:500179"
		SecRule RESPONSE_BODY "TEST" "phase:3,pass,log,auditlog,id:500180"
	),
	match_log => {
		error => [ qr/Pattern match "\^POST" at REQUEST_LINE.*Pattern match "val1" at ARGS.*Pattern match "\." at RESPONSE_HEADERS/s, 1 ],
		-error => [ qr/Pattern match .* RESPONSE_BODY/, 1 ],
	},
	match_response => {
		status => qr/^200$/,
	},
	request => new HTTP::Request(
		POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
		[
			"Content-Type" => "application/x-www-form-urlencoded",
		],
		"arg1=val1&arg2=val2",
	),
},

# Phase 4 (response body)
{
	type => "misc",
	comment => "phase 4",
	conf => qq(
		SecRuleEngine On
		SecRequestBodyAccess On
		SecResponseBodyAccess On
		SecResponseBodyMimeType text/plain null
		SecDebugLog "$ENV{DEBUG_LOG}"
		SecDebugLogLevel 9
		SecRule REQUEST_LINE "^POST" "phase:4,pass,log,auditlog,id:500181"
		SecRule ARGS "val1" "phase:4,pass,log,auditlog,id:500182"
		SecRule RESPONSE_HEADERS:Last-Modified "." "phase:4,pass,log,auditlog,id:500183"
		SecRule RESPONSE_BODY "TEST" "phase:4,pass,log,auditlog,id:500184"
	),
	match_log => {
		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 ],
	},
	match_response => {
		status => qr/^200$/,
	},
	request => new HTTP::Request(
		POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
		[
			"Content-Type" => "application/x-www-form-urlencoded",
		],
		"arg1=val1&arg2=val2",
	),
},

# Phase 5 (logging)
{
	type => "misc",
	comment => "phase 5",
	conf => qq(
		SecRuleEngine On
		SecRequestBodyAccess On
		SecResponseBodyAccess On
		SecResponseBodyMimeType text/plain null
		SecRule REQUEST_LINE "^POST" "phase:5,pass,log,auditlog,id:500185"
		SecRule ARGS "val1" "phase:5,pass,log,auditlog,id:500186"
		SecRule RESPONSE_HEADERS:Last-Modified "." "phase:5,pass,log,auditlog,id:500187"
		SecRule RESPONSE_BODY "TEST" "phase:5,pass,log,auditlog,id:500188"
	),
	match_log => {
		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 ],
	},
	match_response => {
		status => qr/^200$/,
	},
	request => new HTTP::Request(
		POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
		[
			"Content-Type" => "application/x-www-form-urlencoded",
		],
		"arg1=val1&arg2=val2",
	),
},