(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func 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 | |
| 60 | func TestWAF_MatchRequest_Allow(t *testing.T) { |
| 61 | var a = assert.NewAssertion(t) |
nothing calls this directly
no test coverage detected