From 8a99de471e03bf77a838c3c7533a620c040e15f3 Mon Sep 17 00:00:00 2001 From: bui Date: Fri, 12 Jan 2024 14:42:26 +0100 Subject: [PATCH] make Match public --- pkg/appsec/appsec_rule/appsec_rule.go | 4 ++-- pkg/appsec/appsec_rule/modsec_rule_test.go | 28 +++++++++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/appsec/appsec_rule/appsec_rule.go b/pkg/appsec/appsec_rule/appsec_rule.go index 4bc46ef50..289405ef1 100644 --- a/pkg/appsec/appsec_rule/appsec_rule.go +++ b/pkg/appsec/appsec_rule/appsec_rule.go @@ -25,7 +25,7 @@ rules: */ -type match struct { +type Match struct { Type string `yaml:"type"` Value string `yaml:"value"` Not bool `yaml:"not,omitempty"` @@ -37,7 +37,7 @@ type CustomRule struct { Zones []string `yaml:"zones"` Variables []string `yaml:"variables"` - Match match `yaml:"match"` + Match Match `yaml:"match"` Transform []string `yaml:"transform"` //t:lowercase, t:uppercase, etc And []CustomRule `yaml:"and,omitempty"` Or []CustomRule `yaml:"or,omitempty"` diff --git a/pkg/appsec/appsec_rule/modsec_rule_test.go b/pkg/appsec/appsec_rule/modsec_rule_test.go index 3c790cfb9..c29732ac0 100644 --- a/pkg/appsec/appsec_rule/modsec_rule_test.go +++ b/pkg/appsec/appsec_rule/modsec_rule_test.go @@ -13,7 +13,7 @@ func TestVPatchRuleString(t *testing.T) { rule: CustomRule{ Zones: []string{"ARGS"}, Variables: []string{"foo"}, - Match: match{Type: "regex", Value: "[^a-zA-Z]"}, + Match: Match{Type: "regex", Value: "[^a-zA-Z]"}, Transform: []string{"lowercase"}, }, expected: `SecRule ARGS_GET:foo "@rx [^a-zA-Z]" "id:2203944045,phase:2,deny,log,msg:'Base Rule',tag:'crowdsec-Base Rule',t:lowercase"`, @@ -23,7 +23,7 @@ func TestVPatchRuleString(t *testing.T) { rule: CustomRule{ Zones: []string{"ARGS"}, Variables: []string{"foo", "bar"}, - Match: match{Type: "regex", Value: "[^a-zA-Z]"}, + Match: Match{Type: "regex", Value: "[^a-zA-Z]"}, Transform: []string{"lowercase"}, }, expected: `SecRule ARGS_GET:foo|ARGS_GET:bar "@rx [^a-zA-Z]" "id:385719930,phase:2,deny,log,msg:'One zone, multi var',tag:'crowdsec-One zone, multi var',t:lowercase"`, @@ -32,7 +32,7 @@ func TestVPatchRuleString(t *testing.T) { name: "Base Rule #2", rule: CustomRule{ Zones: []string{"METHOD"}, - Match: match{Type: "startsWith", Value: "toto"}, + Match: Match{Type: "startsWith", Value: "toto"}, }, expected: `SecRule REQUEST_METHOD "@beginsWith toto" "id:2759779019,phase:2,deny,log,msg:'Base Rule #2',tag:'crowdsec-Base Rule #2'"`, }, @@ -40,7 +40,7 @@ func TestVPatchRuleString(t *testing.T) { name: "Base Negative Rule", rule: CustomRule{ Zones: []string{"METHOD"}, - Match: match{Type: "startsWith", Value: "toto", Not: true}, + Match: Match{Type: "startsWith", Value: "toto", Not: true}, }, expected: `SecRule REQUEST_METHOD "!@beginsWith toto" "id:3966251995,phase:2,deny,log,msg:'Base Negative Rule',tag:'crowdsec-Base Negative Rule'"`, }, @@ -49,7 +49,7 @@ func TestVPatchRuleString(t *testing.T) { rule: CustomRule{ Zones: []string{"ARGS", "BODY_ARGS"}, Variables: []string{"foo"}, - Match: match{Type: "regex", Value: "[^a-zA-Z]"}, + Match: Match{Type: "regex", Value: "[^a-zA-Z]"}, Transform: []string{"lowercase"}, }, expected: `SecRule ARGS_GET:foo|ARGS_POST:foo "@rx [^a-zA-Z]" "id:3387135861,phase:2,deny,log,msg:'Multiple Zones',tag:'crowdsec-Multiple Zones',t:lowercase"`, @@ -59,7 +59,7 @@ func TestVPatchRuleString(t *testing.T) { rule: CustomRule{ Zones: []string{"ARGS", "BODY_ARGS"}, Variables: []string{"foo", "bar"}, - Match: match{Type: "regex", Value: "[^a-zA-Z]"}, + Match: Match{Type: "regex", Value: "[^a-zA-Z]"}, Transform: []string{"lowercase"}, }, expected: `SecRule ARGS_GET:foo|ARGS_GET:bar|ARGS_POST:foo|ARGS_POST:bar "@rx [^a-zA-Z]" "id:1119773585,phase:2,deny,log,msg:'Multiple Zones Multi Var',tag:'crowdsec-Multiple Zones Multi Var',t:lowercase"`, @@ -68,7 +68,7 @@ func TestVPatchRuleString(t *testing.T) { name: "Multiple Zones No Vars", rule: CustomRule{ Zones: []string{"ARGS", "BODY_ARGS"}, - Match: match{Type: "regex", Value: "[^a-zA-Z]"}, + Match: Match{Type: "regex", Value: "[^a-zA-Z]"}, Transform: []string{"lowercase"}, }, expected: `SecRule ARGS_GET|ARGS_POST "@rx [^a-zA-Z]" "id:2020110336,phase:2,deny,log,msg:'Multiple Zones No Vars',tag:'crowdsec-Multiple Zones No Vars',t:lowercase"`, @@ -81,13 +81,13 @@ func TestVPatchRuleString(t *testing.T) { Zones: []string{"ARGS"}, Variables: []string{"foo"}, - Match: match{Type: "regex", Value: "[^a-zA-Z]"}, + Match: Match{Type: "regex", Value: "[^a-zA-Z]"}, Transform: []string{"lowercase"}, }, { Zones: []string{"ARGS"}, Variables: []string{"bar"}, - Match: match{Type: "regex", Value: "[^a-zA-Z]"}, + Match: Match{Type: "regex", Value: "[^a-zA-Z]"}, Transform: []string{"lowercase"}, }, }, @@ -102,13 +102,13 @@ SecRule ARGS_GET:bar "@rx [^a-zA-Z]" "id:1865217529,phase:2,deny,log,msg:'Basic { Zones: []string{"ARGS"}, Variables: []string{"foo"}, - Match: match{Type: "regex", Value: "[^a-zA-Z]"}, + Match: Match{Type: "regex", Value: "[^a-zA-Z]"}, Transform: []string{"lowercase"}, }, { Zones: []string{"ARGS"}, Variables: []string{"bar"}, - Match: match{Type: "regex", Value: "[^a-zA-Z]"}, + Match: Match{Type: "regex", Value: "[^a-zA-Z]"}, Transform: []string{"lowercase"}, }, }, @@ -123,19 +123,19 @@ SecRule ARGS_GET:bar "@rx [^a-zA-Z]" "id:271441587,phase:2,deny,log,msg:'Basic O { Zones: []string{"ARGS"}, Variables: []string{"foo"}, - Match: match{Type: "regex", Value: "[^a-zA-Z]"}, + Match: Match{Type: "regex", Value: "[^a-zA-Z]"}, Transform: []string{"lowercase"}, Or: []CustomRule{ { Zones: []string{"ARGS"}, Variables: []string{"foo"}, - Match: match{Type: "regex", Value: "[^a-zA-Z]"}, + Match: Match{Type: "regex", Value: "[^a-zA-Z]"}, Transform: []string{"lowercase"}, }, { Zones: []string{"ARGS"}, Variables: []string{"bar"}, - Match: match{Type: "regex", Value: "[^a-zA-Z]"}, + Match: Match{Type: "regex", Value: "[^a-zA-Z]"}, Transform: []string{"lowercase"}, }, },