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

Function BenchmarkRuleSet_MatchRequest_Regexp

internal/waf/rule_set_test.go:168–196  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

166}
167
168func BenchmarkRuleSet_MatchRequest_Regexp(b *testing.B) {
169 runtime.GOMAXPROCS(1)
170
171 var set = waf.NewRuleSet()
172 set.Connector = waf.RuleConnectorOr
173
174 set.Rules = []*waf.Rule{
175 {
176 Param: "${requestBody}",
177 Operator: waf.RuleOperatorMatch,
178 Value: `\b(eval|system|exec|execute|passthru|shell_exec|phpinfo)\s*\(`,
179 IsCaseInsensitive: false,
180 },
181 }
182
183 err := set.Init(nil)
184 if err != nil {
185 b.Fatal(err)
186 }
187
188 rawReq, err := http.NewRequest(http.MethodPost, "http://teaos.cn/hello?name=lu&age=20", bytes.NewBuffer(bytes.Repeat([]byte("HELLO"), 2048)))
189 if err != nil {
190 b.Fatal(err)
191 }
192 req := requests.NewTestRequest(rawReq)
193 for i := 0; i < b.N; i++ {
194 _, _, _ = set.MatchRequest(req)
195 }
196}
197
198func BenchmarkRuleSet_MatchRequest_Regexp2(b *testing.B) {
199 reg, err := regexp.Compile(`(?iU)\b(eval|system|exec|execute|passthru|shell_exec|phpinfo)\b`)

Callers

nothing calls this directly

Calls 4

NewRuleSetFunction · 0.92
NewTestRequestFunction · 0.92
InitMethod · 0.65
MatchRequestMethod · 0.45

Tested by

no test coverage detected