mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-29 03:30:24 +08:00
WAF动作支持有效范围
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
package waf
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"runtime"
|
||||
@@ -13,11 +14,11 @@ import (
|
||||
|
||||
func TestNewIPList(t *testing.T) {
|
||||
list := NewIPList()
|
||||
list.Add(IPTypeAll, "127.0.0.1", time.Now().Unix())
|
||||
list.Add(IPTypeAll, "127.0.0.2", time.Now().Unix()+1)
|
||||
list.Add(IPTypeAll, "127.0.0.1", time.Now().Unix()+2)
|
||||
list.Add(IPTypeAll, "127.0.0.3", time.Now().Unix()+3)
|
||||
list.Add(IPTypeAll, "127.0.0.10", time.Now().Unix()+10)
|
||||
list.Add(IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "127.0.0.1", time.Now().Unix())
|
||||
list.Add(IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "127.0.0.2", time.Now().Unix()+1)
|
||||
list.Add(IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "127.0.0.1", time.Now().Unix()+2)
|
||||
list.Add(IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "127.0.0.3", time.Now().Unix()+3)
|
||||
list.Add(IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "127.0.0.10", time.Now().Unix()+10)
|
||||
|
||||
var ticker = time.NewTicker(1 * time.Second)
|
||||
for range ticker.C {
|
||||
@@ -36,10 +37,10 @@ func TestIPList_Contains(t *testing.T) {
|
||||
list := NewIPList()
|
||||
|
||||
for i := 0; i < 1_0000; i++ {
|
||||
list.Add(IPTypeAll, "192.168.1."+strconv.Itoa(i), time.Now().Unix()+3600)
|
||||
list.Add(IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "192.168.1."+strconv.Itoa(i), time.Now().Unix()+3600)
|
||||
}
|
||||
a.IsTrue(list.Contains(IPTypeAll, "192.168.1.100"))
|
||||
a.IsFalse(list.Contains(IPTypeAll, "192.168.2.100"))
|
||||
a.IsTrue(list.Contains(IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "192.168.1.100"))
|
||||
a.IsFalse(list.Contains(IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "192.168.2.100"))
|
||||
}
|
||||
|
||||
func BenchmarkIPList_Add(b *testing.B) {
|
||||
@@ -47,7 +48,7 @@ func BenchmarkIPList_Add(b *testing.B) {
|
||||
|
||||
list := NewIPList()
|
||||
for i := 0; i < b.N; i++ {
|
||||
list.Add(IPTypeAll, "192.168.1."+strconv.Itoa(i), time.Now().Unix()+3600)
|
||||
list.Add(IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "192.168.1."+strconv.Itoa(i), time.Now().Unix()+3600)
|
||||
}
|
||||
b.Log(len(list.ipMap))
|
||||
}
|
||||
@@ -58,10 +59,10 @@ func BenchmarkIPList_Has(b *testing.B) {
|
||||
list := NewIPList()
|
||||
|
||||
for i := 0; i < 1_0000; i++ {
|
||||
list.Add(IPTypeAll, "192.168.1."+strconv.Itoa(i), time.Now().Unix()+3600)
|
||||
list.Add(IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "192.168.1."+strconv.Itoa(i), time.Now().Unix()+3600)
|
||||
}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
list.Contains(IPTypeAll, "192.168.1.100")
|
||||
list.Contains(IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "192.168.1.100")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user