|
@@ -18,6 +18,7 @@ import (
|
|
"crypto/rand"
|
|
"crypto/rand"
|
|
"fmt"
|
|
"fmt"
|
|
"math/big"
|
|
"math/big"
|
|
|
|
+ "net"
|
|
"os"
|
|
"os"
|
|
"reflect"
|
|
"reflect"
|
|
"testing"
|
|
"testing"
|
|
@@ -312,11 +313,18 @@ func runRulesTests(t *testing.T, ipt *IPTables) {
|
|
t.Fatalf("StructuredStats failed: %v", err)
|
|
t.Fatalf("StructuredStats failed: %v", err)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // It's okay to not check the following errors as they will be evaluated
|
|
|
|
+ // in the subsequent usage
|
|
|
|
+ _, address1CIDR, _ := net.ParseCIDR(address1)
|
|
|
|
+ _, address2CIDR, _ := net.ParseCIDR(address2)
|
|
|
|
+ _, subnet1CIDR, _ := net.ParseCIDR(subnet1)
|
|
|
|
+ _, subnet2CIDR, _ := net.ParseCIDR(subnet2)
|
|
|
|
+
|
|
expectedStructStats := []Stat{
|
|
expectedStructStats := []Stat{
|
|
- {"0", "0", "ACCEPT", "all", opt, "*", "*", subnet1, address1, ""},
|
|
|
|
- {"0", "0", "ACCEPT", "all", opt, "*", "*", subnet2, address2, ""},
|
|
|
|
- {"0", "0", "ACCEPT", "all", opt, "*", "*", subnet2, address1, ""},
|
|
|
|
- {"0", "0", "ACCEPT", "all", opt, "*", "*", address1, subnet2, ""},
|
|
|
|
|
|
+ {0, 0, "ACCEPT", "all", opt, "*", "*", subnet1CIDR, address1CIDR, ""},
|
|
|
|
+ {0, 0, "ACCEPT", "all", opt, "*", "*", subnet2CIDR, address2CIDR, ""},
|
|
|
|
+ {0, 0, "ACCEPT", "all", opt, "*", "*", subnet2CIDR, address1CIDR, ""},
|
|
|
|
+ {0, 0, "ACCEPT", "all", opt, "*", "*", address1CIDR, subnet2CIDR, ""},
|
|
}
|
|
}
|
|
|
|
|
|
if !reflect.DeepEqual(structStats, expectedStructStats) {
|
|
if !reflect.DeepEqual(structStats, expectedStructStats) {
|
|
@@ -324,6 +332,17 @@ func runRulesTests(t *testing.T, ipt *IPTables) {
|
|
structStats, expectedStructStats)
|
|
structStats, expectedStructStats)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ for i, stat := range expectedStats {
|
|
|
|
+ stat, err := ipt.ParseStat(stat)
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatalf("ParseStat failed: %v", err)
|
|
|
|
+ }
|
|
|
|
+ if !reflect.DeepEqual(stat, expectedStructStats[i]) {
|
|
|
|
+ t.Fatalf("ParseStat mismatch: \ngot %#v \nneed %#v",
|
|
|
|
+ stat, expectedStructStats[i])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// Clear the chain that was created.
|
|
// Clear the chain that was created.
|
|
err = ipt.ClearChain("filter", chain)
|
|
err = ipt.ClearChain("filter", chain)
|
|
if err != nil {
|
|
if err != nil {
|