make Match public
This commit is contained in:
parent
adba4e2a2f
commit
8a99de471e
|
@ -25,7 +25,7 @@ rules:
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type match struct {
|
type Match struct {
|
||||||
Type string `yaml:"type"`
|
Type string `yaml:"type"`
|
||||||
Value string `yaml:"value"`
|
Value string `yaml:"value"`
|
||||||
Not bool `yaml:"not,omitempty"`
|
Not bool `yaml:"not,omitempty"`
|
||||||
|
@ -37,7 +37,7 @@ type CustomRule struct {
|
||||||
Zones []string `yaml:"zones"`
|
Zones []string `yaml:"zones"`
|
||||||
Variables []string `yaml:"variables"`
|
Variables []string `yaml:"variables"`
|
||||||
|
|
||||||
Match match `yaml:"match"`
|
Match Match `yaml:"match"`
|
||||||
Transform []string `yaml:"transform"` //t:lowercase, t:uppercase, etc
|
Transform []string `yaml:"transform"` //t:lowercase, t:uppercase, etc
|
||||||
And []CustomRule `yaml:"and,omitempty"`
|
And []CustomRule `yaml:"and,omitempty"`
|
||||||
Or []CustomRule `yaml:"or,omitempty"`
|
Or []CustomRule `yaml:"or,omitempty"`
|
||||||
|
|
|
@ -13,7 +13,7 @@ func TestVPatchRuleString(t *testing.T) {
|
||||||
rule: CustomRule{
|
rule: CustomRule{
|
||||||
Zones: []string{"ARGS"},
|
Zones: []string{"ARGS"},
|
||||||
Variables: []string{"foo"},
|
Variables: []string{"foo"},
|
||||||
Match: match{Type: "regex", Value: "[^a-zA-Z]"},
|
Match: Match{Type: "regex", Value: "[^a-zA-Z]"},
|
||||||
Transform: []string{"lowercase"},
|
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"`,
|
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{
|
rule: CustomRule{
|
||||||
Zones: []string{"ARGS"},
|
Zones: []string{"ARGS"},
|
||||||
Variables: []string{"foo", "bar"},
|
Variables: []string{"foo", "bar"},
|
||||||
Match: match{Type: "regex", Value: "[^a-zA-Z]"},
|
Match: Match{Type: "regex", Value: "[^a-zA-Z]"},
|
||||||
Transform: []string{"lowercase"},
|
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"`,
|
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",
|
name: "Base Rule #2",
|
||||||
rule: CustomRule{
|
rule: CustomRule{
|
||||||
Zones: []string{"METHOD"},
|
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'"`,
|
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",
|
name: "Base Negative Rule",
|
||||||
rule: CustomRule{
|
rule: CustomRule{
|
||||||
Zones: []string{"METHOD"},
|
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'"`,
|
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{
|
rule: CustomRule{
|
||||||
Zones: []string{"ARGS", "BODY_ARGS"},
|
Zones: []string{"ARGS", "BODY_ARGS"},
|
||||||
Variables: []string{"foo"},
|
Variables: []string{"foo"},
|
||||||
Match: match{Type: "regex", Value: "[^a-zA-Z]"},
|
Match: Match{Type: "regex", Value: "[^a-zA-Z]"},
|
||||||
Transform: []string{"lowercase"},
|
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"`,
|
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{
|
rule: CustomRule{
|
||||||
Zones: []string{"ARGS", "BODY_ARGS"},
|
Zones: []string{"ARGS", "BODY_ARGS"},
|
||||||
Variables: []string{"foo", "bar"},
|
Variables: []string{"foo", "bar"},
|
||||||
Match: match{Type: "regex", Value: "[^a-zA-Z]"},
|
Match: Match{Type: "regex", Value: "[^a-zA-Z]"},
|
||||||
Transform: []string{"lowercase"},
|
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"`,
|
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",
|
name: "Multiple Zones No Vars",
|
||||||
rule: CustomRule{
|
rule: CustomRule{
|
||||||
Zones: []string{"ARGS", "BODY_ARGS"},
|
Zones: []string{"ARGS", "BODY_ARGS"},
|
||||||
Match: match{Type: "regex", Value: "[^a-zA-Z]"},
|
Match: Match{Type: "regex", Value: "[^a-zA-Z]"},
|
||||||
Transform: []string{"lowercase"},
|
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"`,
|
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"},
|
Zones: []string{"ARGS"},
|
||||||
Variables: []string{"foo"},
|
Variables: []string{"foo"},
|
||||||
Match: match{Type: "regex", Value: "[^a-zA-Z]"},
|
Match: Match{Type: "regex", Value: "[^a-zA-Z]"},
|
||||||
Transform: []string{"lowercase"},
|
Transform: []string{"lowercase"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Zones: []string{"ARGS"},
|
Zones: []string{"ARGS"},
|
||||||
Variables: []string{"bar"},
|
Variables: []string{"bar"},
|
||||||
Match: match{Type: "regex", Value: "[^a-zA-Z]"},
|
Match: Match{Type: "regex", Value: "[^a-zA-Z]"},
|
||||||
Transform: []string{"lowercase"},
|
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"},
|
Zones: []string{"ARGS"},
|
||||||
Variables: []string{"foo"},
|
Variables: []string{"foo"},
|
||||||
Match: match{Type: "regex", Value: "[^a-zA-Z]"},
|
Match: Match{Type: "regex", Value: "[^a-zA-Z]"},
|
||||||
Transform: []string{"lowercase"},
|
Transform: []string{"lowercase"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Zones: []string{"ARGS"},
|
Zones: []string{"ARGS"},
|
||||||
Variables: []string{"bar"},
|
Variables: []string{"bar"},
|
||||||
Match: match{Type: "regex", Value: "[^a-zA-Z]"},
|
Match: Match{Type: "regex", Value: "[^a-zA-Z]"},
|
||||||
Transform: []string{"lowercase"},
|
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"},
|
Zones: []string{"ARGS"},
|
||||||
Variables: []string{"foo"},
|
Variables: []string{"foo"},
|
||||||
Match: match{Type: "regex", Value: "[^a-zA-Z]"},
|
Match: Match{Type: "regex", Value: "[^a-zA-Z]"},
|
||||||
Transform: []string{"lowercase"},
|
Transform: []string{"lowercase"},
|
||||||
Or: []CustomRule{
|
Or: []CustomRule{
|
||||||
{
|
{
|
||||||
Zones: []string{"ARGS"},
|
Zones: []string{"ARGS"},
|
||||||
Variables: []string{"foo"},
|
Variables: []string{"foo"},
|
||||||
Match: match{Type: "regex", Value: "[^a-zA-Z]"},
|
Match: Match{Type: "regex", Value: "[^a-zA-Z]"},
|
||||||
Transform: []string{"lowercase"},
|
Transform: []string{"lowercase"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Zones: []string{"ARGS"},
|
Zones: []string{"ARGS"},
|
||||||
Variables: []string{"bar"},
|
Variables: []string{"bar"},
|
||||||
Match: match{Type: "regex", Value: "[^a-zA-Z]"},
|
Match: Match{Type: "regex", Value: "[^a-zA-Z]"},
|
||||||
Transform: []string{"lowercase"},
|
Transform: []string{"lowercase"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue