-
Notifications
You must be signed in to change notification settings - Fork 0
/
tailscale_test.go
91 lines (83 loc) · 2.09 KB
/
tailscale_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"net/netip"
"testing"
"github.com/google/go-cmp/cmp"
"tailscale.com/tailcfg"
"tailscale.com/types/netmap"
)
func TestProcessNetMap(t *testing.T) {
ts := &Tailscale{zone: "example.com"}
self := (&tailcfg.Node{
ComputedName: "self",
Addresses: []netip.Prefix{
netip.MustParsePrefix("100.0.0.1/24"),
netip.MustParsePrefix("fd7a:115c:a1e0::1/128"),
},
Tags: []string{"tag:cname-app"},
}).View()
nm := &netmap.NetworkMap{
SelfNode: self,
Peers: []tailcfg.NodeView{
(&tailcfg.Node{
ComputedName: "peer",
Addresses: []netip.Prefix{
netip.MustParsePrefix("100.0.0.2/24"),
netip.MustParsePrefix("fd7a:115c:a1e0::2/128"),
},
Tags: []string{"tag:cname-app"},
}).View(),
(&tailcfg.Node{
// shared node should be excluded
ComputedName: "shared",
Sharer: 1,
Addresses: []netip.Prefix{
netip.MustParsePrefix("100.0.0.3/24"),
netip.MustParsePrefix("fd7a:115c:a1e0::3/128"),
},
Tags: []string{"tag:cname-app"},
}).View(),
(&tailcfg.Node{
// mullvad exit node should be excluded
ComputedName: "mullvad",
IsWireGuardOnly: true,
Addresses: []netip.Prefix{
netip.MustParsePrefix("100.0.0.4/24"),
netip.MustParsePrefix("fd7a:115c:a1e0::4/128"),
},
Tags: []string{"tag:cname-app"},
}).View(),
},
}
want := map[string]map[string][]string{
"self": {
"A": {"100.0.0.1"},
"AAAA": {"fd7a:115c:a1e0::1"},
},
"peer": {
"A": {"100.0.0.2"},
"AAAA": {"fd7a:115c:a1e0::2"},
},
"app": {
"CNAME": {"self.example.com.", "peer.example.com."},
},
}
ts.processNetMap(nm)
if !cmp.Equal(ts.entries, want) {
t.Errorf("ts.entries = %v, want %v", ts.entries, want)
}
// now process another netmap with only self, and make sure peer is removed
ts.processNetMap(&netmap.NetworkMap{SelfNode: self})
want = map[string]map[string][]string{
"self": {
"A": {"100.0.0.1"},
"AAAA": {"fd7a:115c:a1e0::1"},
},
"app": {
"CNAME": {"self.example.com."},
},
}
if !cmp.Equal(ts.entries, want) {
t.Errorf("ts.entries = %v, want %v", ts.entries, want)
}
}