(b *testing.B)
| 122 | } |
| 123 | |
| 124 | func BenchmarkRuleSet_MatchRequest(b *testing.B) { |
| 125 | runtime.GOMAXPROCS(1) |
| 126 | |
| 127 | var set = waf.NewRuleSet() |
| 128 | set.Connector = waf.RuleConnectorOr |
| 129 | |
| 130 | set.Rules = []*waf.Rule{ |
| 131 | { |
| 132 | Param: "${requestAll}", |
| 133 | Operator: waf.RuleOperatorMatch, |
| 134 | Value: `(onmouseover|onmousemove|onmousedown|onmouseup|onerror|onload|onclick|ondblclick|onkeydown|onkeyup|onkeypress)\s*=`, |
| 135 | }, |
| 136 | { |
| 137 | Param: "${requestAll}", |
| 138 | Operator: waf.RuleOperatorMatch, |
| 139 | Value: `\b(eval|system|exec|execute|passthru|shell_exec|phpinfo)\s*\(`, |
| 140 | }, |
| 141 | { |
| 142 | Param: "${arg.name}", |
| 143 | Operator: waf.RuleOperatorEqString, |
| 144 | Value: "lu", |
| 145 | }, |
| 146 | { |
| 147 | Param: "${arg.age}", |
| 148 | Operator: waf.RuleOperatorEq, |
| 149 | Value: "21", |
| 150 | }, |
| 151 | } |
| 152 | |
| 153 | err := set.Init(nil) |
| 154 | if err != nil { |
| 155 | b.Fatal(err) |
| 156 | } |
| 157 | |
| 158 | rawReq, err := http.NewRequest(http.MethodPost, "http://teaos.cn/hello?name=lu&age=20", bytes.NewBuffer(bytes.Repeat([]byte("HELLO"), 1024))) |
| 159 | if err != nil { |
| 160 | b.Fatal(err) |
| 161 | } |
| 162 | req := requests.NewTestRequest(rawReq) |
| 163 | for i := 0; i < b.N; i++ { |
| 164 | _, _, _ = set.MatchRequest(req) |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | func BenchmarkRuleSet_MatchRequest_Regexp(b *testing.B) { |
| 169 | runtime.GOMAXPROCS(1) |
nothing calls this directly
no test coverage detected