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)
|
2018-11-07 16:36:45 +01:00
|
|
|
uci := NewUCIWithExecutor(exec, "")
|
2018-11-07 11:50:59 +01:00
|
|
|
|
2018-11-07 17:17:57 +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
|
|
|
|
|
2018-11-07 17:17:57 +01:00
|
|
|
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)
|
2018-11-07 16:36:45 +01:00
|
|
|
uci := NewUCIWithExecutor(exec, "")
|
2018-11-07 11:50:59 +01:00
|
|
|
|
2018-11-07 17:17:57 +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
|
|
|
|
|
2018-11-07 17:17:57 +01:00
|
|
|
if redirect.Create().ReturnCode != 0 {
|
2018-11-07 11:50:59 +01:00
|
|
|
t.Fatalf("UCIFirewallRedirect.Create() failed !")
|
|
|
|
}
|
|
|
|
|
2018-11-07 16:36:45 +01:00
|
|
|
redirect.Name = "NewRedirect"
|
2018-11-07 11:50:59 +01:00
|
|
|
|
2018-11-07 17:17:57 +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)
|
2018-11-07 16:36:45 +01:00
|
|
|
uci := NewUCIWithExecutor(exec, "")
|
2018-11-07 11:50:59 +01:00
|
|
|
|
2018-11-07 17:17:57 +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
|
|
|
|
|
2018-11-07 17:17:57 +01:00
|
|
|
if redirect.Delete().ReturnCode != 0 {
|
2018-11-07 11:50:59 +01:00
|
|
|
t.Fatalf("UCIWirelessInterface.Delete() failed !")
|
|
|
|
}
|
|
|
|
}
|