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

Method Test

internal/waf/rule.go:385–740  ·  view source on GitHub ↗
(value any)

Source from the content-addressed store, hash-verified

383}
384
385func (this *Rule) Test(value any) bool {
386 // operator
387 switch this.Operator {
388 case RuleOperatorGt:
389 return types.Float64(value) > this.floatValue
390 case RuleOperatorGte:
391 return types.Float64(value) >= this.floatValue
392 case RuleOperatorLt:
393 return types.Float64(value) < this.floatValue
394 case RuleOperatorLte:
395 return types.Float64(value) <= this.floatValue
396 case RuleOperatorEq:
397 return types.Float64(value) == this.floatValue
398 case RuleOperatorNeq:
399 return types.Float64(value) != this.floatValue
400 case RuleOperatorEqString:
401 if this.IsCaseInsensitive {
402 return strings.EqualFold(this.stringifyValue(value), this.Value)
403 } else {
404 return this.stringifyValue(value) == this.Value
405 }
406 case RuleOperatorNeqString:
407 if this.IsCaseInsensitive {
408 return !strings.EqualFold(this.stringifyValue(value), this.Value)
409 } else {
410 return this.stringifyValue(value) != this.Value
411 }
412 case RuleOperatorMatch, RuleOperatorWildcardMatch:
413 if value == nil {
414 value = ""
415 }
416
417 // strings
418 stringList, ok := value.([]string)
419 if ok {
420 for _, s := range stringList {
421 if utils.MatchStringCache(this.reg, s, this.cacheLife) {
422 return true
423 }
424 }
425 return false
426 }
427
428 // bytes list
429 byteSlices, ok := value.([][]byte)
430 if ok {
431 for _, byteSlice := range byteSlices {
432 if utils.MatchBytesCache(this.reg, byteSlice, this.cacheLife) {
433 return true
434 }
435 }
436 return false
437 }
438
439 // bytes
440 byteSlice, ok := value.([]byte)
441 if ok {
442 return utils.MatchBytesCache(this.reg, byteSlice, this.cacheLife)

Callers 7

MatchRequestMethod · 0.95
MatchResponseMethod · 0.95
TestRule_MatchStarFunction · 0.95
TestRule_VersionFunction · 0.95
TestRule_IPFunction · 0.95
TestRule_TestFunction · 0.45
mainFunction · 0.45

Calls 14

stringifyValueMethod · 0.95
containsIPMethod · 0.95
ipToInt64Method · 0.95
MatchStringCacheFunction · 0.92
MatchBytesCacheFunction · 0.92
ContainsAnyWordRunesFunction · 0.92
ContainsAllWordsFunction · 0.92
DetectSQLInjectionCacheFunction · 0.92
DetectXSSCacheFunction · 0.92
ParseIPMethod · 0.80
ContainsMethod · 0.45
LenMethod · 0.45

Tested by 4

TestRule_MatchStarFunction · 0.76
TestRule_VersionFunction · 0.76
TestRule_IPFunction · 0.76
TestRule_TestFunction · 0.36