Skip to content

Commit 9184eee

Browse files
fioneraM4tteoP
andauthored
feat: expose expected directives for e2e test (#1012)
* feat: expose expected directives for e2e test * Update http/e2e/cmd/httpe2e/main.go * Update http/e2e/cmd/httpe2e/main.go --------- Co-authored-by: Matteo Pace <[email protected]>
1 parent cdc7107 commit 9184eee

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

http/e2e/cmd/httpe2e/main.go

+1-18
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,7 @@ import (
1919
// --proxy-hostport: Proxy endpoint used to perform requests. Defaults to "localhost:8080".
2020
// --httpbin-hostport: Upstream httpbin endpoint, used for health checking reasons. Defaults to "localhost:8081".
2121

22-
// Expected Coraza configs:
23-
/*
24-
SecRuleEngine On
25-
SecRequestBodyAccess On
26-
SecResponseBodyAccess On
27-
SecResponseBodyMimeType application/json
28-
# Custom rule for Coraza config check (ensuring that these configs are used)
29-
SecRule &REQUEST_HEADERS:coraza-e2e "@eq 0" "id:100,phase:1,deny,status:424,log,msg:'Coraza E2E - Missing header'"
30-
# Custom rules for e2e testing
31-
SecRule REQUEST_URI "@streq /admin" "id:101,phase:1,t:lowercase,log,deny"
32-
SecRule REQUEST_BODY "@rx maliciouspayload" "id:102,phase:2,t:lowercase,log,deny"
33-
SecRule RESPONSE_HEADERS:pass "@rx leak" "id:103,phase:3,t:lowercase,log,deny"
34-
SecRule RESPONSE_BODY "@contains responsebodycode" "id:104,phase:4,t:lowercase,log,deny"
35-
# Custom rules mimicking the following CRS rules: 941100, 942100, 913100
36-
SecRule ARGS_NAMES|ARGS "@detectXSS" "id:9411,phase:2,t:none,t:utf8toUnicode,t:urlDecodeUni,t:htmlEntityDecode,t:jsDecode,t:cssDecode,t:removeNulls,log,deny"
37-
SecRule ARGS_NAMES|ARGS "@detectSQLi" "id:9421,phase:2,t:none,t:utf8toUnicode,t:urlDecodeUni,t:removeNulls,multiMatch,log,deny"
38-
SecRule REQUEST_HEADERS:User-Agent "@pm grabber masscan" "id:9131,phase:1,t:none,log,deny"
39-
*/
22+
// A dedicated set of directives is expected to be loaded for e2e testing. Refer to the `Directives` const in http/e2e/e2e.go.
4023

4124
func main() {
4225
// Initialize variables

http/e2e/e2e.go

+18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ import (
1818
const (
1919
configCheckStatusCode = 424
2020
healthCheckTimeout = 15 // Seconds
21+
22+
Directives = `
23+
SecRuleEngine On
24+
SecRequestBodyAccess On
25+
SecResponseBodyAccess On
26+
SecResponseBodyMimeType application/json
27+
# Custom rule for Coraza config check (ensuring that these configs are used)
28+
SecRule &REQUEST_HEADERS:coraza-e2e "@eq 0" "id:100,phase:1,deny,status:424,log,msg:'Coraza E2E - Missing header'"
29+
# Custom rules for e2e testing
30+
SecRule REQUEST_URI "@streq /admin" "id:101,phase:1,t:lowercase,log,deny"
31+
SecRule REQUEST_BODY "@rx maliciouspayload" "id:102,phase:2,t:lowercase,log,deny"
32+
SecRule RESPONSE_HEADERS:pass "@rx leak" "id:103,phase:3,t:lowercase,log,deny"
33+
SecRule RESPONSE_BODY "@contains responsebodycode" "id:104,phase:4,t:lowercase,log,deny"
34+
# Custom rules mimicking the following CRS rules: 941100, 942100, 913100
35+
SecRule ARGS_NAMES|ARGS "@detectXSS" "id:9411,phase:2,t:none,t:utf8toUnicode,t:urlDecodeUni,t:htmlEntityDecode,t:jsDecode,t:cssDecode,t:removeNulls,log,deny"
36+
SecRule ARGS_NAMES|ARGS "@detectSQLi" "id:9421,phase:2,t:none,t:utf8toUnicode,t:urlDecodeUni,t:removeNulls,multiMatch,log,deny"
37+
SecRule REQUEST_HEADERS:User-Agent "@pm grabber masscan" "id:9131,phase:1,t:none,log,deny"
38+
`
2139
)
2240

2341
type Config struct {

testing/e2e/e2e_test.go

+1-18
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,8 @@ import (
2323
func TestE2e(t *testing.T) {
2424
conf := coraza.NewWAFConfig()
2525

26-
customE2eDirectives := `
27-
SecRuleEngine On
28-
SecRequestBodyAccess On
29-
SecResponseBodyAccess On
30-
SecResponseBodyMimeType application/json
31-
# Custom rule for Coraza config check (ensuring that these configs are used)
32-
SecRule &REQUEST_HEADERS:coraza-e2e "@eq 0" "id:100,phase:1,deny,status:424,log,msg:'Coraza E2E - Missing header'"
33-
# Custom rules for e2e testing
34-
SecRule REQUEST_URI "@streq /admin" "id:101,phase:1,t:lowercase,log,deny"
35-
SecRule REQUEST_BODY "@rx maliciouspayload" "id:102,phase:2,t:lowercase,log,deny"
36-
SecRule RESPONSE_HEADERS:pass "@rx leak" "id:103,phase:3,t:lowercase,log,deny"
37-
SecRule RESPONSE_BODY "@contains responsebodycode" "id:104,phase:4,t:lowercase,log,deny"
38-
# Custom rules mimicking the following CRS rules: 941100, 942100, 913100
39-
SecRule ARGS_NAMES|ARGS "@detectXSS" "id:9411,phase:2,t:none,t:utf8toUnicode,t:urlDecodeUni,t:htmlEntityDecode,t:jsDecode,t:cssDecode,t:removeNulls,log,deny"
40-
SecRule ARGS_NAMES|ARGS "@detectSQLi" "id:9421,phase:2,t:none,t:utf8toUnicode,t:urlDecodeUni,t:removeNulls,multiMatch,log,deny"
41-
SecRule REQUEST_HEADERS:User-Agent "@pm grabber masscan" "id:9131,phase:1,t:none,log,deny"
42-
`
4326
conf = conf.
44-
WithDirectives(customE2eDirectives)
27+
WithDirectives(e2e.Directives)
4528

4629
waf, err := coraza.NewWAF(conf)
4730
if err != nil {

0 commit comments

Comments
 (0)