cmd/vet: add subtestnames analyzer; fix all existing violations

Add a new vet analyzer that checks t.Run subtest names don't contain
characters requiring quoting when re-running via "go test -run". This
enforces the style guide rule: don't use spaces or punctuation in
subtest names.

The analyzer flags:
- Direct t.Run calls with string literal names containing spaces,
  regex metacharacters, quotes, or other problematic characters
- Table-driven t.Run(tt.name, ...) calls where tt ranges over a
  slice/map literal with bad name field values

Also fix all 978 existing violations across 81 test files, replacing
spaces with hyphens and shortening long sentence-like names to concise
hyphenated forms.

Updates #19242

Change-Id: Ib0ad96a111bd8e764582d1d4902fe2599454ab65
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2026-04-04 21:32:14 +00:00
committed by Brad Fitzpatrick
parent 0f02c20c5e
commit 5ef3713c9f
87 changed files with 1405 additions and 982 deletions
+1 -1
View File
@@ -63,7 +63,7 @@ func TestHandleC2NTLSCertStatus(t *testing.T) {
want *tailcfg.C2NTLSCertInfo
}{
{
name: "no domain",
name: "no-domain",
wantStatus: 400,
wantError: "no 'domain'\n",
},
+8 -4
View File
@@ -39,25 +39,29 @@ func TestCertRequest(t *testing.T) {
}
tests := []struct {
name string
domain string
wantSANs []string
}{
{
name: "example-com",
domain: "example.com",
wantSANs: []string{"example.com"},
},
{
name: "wildcard-example-com",
domain: "*.example.com",
wantSANs: []string{"*.example.com", "example.com"},
},
{
name: "wildcard-foo-bar-com",
domain: "*.foo.bar.com",
wantSANs: []string{"*.foo.bar.com", "foo.bar.com"},
},
}
for _, tt := range tests {
t.Run(tt.domain, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
csrDER, err := certRequest(key, tt.domain, nil)
if err != nil {
t.Fatalf("certRequest: %v", err)
@@ -365,19 +369,19 @@ func TestShouldStartDomainRenewal(t *testing.T) {
wantErr string
}{
{
name: "should renew",
name: "should-renew",
notBefore: now.AddDate(0, 0, -89),
lifetime: 90 * 24 * time.Hour,
want: true,
},
{
name: "short-lived renewal",
name: "short-lived-renewal",
notBefore: now.AddDate(0, 0, -7),
lifetime: 10 * 24 * time.Hour,
want: true,
},
{
name: "no renew",
name: "no-renew",
notBefore: now.AddDate(0, 0, -59), // 59 days ago == not 2/3rds of the way through 90 days yet
lifetime: 90 * 24 * time.Hour,
want: false,
+130 -92
View File
@@ -3035,20 +3035,20 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
lastSuggestedExitNode tailcfg.StableNodeID
}{
{
name: "ExitNodeID key is set",
name: "exitNodeID-set",
exitNodeIDKey: true,
exitNodeID: "123",
exitNodeIDWant: "123",
prefsChanged: true,
},
{
name: "ExitNodeID key not set",
name: "exitNodeID-not-set",
exitNodeIDKey: true,
exitNodeIDWant: "",
prefsChanged: false,
},
{
name: "ExitNodeID key set, ExitNodeIP preference set",
name: "exitNodeID-set-exitNodeIP-pref-set",
exitNodeIDKey: true,
exitNodeID: "123",
prefs: &ipn.Prefs{ExitNodeIP: netip.MustParseAddr("127.0.0.1")},
@@ -3056,7 +3056,7 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
prefsChanged: true,
},
{
name: "ExitNodeID key not set, ExitNodeIP key set",
name: "exitNodeID-not-set-exitNodeIP-set",
exitNodeIPKey: true,
exitNodeIP: "127.0.0.1",
prefs: &ipn.Prefs{ExitNodeIP: netip.MustParseAddr("127.0.0.1")},
@@ -3064,7 +3064,7 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
prefsChanged: false,
},
{
name: "ExitNodeIP key set, existing ExitNodeIP pref",
name: "exitNodeIP-set-existing-pref",
exitNodeIPKey: true,
exitNodeIP: "127.0.0.1",
prefs: &ipn.Prefs{ExitNodeIP: netip.MustParseAddr("127.0.0.1")},
@@ -3072,7 +3072,7 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
prefsChanged: false,
},
{
name: "existing preferences match policy",
name: "existing-prefs-match-policy",
exitNodeIDKey: true,
exitNodeID: "123",
prefs: &ipn.Prefs{ExitNodeID: tailcfg.StableNodeID("123")},
@@ -3080,7 +3080,8 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
prefsChanged: false,
},
{
name: "ExitNodeIP set if net map does not have corresponding node",
// ExitNodeIP is set when net map does not have a corresponding node.
name: "exitNodeIP-set-no-matching-node",
exitNodeIPKey: true,
prefs: &ipn.Prefs{ExitNodeIP: netip.MustParseAddr("127.0.0.1")},
exitNodeIP: "127.0.0.1",
@@ -3116,7 +3117,8 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
},
},
{
name: "ExitNodeIP cleared if net map has corresponding node - policy matches prefs",
// ExitNodeIP cleared when net map has corresponding node and policy matches prefs.
name: "exitNodeIP-cleared-matching-node-policy-matches",
prefs: &ipn.Prefs{ExitNodeIP: netip.MustParseAddr("127.0.0.1")},
exitNodeIPKey: true,
exitNodeIP: "127.0.0.1",
@@ -3156,7 +3158,8 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
},
},
{
name: "ExitNodeIP cleared if net map has corresponding node - no policy set",
// ExitNodeIP cleared when net map has corresponding node and no policy is set.
name: "exitNodeIP-cleared-matching-node-no-policy",
prefs: &ipn.Prefs{ExitNodeIP: netip.MustParseAddr("127.0.0.1")},
exitNodeIPWant: "",
exitNodeIDWant: "123",
@@ -3194,7 +3197,8 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
},
},
{
name: "ExitNodeIP cleared if net map has corresponding node - different exit node IP in policy",
// ExitNodeIP cleared when net map has corresponding node but policy has different exit node IP.
name: "exitNodeIP-cleared-matching-node-different-policy-IP",
exitNodeIPKey: true,
prefs: &ipn.Prefs{ExitNodeIP: netip.MustParseAddr("127.0.0.1")},
exitNodeIP: "100.64.5.6",
@@ -3234,7 +3238,7 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
},
},
{
name: "ExitNodeID key is set to auto:any and last suggested exit node is populated",
name: "exitNodeID-auto-any-last-suggested-populated",
exitNodeIDKey: true,
exitNodeID: "auto:any",
lastSuggestedExitNode: "123",
@@ -3243,7 +3247,7 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
prefsChanged: true,
},
{
name: "ExitNodeID key is set to auto:any and last suggested exit node is not populated",
name: "exitNodeID-auto-any-last-suggested-not-populated",
exitNodeIDKey: true,
exitNodeID: "auto:any",
exitNodeIDWant: "auto:any",
@@ -3251,7 +3255,7 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
prefsChanged: true,
},
{
name: "ExitNodeID key is set to auto:foo and last suggested exit node is populated",
name: "exitNodeID-auto-foo-last-suggested-populated",
exitNodeIDKey: true,
exitNodeID: "auto:foo",
lastSuggestedExitNode: "123",
@@ -3260,7 +3264,7 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
prefsChanged: true,
},
{
name: "ExitNodeID key is set to auto:foo and last suggested exit node is not populated",
name: "exitNodeID-auto-foo-last-suggested-not-populated",
exitNodeIDKey: true,
exitNodeID: "auto:foo",
exitNodeIDWant: "auto:any", // should be "auto:any" for compatibility with existing clients
@@ -3645,10 +3649,10 @@ func TestApplySysPolicy(t *testing.T) {
stringPolicies map[pkey.Key]string
}{
{
name: "empty prefs without policies",
name: "empty-prefs-no-policies",
},
{
name: "prefs set without policies",
name: "prefs-set-no-policies",
prefs: ipn.Prefs{
ControlURL: "1",
ShieldsUp: true,
@@ -3667,7 +3671,7 @@ func TestApplySysPolicy(t *testing.T) {
},
},
{
name: "empty prefs with policies",
name: "empty-prefs-with-policies",
wantPrefs: ipn.Prefs{
ControlURL: "1",
ShieldsUp: true,
@@ -3687,7 +3691,7 @@ func TestApplySysPolicy(t *testing.T) {
},
},
{
name: "prefs set with matching policies",
name: "prefs-set-matching-policies",
prefs: ipn.Prefs{
ControlURL: "1",
ShieldsUp: true,
@@ -3708,7 +3712,7 @@ func TestApplySysPolicy(t *testing.T) {
},
},
{
name: "prefs set with conflicting policies",
name: "prefs-set-conflicting-policies",
prefs: ipn.Prefs{
ControlURL: "1",
ShieldsUp: true,
@@ -3736,7 +3740,7 @@ func TestApplySysPolicy(t *testing.T) {
},
},
{
name: "prefs set with neutral policies",
name: "prefs-set-neutral-policies",
prefs: ipn.Prefs{
ControlURL: "1",
ShieldsUp: true,
@@ -3772,7 +3776,7 @@ func TestApplySysPolicy(t *testing.T) {
},
},
{
name: "enable AutoUpdate apply does not unset check",
name: "enable-apply-keeps-check",
prefs: ipn.Prefs{
AutoUpdate: ipn.AutoUpdatePrefs{
Check: true,
@@ -3791,7 +3795,7 @@ func TestApplySysPolicy(t *testing.T) {
},
},
{
name: "disable AutoUpdate apply does not unset check",
name: "disable-apply-keeps-check",
prefs: ipn.Prefs{
AutoUpdate: ipn.AutoUpdatePrefs{
Check: true,
@@ -3810,7 +3814,7 @@ func TestApplySysPolicy(t *testing.T) {
},
},
{
name: "enable AutoUpdate check does not unset apply",
name: "enable-check-keeps-apply",
prefs: ipn.Prefs{
AutoUpdate: ipn.AutoUpdatePrefs{
Check: false,
@@ -3829,7 +3833,7 @@ func TestApplySysPolicy(t *testing.T) {
},
},
{
name: "disable AutoUpdate check does not unset apply",
name: "disable-check-keeps-apply",
prefs: ipn.Prefs{
AutoUpdate: ipn.AutoUpdatePrefs{
Check: true,
@@ -3879,7 +3883,7 @@ func TestApplySysPolicy(t *testing.T) {
}
})
t.Run("status update", func(t *testing.T) {
t.Run("status-update", func(t *testing.T) {
// Profile manager fills in blank ControlURL but it's not set
// in most test cases to avoid cluttering them, so adjust for
// that.
@@ -3919,75 +3923,75 @@ func TestPreferencePolicyInfo(t *testing.T) {
policyError error
}{
{
name: "force enable modify",
name: "force-enable-modify",
initialValue: false,
wantValue: true,
wantChange: true,
policyValue: "always",
},
{
name: "force enable unchanged",
name: "force-enable-unchanged",
initialValue: true,
wantValue: true,
policyValue: "always",
},
{
name: "force disable modify",
name: "force-disable-modify",
initialValue: true,
wantValue: false,
wantChange: true,
policyValue: "never",
},
{
name: "force disable unchanged",
name: "force-disable-unchanged",
initialValue: false,
wantValue: false,
policyValue: "never",
},
{
name: "unforced enabled",
name: "unforced-enabled",
initialValue: true,
wantValue: true,
policyValue: "user-decides",
},
{
name: "unforced disabled",
name: "unforced-disabled",
initialValue: false,
wantValue: false,
policyValue: "user-decides",
},
{
name: "blank enabled",
name: "blank-enabled",
initialValue: true,
wantValue: true,
policyValue: "",
},
{
name: "blank disabled",
name: "blank-disabled",
initialValue: false,
wantValue: false,
policyValue: "",
},
{
name: "unset enabled",
name: "unset-enabled",
initialValue: true,
wantValue: true,
policyError: syspolicy.ErrNoSuchKey,
},
{
name: "unset disabled",
name: "unset-disabled",
initialValue: false,
wantValue: false,
policyError: syspolicy.ErrNoSuchKey,
},
{
name: "error enabled",
name: "error-enabled",
initialValue: true,
wantValue: true,
policyError: errors.New("test error"),
},
{
name: "error disabled",
name: "error-disabled",
initialValue: false,
wantValue: false,
policyError: errors.New("test error"),
@@ -4113,53 +4117,62 @@ func TestOnTailnetDefaultAutoUpdate(t *testing.T) {
func TestTCPHandlerForDst(t *testing.T) {
b := newTestBackend(t)
tests := []struct {
name string
desc string
dst string
intercept bool
}{
{
name: "100_100_100_100-port80",
desc: "intercept port 80 (Web UI) on quad100 IPv4",
dst: "100.100.100.100:80",
intercept: true,
},
{
name: "fd7a-115c-a1e0--53-port80",
desc: "intercept port 80 (Web UI) on quad100 IPv6",
dst: "[fd7a:115c:a1e0::53]:80",
intercept: true,
},
{
name: "100_100_103_100-port80",
desc: "don't intercept port 80 on local ip",
dst: "100.100.103.100:80",
intercept: false,
},
{
name: "fd7a-115c-a1e0--53-port8080",
desc: "intercept port 8080 (Taildrive) on quad100 IPv4",
dst: "[fd7a:115c:a1e0::53]:8080",
intercept: true,
},
{
name: "100_100_103_100-port8080",
desc: "don't intercept port 8080 on local ip",
dst: "100.100.103.100:8080",
intercept: false,
},
{
name: "100_100_100_100-port9080",
desc: "don't intercept port 9080 on quad100 IPv4",
dst: "100.100.100.100:9080",
intercept: false,
},
{
name: "fd7a-115c-a1e0--53-port9080",
desc: "don't intercept port 9080 on quad100 IPv6",
dst: "[fd7a:115c:a1e0::53]:9080",
intercept: false,
},
{
name: "100_100_103_100-port9080",
desc: "don't intercept port 9080 on local ip",
dst: "100.100.103.100:9080",
intercept: false,
},
}
for _, tt := range tests {
t.Run(tt.dst, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Log(tt.desc)
src := netip.MustParseAddrPort("100.100.102.100:51234")
h, _ := b.TCPHandlerForDst(src, netip.MustParseAddrPort(tt.dst))
@@ -4258,122 +4271,146 @@ func TestTCPHandlerForDstWithVIPService(t *testing.T) {
}
tests := []struct {
name string
desc string
dst string
intercept bool
}{
{
name: "100_100_100_100-port80",
desc: "intercept port 80 (Web UI) on quad100 IPv4",
dst: "100.100.100.100:80",
intercept: true,
},
{
name: "fd7a-115c-a1e0--53-port80",
desc: "intercept port 80 (Web UI) on quad100 IPv6",
dst: "[fd7a:115c:a1e0::53]:80",
intercept: true,
},
{
name: "100_100_103_100-port80",
desc: "don't intercept port 80 on local ip",
dst: "100.100.103.100:80",
intercept: false,
},
{
name: "100_100_100_100-port8080",
desc: "intercept port 8080 (Taildrive) on quad100 IPv4",
dst: "100.100.100.100:8080",
intercept: true,
},
{
name: "fd7a-115c-a1e0--53-port8080",
desc: "intercept port 8080 (Taildrive) on quad100 IPv6",
dst: "[fd7a:115c:a1e0::53]:8080",
intercept: true,
},
{
name: "100_100_103_100-port8080",
desc: "don't intercept port 8080 on local ip",
dst: "100.100.103.100:8080",
intercept: false,
},
{
name: "100_100_100_100-port9080",
desc: "don't intercept port 9080 on quad100 IPv4",
dst: "100.100.100.100:9080",
intercept: false,
},
{
name: "fd7a-115c-a1e0--53-port9080",
desc: "don't intercept port 9080 on quad100 IPv6",
dst: "[fd7a:115c:a1e0::53]:9080",
intercept: false,
},
{
name: "100_100_103_100-port9080",
desc: "don't intercept port 9080 on local ip",
dst: "100.100.103.100:9080",
intercept: false,
},
// VIP service destinations
{
name: "100_101_101_101-port882",
desc: "intercept port 882 (HTTP) on service foo IPv4",
dst: "100.101.101.101:882",
intercept: true,
},
{
name: "fd7a-115c-a1e0-ab12-4843-cd96-6565-6565-port882",
desc: "intercept port 882 (HTTP) on service foo IPv6",
dst: "[fd7a:115c:a1e0:ab12:4843:cd96:6565:6565]:882",
intercept: true,
},
{
name: "100_101_101_101-port883",
desc: "intercept port 883 (HTTPS) on service foo IPv4",
dst: "100.101.101.101:883",
intercept: true,
},
{
name: "fd7a-115c-a1e0-ab12-4843-cd96-6565-6565-port883",
desc: "intercept port 883 (HTTPS) on service foo IPv6",
dst: "[fd7a:115c:a1e0:ab12:4843:cd96:6565:6565]:883",
intercept: true,
},
{
name: "100_99_99_99-port990",
desc: "intercept port 990 (TCPForward) on service bar IPv4",
dst: "100.99.99.99:990",
intercept: true,
},
{
name: "fd7a-115c-a1e0-ab12-4843-cd96-626b-628b-port990",
desc: "intercept port 990 (TCPForward) on service bar IPv6",
dst: "[fd7a:115c:a1e0:ab12:4843:cd96:626b:628b]:990",
intercept: true,
},
{
name: "100_99_99_99-port990-terminateTLS",
desc: "intercept port 991 (TCPForward with TerminateTLS) on service bar IPv4",
dst: "100.99.99.99:990",
intercept: true,
},
{
name: "fd7a-115c-a1e0-ab12-4843-cd96-626b-628b-port990-terminateTLS",
desc: "intercept port 991 (TCPForward with TerminateTLS) on service bar IPv6",
dst: "[fd7a:115c:a1e0:ab12:4843:cd96:626b:628b]:990",
intercept: true,
},
{
name: "100_101_101_101-port4444",
desc: "don't intercept port 4444 on service foo IPv4",
dst: "100.101.101.101:4444",
intercept: false,
},
{
name: "fd7a-115c-a1e0-ab12-4843-cd96-6565-6565-port4444",
desc: "don't intercept port 4444 on service foo IPv6",
dst: "[fd7a:115c:a1e0:ab12:4843:cd96:6565:6565]:4444",
intercept: false,
},
{
name: "100_22_22_22-port883",
desc: "don't intercept port 600 on unknown service IPv4",
dst: "100.22.22.22:883",
intercept: false,
},
{
name: "fd7a-115c-a1e0-ab12-4843-cd96-626b-628b-port883",
desc: "don't intercept port 600 on unknown service IPv6",
dst: "[fd7a:115c:a1e0:ab12:4843:cd96:626b:628b]:883",
intercept: false,
},
{
name: "100_133_133_133-port600",
desc: "don't intercept port 600 (HTTPS) on service baz IPv4",
dst: "100.133.133.133:600",
intercept: false,
},
{
name: "fd7a-115c-a1e0-ab12-4843-cd96-8585-8585-port600",
desc: "don't intercept port 600 (HTTPS) on service baz IPv6",
dst: "[fd7a:115c:a1e0:ab12:4843:cd96:8585:8585]:600",
intercept: false,
@@ -4381,7 +4418,7 @@ func TestTCPHandlerForDstWithVIPService(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.dst, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Log(tt.desc)
src := netip.MustParseAddrPort("100.100.102.100:51234")
h, _ := b.TCPHandlerForDst(src, netip.MustParseAddrPort(tt.dst))
@@ -4664,14 +4701,14 @@ func TestRoundTraffic(t *testing.T) {
bytes int64
want float64
}{
{name: "under 5 bytes", bytes: 4, want: 4},
{name: "under 1000 bytes", bytes: 987, want: 990},
{name: "under 10_000 bytes", bytes: 8875, want: 8900},
{name: "under 100_000 bytes", bytes: 77777, want: 78000},
{name: "under 1_000_000 bytes", bytes: 666523, want: 670000},
{name: "under 10_000_000 bytes", bytes: 22556677, want: 23000000},
{name: "under 1_000_000_000 bytes", bytes: 1234234234, want: 1200000000},
{name: "under 1_000_000_000 bytes", bytes: 123423423499, want: 123400000000},
{name: "under-5B", bytes: 4, want: 4},
{name: "under-1000B", bytes: 987, want: 990},
{name: "under-10000B", bytes: 8875, want: 8900},
{name: "under-100000B", bytes: 77777, want: 78000},
{name: "under-1000000B", bytes: 666523, want: 670000},
{name: "under-10000000B", bytes: 22556677, want: 23000000},
{name: "under-1000000000B", bytes: 1234234234, want: 1200000000},
{name: "over-1000000000B", bytes: 123423423499, want: 123400000000},
}
for _, tt := range tests {
@@ -5033,7 +5070,7 @@ func TestSuggestExitNode(t *testing.T) {
wantError error
}{
{
name: "2 exit nodes in same region",
name: "2-exits-same-region",
lastReport: preferred1Report,
netMap: &netmap.NetworkMap{
SelfNode: selfNode.View(),
@@ -5051,7 +5088,7 @@ func TestSuggestExitNode(t *testing.T) {
wantID: "stable1",
},
{
name: "2 exit nodes different regions unknown latency",
name: "2-exits-different-regions-unknown-latency",
lastReport: noLatency1Report,
netMap: defaultNetmap,
wantRegions: []int{1, 3}, // the only regions with peers
@@ -5060,7 +5097,7 @@ func TestSuggestExitNode(t *testing.T) {
wantID: "stable2",
},
{
name: "2 derp based exit nodes, different regions, equal latency",
name: "2-derp-exits-different-regions-equal-latency",
lastReport: &netcheck.Report{
RegionLatency: map[int]time.Duration{
1: 10,
@@ -5083,7 +5120,7 @@ func TestSuggestExitNode(t *testing.T) {
wantID: "stable1",
},
{
name: "mullvad nodes, no derp based exit nodes",
name: "mullvad-no-derp-exits",
lastReport: noLatency1Report,
netMap: locationNetmap,
wantID: "stable5",
@@ -5091,7 +5128,7 @@ func TestSuggestExitNode(t *testing.T) {
wantName: "Dallas",
},
{
name: "nearby mullvad nodes with different priorities",
name: "nearby-mullvad-different-priorities",
lastReport: noLatency1Report,
netMap: &netmap.NetworkMap{
SelfNode: selfNode.View(),
@@ -5107,7 +5144,7 @@ func TestSuggestExitNode(t *testing.T) {
wantName: "Fort Worth",
},
{
name: "nearby mullvad nodes with same priorities",
name: "nearby-mullvad-same-priorities",
lastReport: noLatency1Report,
netMap: &netmap.NetworkMap{
SelfNode: selfNode.View(),
@@ -5124,7 +5161,7 @@ func TestSuggestExitNode(t *testing.T) {
wantName: "Dallas",
},
{
name: "mullvad nodes, remaining node is not in preferred derp",
name: "mullvad-remaining-not-in-preferred-derp",
lastReport: noLatency1Report,
netMap: &netmap.NetworkMap{
SelfNode: selfNode.View(),
@@ -5140,7 +5177,7 @@ func TestSuggestExitNode(t *testing.T) {
wantName: "peer4",
},
{
name: "no peers",
name: "no-peers",
lastReport: noLatency1Report,
netMap: &netmap.NetworkMap{
SelfNode: selfNode.View(),
@@ -5148,13 +5185,13 @@ func TestSuggestExitNode(t *testing.T) {
},
},
{
name: "nil report",
name: "nil-report",
lastReport: nil,
netMap: largeNetmap,
wantError: ErrNoPreferredDERP,
},
{
name: "no preferred derp region",
name: "no-preferred-derp-region",
lastReport: preferredNoneReport,
netMap: &netmap.NetworkMap{
SelfNode: selfNode.View(),
@@ -5163,13 +5200,13 @@ func TestSuggestExitNode(t *testing.T) {
wantError: ErrNoPreferredDERP,
},
{
name: "nil netmap",
name: "nil-netmap",
lastReport: noLatency1Report,
netMap: nil,
wantError: ErrNoPreferredDERP,
},
{
name: "nil derpmap",
name: "nil-derpmap",
lastReport: noLatency1Report,
netMap: &netmap.NetworkMap{
SelfNode: selfNode.View(),
@@ -5181,7 +5218,7 @@ func TestSuggestExitNode(t *testing.T) {
wantError: ErrNoPreferredDERP,
},
{
name: "missing suggestion capability",
name: "missing-suggestion-capability",
lastReport: noLatency1Report,
netMap: &netmap.NetworkMap{
SelfNode: selfNode.View(),
@@ -5193,7 +5230,7 @@ func TestSuggestExitNode(t *testing.T) {
},
},
{
name: "prefer last node",
name: "prefer-last-node",
lastReport: preferred1Report,
netMap: &netmap.NetworkMap{
SelfNode: selfNode.View(),
@@ -5212,7 +5249,7 @@ func TestSuggestExitNode(t *testing.T) {
wantID: "stable2",
},
{
name: "found better derp node",
name: "found-better-derp-node",
lastSuggestion: "stable3",
lastReport: preferred1Report,
netMap: defaultNetmap,
@@ -5220,7 +5257,7 @@ func TestSuggestExitNode(t *testing.T) {
wantName: "peer2",
},
{
name: "prefer last mullvad node",
name: "prefer-last-mullvad-node",
lastSuggestion: "stable2",
lastReport: preferred1Report,
netMap: &netmap.NetworkMap{
@@ -5238,7 +5275,7 @@ func TestSuggestExitNode(t *testing.T) {
wantLocation: dallas.View(),
},
{
name: "prefer better mullvad node",
name: "prefer-better-mullvad-node",
lastSuggestion: "stable2",
lastReport: preferred1Report,
netMap: &netmap.NetworkMap{
@@ -5256,7 +5293,7 @@ func TestSuggestExitNode(t *testing.T) {
wantLocation: fortWorth.View(),
},
{
name: "large netmap",
name: "large-netmap",
lastReport: preferred1Report,
netMap: largeNetmap,
wantNodes: []tailcfg.StableNodeID{"stable1", "stable2"},
@@ -5264,13 +5301,13 @@ func TestSuggestExitNode(t *testing.T) {
wantName: "peer2",
},
{
name: "no allowed suggestions",
name: "no-allowed-suggestions",
lastReport: preferred1Report,
netMap: largeNetmap,
allowPolicy: []tailcfg.StableNodeID{},
},
{
name: "only derp suggestions",
name: "only-derp-suggestions",
lastReport: preferred1Report,
netMap: largeNetmap,
allowPolicy: []tailcfg.StableNodeID{"stable1", "stable2", "stable3"},
@@ -5279,7 +5316,7 @@ func TestSuggestExitNode(t *testing.T) {
wantName: "peer2",
},
{
name: "only mullvad suggestions",
name: "only-mullvad-suggestions",
lastReport: preferred1Report,
netMap: largeNetmap,
allowPolicy: []tailcfg.StableNodeID{"stable5", "stable6", "stable7"},
@@ -5288,7 +5325,7 @@ func TestSuggestExitNode(t *testing.T) {
wantLocation: fortWorth.View(),
},
{
name: "only worst derp",
name: "only-worst-derp",
lastReport: preferred1Report,
netMap: largeNetmap,
allowPolicy: []tailcfg.StableNodeID{"stable3"},
@@ -5296,7 +5333,7 @@ func TestSuggestExitNode(t *testing.T) {
wantName: "peer3",
},
{
name: "only worst mullvad",
name: "only-worst-mullvad",
lastReport: preferred1Report,
netMap: largeNetmap,
allowPolicy: []tailcfg.StableNodeID{"stable6"},
@@ -5306,7 +5343,7 @@ func TestSuggestExitNode(t *testing.T) {
},
{
// Regression test for https://github.com/tailscale/tailscale/issues/17661
name: "exit nodes with no home DERP, randomly selected",
name: "exits-no-home-DERP-random-selection",
lastReport: &netcheck.Report{
RegionLatency: map[int]time.Duration{
1: 10,
@@ -5388,7 +5425,7 @@ func TestSuggestExitNodePickWeighted(t *testing.T) {
wantIDs []tailcfg.StableNodeID
}{
{
name: "different priorities",
name: "different-priorities",
candidates: []tailcfg.NodeView{
makePeer(2, withExitRoutes(), withLocation(location20.View())),
makePeer(3, withExitRoutes(), withLocation(location10.View())),
@@ -5396,7 +5433,7 @@ func TestSuggestExitNodePickWeighted(t *testing.T) {
wantIDs: []tailcfg.StableNodeID{"stable2"},
},
{
name: "same priorities",
name: "same-priorities",
candidates: []tailcfg.NodeView{
makePeer(2, withExitRoutes(), withLocation(location10.View())),
makePeer(3, withExitRoutes(), withLocation(location10.View())),
@@ -5404,11 +5441,11 @@ func TestSuggestExitNodePickWeighted(t *testing.T) {
wantIDs: []tailcfg.StableNodeID{"stable2", "stable3"},
},
{
name: "<1 candidates",
name: "lt1-candidates",
candidates: []tailcfg.NodeView{},
},
{
name: "1 candidate",
name: "1-candidate",
candidates: []tailcfg.NodeView{
makePeer(2, withExitRoutes(), withLocation(location20.View())),
},
@@ -5444,7 +5481,7 @@ func TestSuggestExitNodeLongLatDistance(t *testing.T) {
want float64
}{
{
name: "zero values",
name: "zero-values",
fromLat: 0,
fromLong: 0,
toLat: 0,
@@ -5452,7 +5489,7 @@ func TestSuggestExitNodeLongLatDistance(t *testing.T) {
want: 0,
},
{
name: "valid values",
name: "valid-values",
fromLat: 40.73061,
fromLong: -73.935242,
toLat: 37.3382082,
@@ -5460,7 +5497,8 @@ func TestSuggestExitNodeLongLatDistance(t *testing.T) {
want: 4117266.873301274,
},
{
name: "valid values, locations in north and south of equator",
// Locations in north and south of equator.
name: "valid-values-cross-equator",
fromLat: 40.73061,
fromLong: -73.935242,
toLat: -33.861481,
@@ -5865,13 +5903,13 @@ func TestMinLatencyDERPregion(t *testing.T) {
wantRegion int
}{
{
name: "regions, no latency values",
name: "regions-no-latency",
regions: []int{1, 2, 3},
wantRegion: 0,
report: &netcheck.Report{},
},
{
name: "regions, different latency values",
name: "regions-different-latency",
regions: []int{1, 2, 3},
wantRegion: 2,
report: &netcheck.Report{
@@ -5883,7 +5921,7 @@ func TestMinLatencyDERPregion(t *testing.T) {
},
},
{
name: "regions, same values",
name: "regions-same-latency",
regions: []int{1, 2, 3},
wantRegion: 1,
report: &netcheck.Report{
@@ -6030,7 +6068,7 @@ func TestFillAllowedSuggestions(t *testing.T) {
want: []tailcfg.StableNodeID{"one", "three", "four", "two"}, // order should not matter
},
{
name: "preserve case",
name: "preserve-case",
allowPolicy: []string{"ABC", "def", "gHiJ"},
want: []tailcfg.StableNodeID{"ABC", "def", "gHiJ"},
},
@@ -6184,61 +6222,61 @@ func TestNotificationTargetMatch(t *testing.T) {
wantMatch: false,
},
{
name: "FilterByUID+CID/Nil",
name: "FilterByUID-CID/Nil",
target: notificationTarget{userID: "S-1-5-21-1-2-3-4"},
actor: nil,
wantMatch: false,
},
{
name: "FilterByUID+CID/NoUID/NoCID",
name: "FilterByUID-CID/NoUID/NoCID",
target: notificationTarget{userID: "S-1-5-21-1-2-3-4", clientID: ipnauth.ClientIDFrom("A")},
actor: &ipnauth.TestActor{},
wantMatch: false,
},
{
name: "FilterByUID+CID/NoUID/SameCID",
name: "FilterByUID-CID/NoUID/SameCID",
target: notificationTarget{userID: "S-1-5-21-1-2-3-4", clientID: ipnauth.ClientIDFrom("A")},
actor: &ipnauth.TestActor{CID: ipnauth.ClientIDFrom("A")},
wantMatch: false,
},
{
name: "FilterByUID+CID/NoUID/DifferentCID",
name: "FilterByUID-CID/NoUID/DifferentCID",
target: notificationTarget{userID: "S-1-5-21-1-2-3-4", clientID: ipnauth.ClientIDFrom("A")},
actor: &ipnauth.TestActor{CID: ipnauth.ClientIDFrom("B")},
wantMatch: false,
},
{
name: "FilterByUID+CID/SameUID/NoCID",
name: "FilterByUID-CID/SameUID/NoCID",
target: notificationTarget{userID: "S-1-5-21-1-2-3-4", clientID: ipnauth.ClientIDFrom("A")},
actor: &ipnauth.TestActor{UID: "S-1-5-21-1-2-3-4"},
wantMatch: false,
},
{
name: "FilterByUID+CID/SameUID/SameCID",
name: "FilterByUID-CID/SameUID/SameCID",
target: notificationTarget{userID: "S-1-5-21-1-2-3-4", clientID: ipnauth.ClientIDFrom("A")},
actor: &ipnauth.TestActor{UID: "S-1-5-21-1-2-3-4", CID: ipnauth.ClientIDFrom("A")},
wantMatch: true,
},
{
name: "FilterByUID+CID/SameUID/DifferentCID",
name: "FilterByUID-CID/SameUID/DifferentCID",
target: notificationTarget{userID: "S-1-5-21-1-2-3-4", clientID: ipnauth.ClientIDFrom("A")},
actor: &ipnauth.TestActor{UID: "S-1-5-21-1-2-3-4", CID: ipnauth.ClientIDFrom("B")},
wantMatch: false,
},
{
name: "FilterByUID+CID/DifferentUID/NoCID",
name: "FilterByUID-CID/DifferentUID/NoCID",
target: notificationTarget{userID: "S-1-5-21-1-2-3-4", clientID: ipnauth.ClientIDFrom("A")},
actor: &ipnauth.TestActor{UID: "S-1-5-21-5-6-7-8"},
wantMatch: false,
},
{
name: "FilterByUID+CID/DifferentUID/SameCID",
name: "FilterByUID-CID/DifferentUID/SameCID",
target: notificationTarget{userID: "S-1-5-21-1-2-3-4", clientID: ipnauth.ClientIDFrom("A")},
actor: &ipnauth.TestActor{UID: "S-1-5-21-5-6-7-8", CID: ipnauth.ClientIDFrom("A")},
wantMatch: false,
},
{
name: "FilterByUID+CID/DifferentUID/DifferentCID",
name: "FilterByUID-CID/DifferentUID/DifferentCID",
target: notificationTarget{userID: "S-1-5-21-1-2-3-4", clientID: ipnauth.ClientIDFrom("A")},
actor: &ipnauth.TestActor{UID: "S-1-5-21-5-6-7-8", CID: ipnauth.ClientIDFrom("B")},
wantMatch: false,
+7 -7
View File
@@ -300,9 +300,9 @@ func TestTKASync(t *testing.T) {
}
tcs := []tkaSyncScenario{
{name: "up to date"},
{name: "up-to-date"},
{
name: "control has an update",
name: "control-has-an-update",
controlAUMs: func(t *testing.T, a *tka.Authority, storage tka.Chonk, signer tka.Signer) []tka.AUM {
b := a.NewUpdater(signer)
if err := b.RemoveKey(someKey.MustID()); err != nil {
@@ -317,7 +317,7 @@ func TestTKASync(t *testing.T) {
},
{
// AKA 'control data loss' scenario
name: "node has an update",
name: "node-has-an-update",
nodeAUMs: func(t *testing.T, a *tka.Authority, storage tka.Chonk, signer tka.Signer) []tka.AUM {
b := a.NewUpdater(signer)
if err := b.RemoveKey(someKey.MustID()); err != nil {
@@ -332,7 +332,7 @@ func TestTKASync(t *testing.T) {
},
{
// AKA 'control data loss + update in the meantime' scenario
name: "node and control diverge",
name: "node-and-control-diverge",
controlAUMs: func(t *testing.T, a *tka.Authority, storage tka.Chonk, signer tka.Signer) []tka.AUM {
b := a.NewUpdater(signer)
if err := b.SetKeyMeta(someKey.MustID(), map[string]string{"ye": "swiggity"}); err != nil {
@@ -1020,7 +1020,7 @@ func TestTKAAffectedSigs(t *testing.T) {
wantErr string
}{
{
"no error",
"no-error",
func() *tka.NodeKeySignature {
sig, _ := signNodeKey(tailcfg.TKASignInfo{NodePublic: nodePriv.Public()}, nlPriv)
return sig
@@ -1028,7 +1028,7 @@ func TestTKAAffectedSigs(t *testing.T) {
"",
},
{
"signature for different keyID",
"signature-for-different-keyID",
func() *tka.NodeKeySignature {
sig, _ := signNodeKey(tailcfg.TKASignInfo{NodePublic: nodePriv.Public()}, untrustedKey)
return sig
@@ -1036,7 +1036,7 @@ func TestTKAAffectedSigs(t *testing.T) {
fmt.Sprintf("got signature with keyID %X from request for %X", untrustedKey.KeyID(), nlPriv.KeyID()),
},
{
"invalid signature",
"invalid-signature",
func() *tka.NodeKeySignature {
sig, _ := signNodeKey(tailcfg.TKASignInfo{NodePublic: nodePriv.Public()}, nlPriv)
copy(sig.Signature, []byte{1, 2, 3, 4, 5, 6}) // overwrite with trash to invalid signature
+22 -22
View File
@@ -619,49 +619,49 @@ func TestServeHTTPProxyPath(t *testing.T) {
wantRequestPath string
}{
{
name: "/foo -> /foo, with mount point and path /foo",
name: "foo-to-foo-mount-foo",
mountPoint: "/foo",
proxyPath: "/foo",
requestPath: "/foo",
wantRequestPath: "/foo",
},
{
name: "/foo/ -> /foo/, with mount point and path /foo",
name: "foo-slash-to-foo-slash-mount-foo",
mountPoint: "/foo",
proxyPath: "/foo",
requestPath: "/foo/",
wantRequestPath: "/foo/",
},
{
name: "/foo -> /foo/, with mount point and path /foo/",
name: "foo-to-foo-slash-mount-foo-slash",
mountPoint: "/foo/",
proxyPath: "/foo/",
requestPath: "/foo",
wantRequestPath: "/foo/",
},
{
name: "/-> /, with mount point and path /",
name: "root-to-root-mount-root",
mountPoint: "/",
proxyPath: "/",
requestPath: "/",
wantRequestPath: "/",
},
{
name: "/foo -> /foo, with mount point and path /",
name: "foo-to-foo-mount-root",
mountPoint: "/",
proxyPath: "/",
requestPath: "/foo",
wantRequestPath: "/foo",
},
{
name: "/foo/bar -> /foo/bar, with mount point and path /foo",
name: "foo-bar-to-foo-bar-mount-foo",
mountPoint: "/foo",
proxyPath: "/foo",
requestPath: "/foo/bar",
wantRequestPath: "/foo/bar",
},
{
name: "/foo/bar/baz -> /foo/bar/baz, with mount point and path /foo",
name: "foo-bar-baz-to-foo-bar-baz-mount-foo",
mountPoint: "/foo",
proxyPath: "/foo",
requestPath: "/foo/bar/baz",
@@ -1457,7 +1457,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError bool
}{
{
name: "empty existing config",
name: "empty-existing-config",
description: "should be able to update with empty existing config",
existing: &ipn.ServeConfig{},
incoming: &ipn.ServeConfig{
@@ -1468,7 +1468,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: false,
},
{
name: "no existing config",
name: "no-existing-config",
description: "should be able to update with no existing config",
existing: nil,
incoming: &ipn.ServeConfig{
@@ -1479,7 +1479,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: false,
},
{
name: "empty incoming config",
name: "empty-incoming-config",
description: "wiping config should work",
existing: &ipn.ServeConfig{
TCP: map[uint16]*ipn.TCPPortHandler{
@@ -1490,7 +1490,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: false,
},
{
name: "no incoming config",
name: "no-incoming-config",
description: "missing incoming config should not result in an error",
existing: &ipn.ServeConfig{
TCP: map[uint16]*ipn.TCPPortHandler{
@@ -1501,7 +1501,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: false,
},
{
name: "non-overlapping update",
name: "non-overlapping-update",
description: "non-overlapping update should work",
existing: &ipn.ServeConfig{
TCP: map[uint16]*ipn.TCPPortHandler{
@@ -1516,7 +1516,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: false,
},
{
name: "overwriting background port",
name: "overwriting-background-port",
description: "should be able to overwrite a background port",
existing: &ipn.ServeConfig{
TCP: map[uint16]*ipn.TCPPortHandler{
@@ -1535,7 +1535,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: false,
},
{
name: "broken existing config",
name: "broken-existing-config",
description: "broken existing config should not prevent new config updates",
existing: &ipn.ServeConfig{
TCP: map[uint16]*ipn.TCPPortHandler{
@@ -1573,7 +1573,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: false,
},
{
name: "services same port as background",
name: "services-same-port-as-background",
description: "services should be able to use the same port as background listeners",
existing: &ipn.ServeConfig{
TCP: map[uint16]*ipn.TCPPortHandler{
@@ -1592,7 +1592,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: false,
},
{
name: "services tun mode",
name: "services-tun-mode",
description: "TUN mode should be mutually exclusive with TCP or web handlers for new Services",
existing: &ipn.ServeConfig{},
incoming: &ipn.ServeConfig{
@@ -1608,7 +1608,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: true,
},
{
name: "new foreground listener",
name: "new-foreground-listener",
description: "new foreground listeners must be on open ports",
existing: &ipn.ServeConfig{
TCP: map[uint16]*ipn.TCPPortHandler{
@@ -1627,7 +1627,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: true,
},
{
name: "new background listener",
name: "new-background-listener",
description: "new background listers cannot overwrite foreground listeners",
existing: &ipn.ServeConfig{
Foreground: map[string]*ipn.ServeConfig{
@@ -1646,7 +1646,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: true,
},
{
name: "serve type overwrite",
name: "serve-type-overwrite",
description: "incoming configuration cannot change the serve type in use by a port",
existing: &ipn.ServeConfig{
TCP: map[uint16]*ipn.TCPPortHandler{
@@ -1665,7 +1665,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: true,
},
{
name: "serve type overwrite services",
name: "serve-type-overwrite-services",
description: "incoming Services configuration cannot change the serve type in use by a port",
existing: &ipn.ServeConfig{
Services: map[tailcfg.ServiceName]*ipn.ServiceConfig{
@@ -1692,7 +1692,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: true,
},
{
name: "tun mode with handlers",
name: "tun-mode-with-handlers",
description: "Services cannot enable TUN mode if L4 or L7 handlers already exist",
existing: &ipn.ServeConfig{
Services: map[tailcfg.ServiceName]*ipn.ServiceConfig{
@@ -1720,7 +1720,7 @@ func TestValidateServeConfigUpdate(t *testing.T) {
wantError: true,
},
{
name: "handlers with tun mode",
name: "handlers-with-tun-mode",
description: "Services cannot add L4 or L7 handlers if TUN mode is already enabled",
existing: &ipn.ServeConfig{
Services: map[tailcfg.ServiceName]*ipn.ServiceConfig{
+5 -1
View File
@@ -23,26 +23,30 @@ import (
func TestExpandProxyArgUnix(t *testing.T) {
tests := []struct {
name string
input string
wantURL string
wantInsecure bool
}{
{
name: "unix-tmp-sock",
input: "unix:/tmp/test.sock",
wantURL: "unix:/tmp/test.sock",
},
{
name: "unix-var-run-docker-sock",
input: "unix:/var/run/docker.sock",
wantURL: "unix:/var/run/docker.sock",
},
{
name: "unix-relative-sock",
input: "unix:./relative.sock",
wantURL: "unix:./relative.sock",
},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
gotURL, gotInsecure := expandProxyArg(tt.input)
if gotURL != tt.wantURL {
t.Errorf("expandProxyArg(%q) url = %q, want %q", tt.input, gotURL, tt.wantURL)
+5 -5
View File
@@ -458,7 +458,7 @@ func TestPrefsFromBytesPreservesOldValues(t *testing.T) {
want: Prefs{ControlURL: "https://foo", RouteAll: true},
},
{
name: "opt.Bool", // test that we don't normalize it early
name: "opt-Bool", // test that we don't normalize it early
old: Prefs{Sync: "unset"},
json: []byte(`{}`),
want: Prefs{Sync: "unset"},
@@ -1236,13 +1236,13 @@ func TestParseAutoExitNodeString(t *testing.T) {
wantExpr ExitNodeExpression
}{
{
name: "empty expr",
name: "empty-expr",
exitNodeID: "",
wantOk: false,
wantExpr: "",
},
{
name: "no auto prefix",
name: "no-auto-prefix",
exitNodeID: "foo",
wantOk: false,
wantExpr: "",
@@ -1260,13 +1260,13 @@ func TestParseAutoExitNodeString(t *testing.T) {
wantExpr: "foo",
},
{
name: "auto prefix but empty suffix",
name: "auto-prefix-empty-suffix",
exitNodeID: "auto:",
wantOk: false,
wantExpr: "",
},
{
name: "auto prefix no colon",
name: "auto-prefix-no-colon",
exitNodeID: "auto",
wantOk: false,
wantExpr: "",
+2 -2
View File
@@ -283,11 +283,11 @@ func TestExpandProxyTargetDev(t *testing.T) {
wantErr bool
}{
{name: "port-only", input: "8080", expected: "http://127.0.0.1:8080"},
{name: "hostname+port", input: "localhost:8080", expected: "http://localhost:8080"},
{name: "hostname-and-port", input: "localhost:8080", expected: "http://localhost:8080"},
{name: "no-change", input: "http://127.0.0.1:8080", expected: "http://127.0.0.1:8080"},
{name: "include-path", input: "http://127.0.0.1:8080/foo", expected: "http://127.0.0.1:8080/foo"},
{name: "https-scheme", input: "https://localhost:8080", expected: "https://localhost:8080"},
{name: "https+insecure-scheme", input: "https+insecure://localhost:8080", expected: "https+insecure://localhost:8080"},
{name: "https-insecure-scheme", input: "https+insecure://localhost:8080", expected: "https+insecure://localhost:8080"},
{name: "change-default-scheme", input: "localhost:8080", defaultScheme: "https", expected: "https://localhost:8080"},
{name: "change-supported-schemes", input: "localhost:8080", defaultScheme: "tcp", supportedSchemes: []string{"tcp"}, expected: "tcp://localhost:8080"},
{name: "remote-target", input: "https://example.com:8080", expected: "https://example.com:8080"},