|
|
@@ -18,9 +18,11 @@ import (
|
|
|
"net"
|
|
|
"strings"
|
|
|
"testing"
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/go-kit/kit/log"
|
|
|
"github.com/kylelemons/godebug/pretty"
|
|
|
+ "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
|
|
|
|
|
"github.com/squat/kilo/pkg/wireguard"
|
|
|
)
|
|
|
@@ -29,17 +31,25 @@ func allowedIPs(ips ...string) string {
|
|
|
return strings.Join(ips, ", ")
|
|
|
}
|
|
|
|
|
|
-func mustParseCIDR(s string) (r *net.IPNet) {
|
|
|
+func mustParseCIDR(s string) (r net.IPNet) {
|
|
|
if _, ip, err := net.ParseCIDR(s); err != nil {
|
|
|
panic("failed to parse CIDR")
|
|
|
} else {
|
|
|
- r = ip
|
|
|
+ r = *ip
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func setup(t *testing.T) (map[string]*Node, map[string]*Peer, []byte, uint32) {
|
|
|
- key := []byte("private")
|
|
|
+var (
|
|
|
+ key1 = wgtypes.Key{'k', 'e', 'y', '1'}
|
|
|
+ key2 = wgtypes.Key{'k', 'e', 'y', '2'}
|
|
|
+ key3 = wgtypes.Key{'k', 'e', 'y', '3'}
|
|
|
+ key4 = wgtypes.Key{'k', 'e', 'y', '4'}
|
|
|
+ key5 = wgtypes.Key{'k', 'e', 'y', '5'}
|
|
|
+)
|
|
|
+
|
|
|
+func setup(t *testing.T) (map[string]*Node, map[string]*Peer, wgtypes.Key, int) {
|
|
|
+ key := wgtypes.Key{'p', 'r', 'i', 'v'}
|
|
|
e1 := &net.IPNet{IP: net.ParseIP("10.1.0.1").To4(), Mask: net.CIDRMask(16, 32)}
|
|
|
e2 := &net.IPNet{IP: net.ParseIP("10.1.0.2").To4(), Mask: net.CIDRMask(16, 32)}
|
|
|
e3 := &net.IPNet{IP: net.ParseIP("10.1.0.3").To4(), Mask: net.CIDRMask(16, 32)}
|
|
|
@@ -50,62 +60,63 @@ func setup(t *testing.T) (map[string]*Node, map[string]*Peer, []byte, uint32) {
|
|
|
nodes := map[string]*Node{
|
|
|
"a": {
|
|
|
Name: "a",
|
|
|
- Endpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e1.IP}, Port: DefaultKiloPort},
|
|
|
+ Endpoint: wireguard.NewEndpoint(e1.IP, DefaultKiloPort),
|
|
|
InternalIP: i1,
|
|
|
Location: "1",
|
|
|
Subnet: &net.IPNet{IP: net.ParseIP("10.2.1.0"), Mask: net.CIDRMask(24, 32)},
|
|
|
- Key: []byte("key1"),
|
|
|
+ Key: key1,
|
|
|
PersistentKeepalive: 25,
|
|
|
},
|
|
|
"b": {
|
|
|
Name: "b",
|
|
|
- Endpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e2.IP}, Port: DefaultKiloPort},
|
|
|
+ Endpoint: wireguard.NewEndpoint(e2.IP, DefaultKiloPort),
|
|
|
InternalIP: i1,
|
|
|
Location: "2",
|
|
|
Subnet: &net.IPNet{IP: net.ParseIP("10.2.2.0"), Mask: net.CIDRMask(24, 32)},
|
|
|
- Key: []byte("key2"),
|
|
|
- AllowedLocationIPs: []*net.IPNet{i3},
|
|
|
+ Key: key2,
|
|
|
+ AllowedLocationIPs: []net.IPNet{*i3},
|
|
|
},
|
|
|
"c": {
|
|
|
Name: "c",
|
|
|
- Endpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e3.IP}, Port: DefaultKiloPort},
|
|
|
+ Endpoint: wireguard.NewEndpoint(e3.IP, DefaultKiloPort),
|
|
|
InternalIP: i2,
|
|
|
// Same location as node b.
|
|
|
Location: "2",
|
|
|
Subnet: &net.IPNet{IP: net.ParseIP("10.2.3.0"), Mask: net.CIDRMask(24, 32)},
|
|
|
- Key: []byte("key3"),
|
|
|
+ Key: key3,
|
|
|
},
|
|
|
"d": {
|
|
|
Name: "d",
|
|
|
- Endpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e4.IP}, Port: DefaultKiloPort},
|
|
|
+ Endpoint: wireguard.NewEndpoint(e4.IP, DefaultKiloPort),
|
|
|
// Same location as node a, but without private IP
|
|
|
Location: "1",
|
|
|
Subnet: &net.IPNet{IP: net.ParseIP("10.2.4.0"), Mask: net.CIDRMask(24, 32)},
|
|
|
- Key: []byte("key4"),
|
|
|
+ Key: key4,
|
|
|
},
|
|
|
}
|
|
|
peers := map[string]*Peer{
|
|
|
"a": {
|
|
|
Name: "a",
|
|
|
Peer: wireguard.Peer{
|
|
|
- AllowedIPs: []*net.IPNet{
|
|
|
- {IP: net.ParseIP("10.5.0.1"), Mask: net.CIDRMask(24, 32)},
|
|
|
- {IP: net.ParseIP("10.5.0.2"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+ AllowedIPs: []net.IPNet{
|
|
|
+ {IP: net.ParseIP("10.5.0.1"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ {IP: net.ParseIP("10.5.0.2"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ },
|
|
|
+ PublicKey: key4,
|
|
|
},
|
|
|
- PublicKey: []byte("key4"),
|
|
|
},
|
|
|
},
|
|
|
"b": {
|
|
|
Name: "b",
|
|
|
Peer: wireguard.Peer{
|
|
|
- AllowedIPs: []*net.IPNet{
|
|
|
- {IP: net.ParseIP("10.5.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
- },
|
|
|
- Endpoint: &wireguard.Endpoint{
|
|
|
- DNSOrIP: wireguard.DNSOrIP{IP: net.ParseIP("192.168.0.1")},
|
|
|
- Port: DefaultKiloPort,
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+ AllowedIPs: []net.IPNet{
|
|
|
+ {IP: net.ParseIP("10.5.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ },
|
|
|
+ PublicKey: key5,
|
|
|
},
|
|
|
- PublicKey: []byte("key5"),
|
|
|
+ Endpoint: wireguard.NewEndpoint(net.ParseIP("192.168.0.1"), DefaultKiloPort),
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
@@ -138,7 +149,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardCIDR: &net.IPNet{IP: w1, Mask: net.CIDRMask(16, 32)},
|
|
|
segments: []*segment{
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["a"].Endpoint,
|
|
|
key: nodes["a"].Key,
|
|
|
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
|
|
@@ -149,7 +160,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardIP: w1,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, nodes["c"].Subnet, nodes["c"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, *nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["b"].Endpoint,
|
|
|
key: nodes["b"].Key,
|
|
|
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
|
|
@@ -161,7 +172,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
allowedLocationIPs: nodes["b"].AllowedLocationIPs,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["d"].Subnet, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["d"].Endpoint,
|
|
|
key: nodes["d"].Key,
|
|
|
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
|
|
@@ -189,7 +200,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardCIDR: &net.IPNet{IP: w2, Mask: net.CIDRMask(16, 32)},
|
|
|
segments: []*segment{
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["a"].Endpoint,
|
|
|
key: nodes["a"].Key,
|
|
|
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
|
|
@@ -200,7 +211,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardIP: w1,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, nodes["c"].Subnet, nodes["c"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, *nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["b"].Endpoint,
|
|
|
key: nodes["b"].Key,
|
|
|
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
|
|
@@ -212,7 +223,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
allowedLocationIPs: nodes["b"].AllowedLocationIPs,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["d"].Subnet, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["d"].Endpoint,
|
|
|
key: nodes["d"].Key,
|
|
|
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
|
|
@@ -240,7 +251,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardCIDR: DefaultKiloSubnet,
|
|
|
segments: []*segment{
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["a"].Endpoint,
|
|
|
key: nodes["a"].Key,
|
|
|
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
|
|
@@ -251,7 +262,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardIP: w1,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, nodes["c"].Subnet, nodes["c"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, *nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["b"].Endpoint,
|
|
|
key: nodes["b"].Key,
|
|
|
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
|
|
@@ -263,7 +274,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
allowedLocationIPs: nodes["b"].AllowedLocationIPs,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["d"].Subnet, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["d"].Endpoint,
|
|
|
key: nodes["d"].Key,
|
|
|
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
|
|
@@ -291,7 +302,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardCIDR: &net.IPNet{IP: w1, Mask: net.CIDRMask(16, 32)},
|
|
|
segments: []*segment{
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["a"].Endpoint,
|
|
|
key: nodes["a"].Key,
|
|
|
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
|
|
@@ -302,7 +313,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardIP: w1,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["b"].Endpoint,
|
|
|
key: nodes["b"].Key,
|
|
|
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
|
|
@@ -314,7 +325,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
allowedLocationIPs: nodes["b"].AllowedLocationIPs,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["c"].Subnet, nodes["c"].InternalIP, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["c"].Endpoint,
|
|
|
key: nodes["c"].Key,
|
|
|
persistentKeepalive: nodes["c"].PersistentKeepalive,
|
|
|
@@ -325,7 +336,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardIP: w3,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["d"].Subnet, {IP: w4, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w4, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["d"].Endpoint,
|
|
|
key: nodes["d"].Key,
|
|
|
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
|
|
@@ -353,7 +364,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardCIDR: &net.IPNet{IP: w2, Mask: net.CIDRMask(16, 32)},
|
|
|
segments: []*segment{
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["a"].Endpoint,
|
|
|
key: nodes["a"].Key,
|
|
|
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
|
|
@@ -364,7 +375,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardIP: w1,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["b"].Endpoint,
|
|
|
key: nodes["b"].Key,
|
|
|
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
|
|
@@ -376,7 +387,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
allowedLocationIPs: nodes["b"].AllowedLocationIPs,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["c"].Subnet, nodes["c"].InternalIP, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["c"].Endpoint,
|
|
|
key: nodes["c"].Key,
|
|
|
persistentKeepalive: nodes["c"].PersistentKeepalive,
|
|
|
@@ -387,7 +398,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardIP: w3,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["d"].Subnet, {IP: w4, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w4, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["d"].Endpoint,
|
|
|
key: nodes["d"].Key,
|
|
|
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
|
|
@@ -415,7 +426,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardCIDR: &net.IPNet{IP: w3, Mask: net.CIDRMask(16, 32)},
|
|
|
segments: []*segment{
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["a"].Endpoint,
|
|
|
key: nodes["a"].Key,
|
|
|
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
|
|
@@ -426,7 +437,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardIP: w1,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["b"].Endpoint,
|
|
|
key: nodes["b"].Key,
|
|
|
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
|
|
@@ -438,7 +449,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
allowedLocationIPs: nodes["b"].AllowedLocationIPs,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["c"].Subnet, nodes["c"].InternalIP, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["c"].Endpoint,
|
|
|
key: nodes["c"].Key,
|
|
|
persistentKeepalive: nodes["c"].PersistentKeepalive,
|
|
|
@@ -449,7 +460,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardIP: w3,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["d"].Subnet, {IP: w4, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w4, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["d"].Endpoint,
|
|
|
key: nodes["d"].Key,
|
|
|
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
|
|
@@ -477,7 +488,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardCIDR: &net.IPNet{IP: w4, Mask: net.CIDRMask(16, 32)},
|
|
|
segments: []*segment{
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["a"].Endpoint,
|
|
|
key: nodes["a"].Key,
|
|
|
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
|
|
@@ -488,7 +499,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardIP: w1,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["b"].Endpoint,
|
|
|
key: nodes["b"].Key,
|
|
|
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
|
|
@@ -500,7 +511,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
allowedLocationIPs: nodes["b"].AllowedLocationIPs,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["c"].Subnet, nodes["c"].InternalIP, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["c"].Endpoint,
|
|
|
key: nodes["c"].Key,
|
|
|
persistentKeepalive: nodes["c"].PersistentKeepalive,
|
|
|
@@ -511,7 +522,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
wireGuardIP: w3,
|
|
|
},
|
|
|
{
|
|
|
- allowedIPs: []*net.IPNet{nodes["d"].Subnet, {IP: w4, Mask: net.CIDRMask(32, 32)}},
|
|
|
+ allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w4, Mask: net.CIDRMask(32, 32)}},
|
|
|
endpoint: nodes["d"].Endpoint,
|
|
|
key: nodes["d"].Key,
|
|
|
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
|
|
@@ -539,7 +550,7 @@ func TestNewTopology(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func mustTopo(t *testing.T, nodes map[string]*Node, peers map[string]*Peer, granularity Granularity, hostname string, port uint32, key []byte, subnet *net.IPNet, persistentKeepalive int) *Topology {
|
|
|
+func mustTopo(t *testing.T, nodes map[string]*Node, peers map[string]*Peer, granularity Granularity, hostname string, port int, key wgtypes.Key, subnet *net.IPNet, persistentKeepalive time.Duration) *Topology {
|
|
|
topo, err := NewTopology(nodes, peers, granularity, hostname, port, key, subnet, persistentKeepalive, nil)
|
|
|
if err != nil {
|
|
|
t.Errorf("failed to generate Topology: %v", err)
|
|
|
@@ -547,211 +558,6 @@ func mustTopo(t *testing.T, nodes map[string]*Node, peers map[string]*Peer, gran
|
|
|
return topo
|
|
|
}
|
|
|
|
|
|
-func TestConf(t *testing.T) {
|
|
|
- nodes, peers, key, port := setup(t)
|
|
|
- for _, tc := range []struct {
|
|
|
- name string
|
|
|
- topology *Topology
|
|
|
- result string
|
|
|
- }{
|
|
|
- {
|
|
|
- name: "logical from a",
|
|
|
- topology: mustTopo(t, nodes, peers, LogicalGranularity, nodes["a"].Name, port, key, DefaultKiloSubnet, nodes["a"].PersistentKeepalive),
|
|
|
- result: `[Interface]
|
|
|
-PrivateKey = private
|
|
|
-ListenPort = 51820
|
|
|
-
|
|
|
-[Peer]
|
|
|
-PublicKey = key2
|
|
|
-Endpoint = 10.1.0.2:51820
|
|
|
-AllowedIPs = 10.2.2.0/24, 192.168.0.1/32, 10.2.3.0/24, 192.168.0.2/32, 10.4.0.2/32, 192.168.178.3/32
|
|
|
-PersistentKeepalive = 25
|
|
|
-
|
|
|
-[Peer]
|
|
|
-PublicKey = key4
|
|
|
-Endpoint = 10.1.0.4:51820
|
|
|
-AllowedIPs = 10.2.4.0/24, 10.4.0.3/32
|
|
|
-PersistentKeepalive = 25
|
|
|
-
|
|
|
-[Peer]
|
|
|
-PublicKey = key4
|
|
|
-AllowedIPs = 10.5.0.1/24, 10.5.0.2/24
|
|
|
-PersistentKeepalive = 25
|
|
|
-
|
|
|
-[Peer]
|
|
|
-PublicKey = key5
|
|
|
-Endpoint = 192.168.0.1:51820
|
|
|
-AllowedIPs = 10.5.0.3/24
|
|
|
-PersistentKeepalive = 25
|
|
|
-`,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "logical from b",
|
|
|
- topology: mustTopo(t, nodes, peers, LogicalGranularity, nodes["b"].Name, port, key, DefaultKiloSubnet, nodes["b"].PersistentKeepalive),
|
|
|
- result: `[Interface]
|
|
|
- PrivateKey = private
|
|
|
- ListenPort = 51820
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key1
|
|
|
- Endpoint = 10.1.0.1:51820
|
|
|
- AllowedIPs = 10.2.1.0/24, 192.168.0.1/32, 10.4.0.1/32
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key4
|
|
|
- Endpoint = 10.1.0.4:51820
|
|
|
- AllowedIPs = 10.2.4.0/24, 10.4.0.3/32
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key4
|
|
|
- AllowedIPs = 10.5.0.1/24, 10.5.0.2/24
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key5
|
|
|
- Endpoint = 192.168.0.1:51820
|
|
|
- AllowedIPs = 10.5.0.3/24
|
|
|
- `,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "logical from c",
|
|
|
- topology: mustTopo(t, nodes, peers, LogicalGranularity, nodes["c"].Name, port, key, DefaultKiloSubnet, nodes["c"].PersistentKeepalive),
|
|
|
- result: `[Interface]
|
|
|
- PrivateKey = private
|
|
|
- ListenPort = 51820
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key1
|
|
|
- Endpoint = 10.1.0.1:51820
|
|
|
- AllowedIPs = 10.2.1.0/24, 192.168.0.1/32, 10.4.0.1/32
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key4
|
|
|
- Endpoint = 10.1.0.4:51820
|
|
|
- AllowedIPs = 10.2.4.0/24, 10.4.0.3/32
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key4
|
|
|
- AllowedIPs = 10.5.0.1/24, 10.5.0.2/24
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key5
|
|
|
- Endpoint = 192.168.0.1:51820
|
|
|
- AllowedIPs = 10.5.0.3/24
|
|
|
- `,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "full from a",
|
|
|
- topology: mustTopo(t, nodes, peers, FullGranularity, nodes["a"].Name, port, key, DefaultKiloSubnet, nodes["a"].PersistentKeepalive),
|
|
|
- result: `[Interface]
|
|
|
- PrivateKey = private
|
|
|
- ListenPort = 51820
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key2
|
|
|
- Endpoint = 10.1.0.2:51820
|
|
|
- AllowedIPs = 10.2.2.0/24, 192.168.0.1/32, 10.4.0.2/32, 192.168.178.3/32
|
|
|
- PersistentKeepalive = 25
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key3
|
|
|
- Endpoint = 10.1.0.3:51820
|
|
|
- AllowedIPs = 10.2.3.0/24, 192.168.0.2/32, 10.4.0.3/32
|
|
|
- PersistentKeepalive = 25
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key4
|
|
|
- Endpoint = 10.1.0.4:51820
|
|
|
- AllowedIPs = 10.2.4.0/24, 10.4.0.4/32
|
|
|
- PersistentKeepalive = 25
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key4
|
|
|
- AllowedIPs = 10.5.0.1/24, 10.5.0.2/24
|
|
|
- PersistentKeepalive = 25
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key5
|
|
|
- Endpoint = 192.168.0.1:51820
|
|
|
- AllowedIPs = 10.5.0.3/24
|
|
|
- PersistentKeepalive = 25
|
|
|
- `,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "full from b",
|
|
|
- topology: mustTopo(t, nodes, peers, FullGranularity, nodes["b"].Name, port, key, DefaultKiloSubnet, nodes["b"].PersistentKeepalive),
|
|
|
- result: `[Interface]
|
|
|
- PrivateKey = private
|
|
|
- ListenPort = 51820
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key1
|
|
|
- Endpoint = 10.1.0.1:51820
|
|
|
- AllowedIPs = 10.2.1.0/24, 192.168.0.1/32, 10.4.0.1/32
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key3
|
|
|
- Endpoint = 10.1.0.3:51820
|
|
|
- AllowedIPs = 10.2.3.0/24, 192.168.0.2/32, 10.4.0.3/32
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key4
|
|
|
- Endpoint = 10.1.0.4:51820
|
|
|
- AllowedIPs = 10.2.4.0/24, 10.4.0.4/32
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key4
|
|
|
- AllowedIPs = 10.5.0.1/24, 10.5.0.2/24
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key5
|
|
|
- Endpoint = 192.168.0.1:51820
|
|
|
- AllowedIPs = 10.5.0.3/24
|
|
|
- `,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "full from c",
|
|
|
- topology: mustTopo(t, nodes, peers, FullGranularity, nodes["c"].Name, port, key, DefaultKiloSubnet, nodes["c"].PersistentKeepalive),
|
|
|
- result: `[Interface]
|
|
|
- PrivateKey = private
|
|
|
- ListenPort = 51820
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key1
|
|
|
- Endpoint = 10.1.0.1:51820
|
|
|
- AllowedIPs = 10.2.1.0/24, 192.168.0.1/32, 10.4.0.1/32
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key2
|
|
|
- Endpoint = 10.1.0.2:51820
|
|
|
- AllowedIPs = 10.2.2.0/24, 192.168.0.1/32, 10.4.0.2/32, 192.168.178.3/32
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key4
|
|
|
- Endpoint = 10.1.0.4:51820
|
|
|
- AllowedIPs = 10.2.4.0/24, 10.4.0.4/32
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key4
|
|
|
- AllowedIPs = 10.5.0.1/24, 10.5.0.2/24
|
|
|
-
|
|
|
- [Peer]
|
|
|
- PublicKey = key5
|
|
|
- Endpoint = 192.168.0.1:51820
|
|
|
- AllowedIPs = 10.5.0.3/24
|
|
|
- `,
|
|
|
- },
|
|
|
- } {
|
|
|
- conf := tc.topology.Conf()
|
|
|
- if !conf.Equal(wireguard.Parse([]byte(tc.result))) {
|
|
|
- buf, err := conf.Bytes()
|
|
|
- if err != nil {
|
|
|
- t.Errorf("test case %q: failed to render conf: %v", tc.name, err)
|
|
|
- }
|
|
|
- t.Errorf("test case %q: expected %s got %s", tc.name, tc.result, string(buf))
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
func TestFindLeader(t *testing.T) {
|
|
|
ip, e1, err := net.ParseCIDR("10.0.0.1/32")
|
|
|
if err != nil {
|
|
|
@@ -767,24 +573,24 @@ func TestFindLeader(t *testing.T) {
|
|
|
nodes := []*Node{
|
|
|
{
|
|
|
Name: "a",
|
|
|
- Endpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e1.IP}, Port: DefaultKiloPort},
|
|
|
+ Endpoint: wireguard.NewEndpoint(e1.IP, DefaultKiloPort),
|
|
|
},
|
|
|
{
|
|
|
Name: "b",
|
|
|
- Endpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e2.IP}, Port: DefaultKiloPort},
|
|
|
+ Endpoint: wireguard.NewEndpoint(e2.IP, DefaultKiloPort),
|
|
|
},
|
|
|
{
|
|
|
Name: "c",
|
|
|
- Endpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e2.IP}, Port: DefaultKiloPort},
|
|
|
+ Endpoint: wireguard.NewEndpoint(e2.IP, DefaultKiloPort),
|
|
|
},
|
|
|
{
|
|
|
Name: "d",
|
|
|
- Endpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e1.IP}, Port: DefaultKiloPort},
|
|
|
+ Endpoint: wireguard.NewEndpoint(e1.IP, DefaultKiloPort),
|
|
|
Leader: true,
|
|
|
},
|
|
|
{
|
|
|
Name: "2",
|
|
|
- Endpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e2.IP}, Port: DefaultKiloPort},
|
|
|
+ Endpoint: wireguard.NewEndpoint(e2.IP, DefaultKiloPort),
|
|
|
Leader: true,
|
|
|
},
|
|
|
}
|
|
|
@@ -840,31 +646,38 @@ func TestDeduplicatePeerIPs(t *testing.T) {
|
|
|
p1 := &Peer{
|
|
|
Name: "1",
|
|
|
Peer: wireguard.Peer{
|
|
|
- PublicKey: []byte("key1"),
|
|
|
- AllowedIPs: []*net.IPNet{
|
|
|
- {IP: net.ParseIP("10.0.0.1"), Mask: net.CIDRMask(24, 32)},
|
|
|
- {IP: net.ParseIP("10.0.0.2"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+
|
|
|
+ PublicKey: key1,
|
|
|
+ AllowedIPs: []net.IPNet{
|
|
|
+ {IP: net.ParseIP("10.0.0.1"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ {IP: net.ParseIP("10.0.0.2"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
p2 := &Peer{
|
|
|
Name: "2",
|
|
|
Peer: wireguard.Peer{
|
|
|
- PublicKey: []byte("key2"),
|
|
|
- AllowedIPs: []*net.IPNet{
|
|
|
- {IP: net.ParseIP("10.0.0.1"), Mask: net.CIDRMask(24, 32)},
|
|
|
- {IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+ PublicKey: key2,
|
|
|
+ AllowedIPs: []net.IPNet{
|
|
|
+ {IP: net.ParseIP("10.0.0.1"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ {IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
p3 := &Peer{
|
|
|
Name: "3",
|
|
|
Peer: wireguard.Peer{
|
|
|
- PublicKey: []byte("key3"),
|
|
|
- AllowedIPs: []*net.IPNet{
|
|
|
- {IP: net.ParseIP("10.0.0.2"), Mask: net.CIDRMask(24, 32)},
|
|
|
- {IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
- {IP: net.ParseIP("10.0.0.1"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+ PublicKey: key3,
|
|
|
+ AllowedIPs: []net.IPNet{
|
|
|
+ {IP: net.ParseIP("10.0.0.2"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ {IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ {IP: net.ParseIP("10.0.0.1"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
@@ -872,10 +685,12 @@ func TestDeduplicatePeerIPs(t *testing.T) {
|
|
|
p4 := &Peer{
|
|
|
Name: "4",
|
|
|
Peer: wireguard.Peer{
|
|
|
- PublicKey: []byte("key4"),
|
|
|
- AllowedIPs: []*net.IPNet{
|
|
|
- {IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
- {IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+ PublicKey: key4,
|
|
|
+ AllowedIPs: []net.IPNet{
|
|
|
+ {IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ {IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
@@ -898,9 +713,11 @@ func TestDeduplicatePeerIPs(t *testing.T) {
|
|
|
{
|
|
|
Name: "2",
|
|
|
Peer: wireguard.Peer{
|
|
|
- PublicKey: []byte("key2"),
|
|
|
- AllowedIPs: []*net.IPNet{
|
|
|
- {IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+ PublicKey: key2,
|
|
|
+ AllowedIPs: []net.IPNet{
|
|
|
+ {IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -914,9 +731,11 @@ func TestDeduplicatePeerIPs(t *testing.T) {
|
|
|
{
|
|
|
Name: "1",
|
|
|
Peer: wireguard.Peer{
|
|
|
- PublicKey: []byte("key1"),
|
|
|
- AllowedIPs: []*net.IPNet{
|
|
|
- {IP: net.ParseIP("10.0.0.2"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+ PublicKey: key1,
|
|
|
+ AllowedIPs: []net.IPNet{
|
|
|
+ {IP: net.ParseIP("10.0.0.2"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -930,19 +749,25 @@ func TestDeduplicatePeerIPs(t *testing.T) {
|
|
|
{
|
|
|
Name: "2",
|
|
|
Peer: wireguard.Peer{
|
|
|
- PublicKey: []byte("key2"),
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+ PublicKey: key2,
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
Name: "1",
|
|
|
Peer: wireguard.Peer{
|
|
|
- PublicKey: []byte("key1"),
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+ PublicKey: key1,
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
Name: "4",
|
|
|
Peer: wireguard.Peer{
|
|
|
- PublicKey: []byte("key4"),
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+ PublicKey: key4,
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -954,19 +779,23 @@ func TestDeduplicatePeerIPs(t *testing.T) {
|
|
|
{
|
|
|
Name: "4",
|
|
|
Peer: wireguard.Peer{
|
|
|
- PublicKey: []byte("key4"),
|
|
|
- AllowedIPs: []*net.IPNet{
|
|
|
- {IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+ PublicKey: key4,
|
|
|
+ AllowedIPs: []net.IPNet{
|
|
|
+ {IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
Name: "1",
|
|
|
Peer: wireguard.Peer{
|
|
|
- PublicKey: []byte("key1"),
|
|
|
- AllowedIPs: []*net.IPNet{
|
|
|
- {IP: net.ParseIP("10.0.0.1"), Mask: net.CIDRMask(24, 32)},
|
|
|
- {IP: net.ParseIP("10.0.0.2"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ PeerConfig: wgtypes.PeerConfig{
|
|
|
+ PublicKey: key1,
|
|
|
+ AllowedIPs: []net.IPNet{
|
|
|
+ {IP: net.ParseIP("10.0.0.1"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ {IP: net.ParseIP("10.0.0.2"), Mask: net.CIDRMask(24, 32)},
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -985,12 +814,12 @@ func TestFilterAllowedIPs(t *testing.T) {
|
|
|
topo := mustTopo(t, nodes, peers, LogicalGranularity, nodes["a"].Name, port, key, DefaultKiloSubnet, nodes["a"].PersistentKeepalive)
|
|
|
for _, tc := range []struct {
|
|
|
name string
|
|
|
- allowedLocationIPs map[int][]*net.IPNet
|
|
|
- result map[int][]*net.IPNet
|
|
|
+ allowedLocationIPs map[int][]net.IPNet
|
|
|
+ result map[int][]net.IPNet
|
|
|
}{
|
|
|
{
|
|
|
name: "nothing to filter",
|
|
|
- allowedLocationIPs: map[int][]*net.IPNet{
|
|
|
+ allowedLocationIPs: map[int][]net.IPNet{
|
|
|
0: {
|
|
|
mustParseCIDR("192.168.178.4/32"),
|
|
|
},
|
|
|
@@ -1002,7 +831,7 @@ func TestFilterAllowedIPs(t *testing.T) {
|
|
|
mustParseCIDR("192.168.178.7/32"),
|
|
|
},
|
|
|
},
|
|
|
- result: map[int][]*net.IPNet{
|
|
|
+ result: map[int][]net.IPNet{
|
|
|
0: {
|
|
|
mustParseCIDR("192.168.178.4/32"),
|
|
|
},
|
|
|
@@ -1017,7 +846,7 @@ func TestFilterAllowedIPs(t *testing.T) {
|
|
|
},
|
|
|
{
|
|
|
name: "intersections between segments",
|
|
|
- allowedLocationIPs: map[int][]*net.IPNet{
|
|
|
+ allowedLocationIPs: map[int][]net.IPNet{
|
|
|
0: {
|
|
|
mustParseCIDR("192.168.178.4/32"),
|
|
|
mustParseCIDR("192.168.178.8/32"),
|
|
|
@@ -1031,7 +860,7 @@ func TestFilterAllowedIPs(t *testing.T) {
|
|
|
mustParseCIDR("192.168.178.4/32"),
|
|
|
},
|
|
|
},
|
|
|
- result: map[int][]*net.IPNet{
|
|
|
+ result: map[int][]net.IPNet{
|
|
|
0: {
|
|
|
mustParseCIDR("192.168.178.8/32"),
|
|
|
},
|
|
|
@@ -1047,7 +876,7 @@ func TestFilterAllowedIPs(t *testing.T) {
|
|
|
},
|
|
|
{
|
|
|
name: "intersections with wireGuardCIDR",
|
|
|
- allowedLocationIPs: map[int][]*net.IPNet{
|
|
|
+ allowedLocationIPs: map[int][]net.IPNet{
|
|
|
0: {
|
|
|
mustParseCIDR("10.4.0.1/32"),
|
|
|
mustParseCIDR("192.168.178.8/32"),
|
|
|
@@ -1060,7 +889,7 @@ func TestFilterAllowedIPs(t *testing.T) {
|
|
|
mustParseCIDR("192.168.178.7/32"),
|
|
|
},
|
|
|
},
|
|
|
- result: map[int][]*net.IPNet{
|
|
|
+ result: map[int][]net.IPNet{
|
|
|
0: {
|
|
|
mustParseCIDR("192.168.178.8/32"),
|
|
|
},
|
|
|
@@ -1075,7 +904,7 @@ func TestFilterAllowedIPs(t *testing.T) {
|
|
|
},
|
|
|
{
|
|
|
name: "intersections with more than one allowedLocationIPs",
|
|
|
- allowedLocationIPs: map[int][]*net.IPNet{
|
|
|
+ allowedLocationIPs: map[int][]net.IPNet{
|
|
|
0: {
|
|
|
mustParseCIDR("192.168.178.8/32"),
|
|
|
},
|
|
|
@@ -1086,7 +915,7 @@ func TestFilterAllowedIPs(t *testing.T) {
|
|
|
mustParseCIDR("192.168.178.7/24"),
|
|
|
},
|
|
|
},
|
|
|
- result: map[int][]*net.IPNet{
|
|
|
+ result: map[int][]net.IPNet{
|
|
|
0: {},
|
|
|
1: {},
|
|
|
2: {
|