2018-11-07 11:50:59 +01:00
|
|
|
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)
|
2018-11-07 16:36:45 +01:00
|
|
|
uci := NewUCIWithExecutor(exec, "")
|
2018-11-07 11:50:59 +01:00
|
|
|
|
2018-11-07 17:09:51 +01:00
|
|
|
rule := NewUCIFirewallRule(uci)
|
2018-11-07 11:50:59 +01:00
|
|
|
rule.Name = ruleName
|
|
|
|
rule.Index = ruleIndex
|
|
|
|
rule.Src = ruleSrc
|
|
|
|
rule.Target = ruleTarget
|
|
|
|
rule.Proto = ruleProto
|
|
|
|
rule.DestPort = ruleDestPort
|
|
|
|
rule.SourcePort = ruleSourcePort
|
|
|
|
|
2018-11-07 17:09:51 +01:00
|
|
|
if rule.Create().ReturnCode != 0 {
|
2018-11-07 11:50:59 +01:00
|
|
|
t.Fatalf("UCIFirewallRule.Create() failed !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFWRuleUpdate(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:09:51 +01:00
|
|
|
rule := NewUCIFirewallRule(uci)
|
2018-11-07 11:50:59 +01:00
|
|
|
rule.Name = ruleName
|
|
|
|
rule.Index = ruleIndex
|
|
|
|
rule.Src = ruleSrc
|
|
|
|
rule.Target = ruleTarget
|
|
|
|
rule.Proto = ruleProto
|
|
|
|
rule.DestPort = ruleDestPort
|
|
|
|
rule.SourcePort = ruleSourcePort
|
|
|
|
|
2018-11-07 17:09:51 +01:00
|
|
|
if rule.Create().ReturnCode != 0 {
|
2018-11-07 11:50:59 +01:00
|
|
|
t.Fatalf("UCIFirewallRule.Create() failed !")
|
|
|
|
}
|
|
|
|
|
|
|
|
rule.Name = "Tutu"
|
|
|
|
|
2018-11-07 17:09:51 +01:00
|
|
|
if rule.Update().ReturnCode != 0 {
|
2018-11-07 11:50:59 +01:00
|
|
|
t.Fatalf("UCIFirewallRule.Update() failed !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFWRuleDelete(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:09:51 +01:00
|
|
|
rule := NewUCIFirewallRule(uci)
|
2018-11-07 11:50:59 +01:00
|
|
|
rule.Name = ruleName
|
|
|
|
rule.Index = ruleIndex
|
|
|
|
rule.Src = ruleSrc
|
|
|
|
rule.Target = ruleTarget
|
|
|
|
rule.Proto = ruleProto
|
|
|
|
rule.DestPort = ruleDestPort
|
|
|
|
rule.SourcePort = ruleSourcePort
|
|
|
|
|
2018-11-07 17:09:51 +01:00
|
|
|
if rule.Delete().ReturnCode != 0 {
|
2018-11-07 11:50:59 +01:00
|
|
|
t.Fatalf("UCIWirelessInterface.Delete() failed !")
|
|
|
|
}
|
|
|
|
}
|