MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / TestRuleSet_MatchRequest_Allow

Function TestRuleSet_MatchRequest_Allow

internal/waf/rule_set_test.go:78–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

76}
77
78func TestRuleSet_MatchRequest_Allow(t *testing.T) {
79 var a = assert.NewAssertion(t)
80
81 var set = waf.NewRuleSet()
82 set.Connector = waf.RuleConnectorOr
83
84 set.Rules = []*waf.Rule{
85 {
86 Param: "${requestPath}",
87 Operator: waf.RuleOperatorMatch,
88 Value: "hello",
89 },
90 }
91
92 set.Actions = []*waf.ActionConfig{
93 {
94 Code: "allow",
95 Options: maps.Map{
96 "scope": waf.AllowScopeGroup,
97 },
98 },
99 }
100
101 var wafInstance = waf.NewWAF()
102
103 err := set.Init(wafInstance)
104 if err != nil {
105 t.Fatal(err)
106 }
107
108 rawReq, err := http.NewRequest(http.MethodGet, "http://teaos.cn/hello?name=lu&age=20", nil)
109 if err != nil {
110 t.Fatal(err)
111 }
112 var req = requests.NewTestRequest(rawReq)
113 b, _, err := set.MatchRequest(req)
114 if err != nil {
115 t.Fatal(err)
116 }
117 a.IsTrue(b)
118
119 var result = set.PerformActions(wafInstance, &waf.RuleGroup{}, req, nil)
120 a.IsTrue(result.IsAllowed)
121 t.Log("scope:", result.AllowScope)
122}
123
124func BenchmarkRuleSet_MatchRequest(b *testing.B) {
125 runtime.GOMAXPROCS(1)

Callers

nothing calls this directly

Calls 7

NewRuleSetFunction · 0.92
NewWAFFunction · 0.92
NewTestRequestFunction · 0.92
PerformActionsMethod · 0.80
LogMethod · 0.80
InitMethod · 0.65
MatchRequestMethod · 0.45

Tested by

no test coverage detected