mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-11 22:00:25 +08:00
增加IP动作
This commit is contained in:
81
internal/iplibrary/action_ipset_test.go
Normal file
81
internal/iplibrary/action_ipset_test.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package iplibrary
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestIPSetAction_Init(t *testing.T) {
|
||||
action := NewIPSetAction()
|
||||
err := action.Init(&firewallconfigs.FirewallActionConfig{
|
||||
Params: maps.Map{
|
||||
"path": "/usr/bin/iptables",
|
||||
"whiteName": "white-list",
|
||||
"blackName": "black-list",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("ok")
|
||||
}
|
||||
|
||||
func TestIPSetAction_AddItem(t *testing.T) {
|
||||
action := NewIPSetAction()
|
||||
action.config = &firewallconfigs.FirewallActionIPSetConfig{
|
||||
Path: "/usr/bin/iptables",
|
||||
WhiteName: "white-list",
|
||||
BlackName: "black-list",
|
||||
}
|
||||
{
|
||||
err := action.AddItem(IPListTypeWhite, &pb.IPItem{
|
||||
Type: "ipv4",
|
||||
Id: 1,
|
||||
IpFrom: "192.168.1.100",
|
||||
ExpiredAt: time.Now().Unix() + 30,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("ok")
|
||||
}
|
||||
|
||||
{
|
||||
err := action.AddItem(IPListTypeBlack, &pb.IPItem{
|
||||
Type: "ipv4",
|
||||
Id: 1,
|
||||
IpFrom: "192.168.1.100",
|
||||
ExpiredAt: time.Now().Unix() + 30,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("ok")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPSetAction_DeleteItem(t *testing.T) {
|
||||
action := NewIPSetAction()
|
||||
err := action.Init(&firewallconfigs.FirewallActionConfig{
|
||||
Params: maps.Map{
|
||||
"path": "/usr/bin/firewalld",
|
||||
"whiteName": "white-list",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = action.DeleteItem(IPListTypeWhite, &pb.IPItem{
|
||||
Type: "ipv4",
|
||||
Id: 1,
|
||||
IpFrom: "192.168.1.100",
|
||||
ExpiredAt: time.Now().Unix() + 30,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("ok")
|
||||
}
|
||||
Reference in New Issue
Block a user