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

Function BenchmarkRuleSet_MatchRequest

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

Source from the content-addressed store, hash-verified

122}
123
124func 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
168func BenchmarkRuleSet_MatchRequest_Regexp(b *testing.B) {
169 runtime.GOMAXPROCS(1)

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