owrt/uci_firewall_redirect_test.go

84 lines
2.1 KiB
Go
Raw Normal View History

2018-11-07 11:50:59 +01:00
package owrt
import (
"testing"
)
const (
redirectName = "Test"
redirectIndex = -1
redirectSrc = "10.10.10.10/24"
redirectTarget = "ACCEPT"
redirectProto = "tcp"
redirectSrcDIP = "1.1.1.1"
redirectSrcDPort = "333"
redirectDestIP = "10.10.10.10"
redirectDestPort = "22"
)
func TestFWRedirectCreate(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec, "")
2018-11-07 11:50:59 +01:00
redirect := NewUCIFirewallRedirect(uci)
2018-11-07 11:50:59 +01:00
redirect.Name = redirectName
redirect.Index = redirectIndex
redirect.Src = redirectSrc
redirect.Target = redirectTarget
redirect.Proto = redirectProto
redirect.SrcDIP = redirectSrcDIP
redirect.SrcDPort = redirectSrcDPort
redirect.DestIP = redirectDestIP
redirect.DestPort = redirectDestPort
if redirect.Create().ReturnCode != 0 {
2018-11-07 11:50:59 +01:00
t.Fatalf("UCIFirewallRedirect.Create() failed !")
}
}
func TestFWRedirectUpdate(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec, "")
2018-11-07 11:50:59 +01:00
redirect := NewUCIFirewallRedirect(uci)
2018-11-07 11:50:59 +01:00
redirect.Name = redirectName
redirect.Index = redirectIndex
redirect.Src = redirectSrc
redirect.Target = redirectTarget
redirect.Proto = redirectProto
redirect.SrcDIP = redirectSrcDIP
redirect.SrcDPort = redirectSrcDPort
redirect.DestIP = redirectDestIP
redirect.DestPort = redirectDestPort
if redirect.Create().ReturnCode != 0 {
2018-11-07 11:50:59 +01:00
t.Fatalf("UCIFirewallRedirect.Create() failed !")
}
redirect.Name = "NewRedirect"
2018-11-07 11:50:59 +01:00
if redirect.Update().ReturnCode != 0 {
2018-11-07 11:50:59 +01:00
t.Fatalf("UCIFirewallRedirect.Update() failed !")
}
}
func TestFWRedirectDelete(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec, "")
2018-11-07 11:50:59 +01:00
redirect := NewUCIFirewallRedirect(uci)
2018-11-07 11:50:59 +01:00
redirect.Name = redirectName
redirect.Index = redirectIndex
redirect.Src = redirectSrc
redirect.Target = redirectTarget
redirect.Proto = redirectProto
redirect.SrcDIP = redirectSrcDIP
redirect.SrcDPort = redirectSrcDPort
redirect.DestIP = redirectDestIP
redirect.DestPort = redirectDestPort
if redirect.Delete().ReturnCode != 0 {
2018-11-07 11:50:59 +01:00
t.Fatalf("UCIWirelessInterface.Delete() failed !")
}
}