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

Function TestWAF_MatchRequest

internal/waf/waf_test.go:13–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestWAF_MatchRequest(t *testing.T) {
14 var a = assert.NewAssertion(t)
15
16 var set = waf.NewRuleSet()
17 set.Name = "Name_Age"
18 set.Connector = waf.RuleConnectorAnd
19 set.Rules = []*waf.Rule{
20 {
21 Param: "${arg.name}",
22 Operator: waf.RuleOperatorEqString,
23 Value: "lu",
24 },
25 {
26 Param: "${arg.age}",
27 Operator: waf.RuleOperatorEq,
28 Value: "20",
29 },
30 }
31 set.AddAction(waf.ActionBlock, nil)
32
33 var group = waf.NewRuleGroup()
34 group.AddRuleSet(set)
35 group.IsInbound = true
36
37 var wafInstance = waf.NewWAF()
38 wafInstance.AddRuleGroup(group)
39 errs := wafInstance.Init()
40 if len(errs) > 0 {
41 t.Fatal(errs[0])
42 }
43
44 req, err := http.NewRequest(http.MethodGet, "http://teaos.cn/hello?name=lu&age=20", nil)
45 if err != nil {
46 t.Fatal(err)
47 }
48 result, err := wafInstance.MatchRequest(requests.NewTestRequest(req), nil, firewallconfigs.ServerCaptchaTypeNone)
49 if err != nil {
50 t.Fatal(err)
51 }
52 if set == nil {
53 t.Log("not match")
54 return
55 }
56 t.Log("goNext:", result.GoNext, "set:", set.Name)
57 a.IsFalse(result.GoNext)
58}
59
60func TestWAF_MatchRequest_Allow(t *testing.T) {
61 var a = assert.NewAssertion(t)

Callers

nothing calls this directly

Calls 10

NewRuleSetFunction · 0.92
NewRuleGroupFunction · 0.92
NewWAFFunction · 0.92
NewTestRequestFunction · 0.92
AddRuleSetMethod · 0.80
AddRuleGroupMethod · 0.80
LogMethod · 0.80
InitMethod · 0.65
AddActionMethod · 0.45
MatchRequestMethod · 0.45

Tested by

no test coverage detected