76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package owrt
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
const (
|
|
ruleName = "Test"
|
|
ruleIndex = -1
|
|
ruleSrc = "10.10.10.10/24"
|
|
ruleTarget = "ACCEPT"
|
|
ruleProto = "tcp"
|
|
ruleDestPort = "80"
|
|
ruleSourcePort = "8080"
|
|
)
|
|
|
|
func TestFWRuleCreate(t *testing.T) {
|
|
exec := createMockExecutor("", "", 0)
|
|
uci := NewUCIWithExecutor(exec, "")
|
|
|
|
rule := NewUCIFirewallRule(uci)
|
|
rule.Name = ruleName
|
|
rule.Index = ruleIndex
|
|
rule.Src = ruleSrc
|
|
rule.Target = ruleTarget
|
|
rule.Proto = ruleProto
|
|
rule.DestPort = ruleDestPort
|
|
rule.SourcePort = ruleSourcePort
|
|
|
|
if rule.Create().ReturnCode != 0 {
|
|
t.Fatalf("UCIFirewallRule.Create() failed !")
|
|
}
|
|
}
|
|
|
|
func TestFWRuleUpdate(t *testing.T) {
|
|
exec := createMockExecutor("", "", 0)
|
|
uci := NewUCIWithExecutor(exec, "")
|
|
|
|
rule := NewUCIFirewallRule(uci)
|
|
rule.Name = ruleName
|
|
rule.Index = ruleIndex
|
|
rule.Src = ruleSrc
|
|
rule.Target = ruleTarget
|
|
rule.Proto = ruleProto
|
|
rule.DestPort = ruleDestPort
|
|
rule.SourcePort = ruleSourcePort
|
|
|
|
if rule.Create().ReturnCode != 0 {
|
|
t.Fatalf("UCIFirewallRule.Create() failed !")
|
|
}
|
|
|
|
rule.Name = "Tutu"
|
|
|
|
if rule.Update().ReturnCode != 0 {
|
|
t.Fatalf("UCIFirewallRule.Update() failed !")
|
|
}
|
|
}
|
|
|
|
func TestFWRuleDelete(t *testing.T) {
|
|
exec := createMockExecutor("", "", 0)
|
|
uci := NewUCIWithExecutor(exec, "")
|
|
|
|
rule := NewUCIFirewallRule(uci)
|
|
rule.Name = ruleName
|
|
rule.Index = ruleIndex
|
|
rule.Src = ruleSrc
|
|
rule.Target = ruleTarget
|
|
rule.Proto = ruleProto
|
|
rule.DestPort = ruleDestPort
|
|
rule.SourcePort = ruleSourcePort
|
|
|
|
if rule.Delete().ReturnCode != 0 {
|
|
t.Fatalf("UCIWirelessInterface.Delete() failed !")
|
|
}
|
|
}
|