cmd/tailscale/cli: fix macOS crash reading envknob in init (#11667)

And add a test.

Regression from a5e1f7d703

Fixes tailscale/corp#19036

Change-Id: If90984049af0a4820c96e1f77ddf2fce8cb3043f

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/11451/head
Brad Fitzpatrick 8 months ago committed by GitHub
parent 0f3a292ebd
commit e6983baa73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -131,7 +131,7 @@ change in the future.
certCmd, certCmd,
netlockCmd, netlockCmd,
licensesCmd, licensesCmd,
exitNodeCmd, exitNodeCmd(),
updateCmd, updateCmd,
whoisCmd, whoisCmd,
}, },

@ -16,6 +16,7 @@ import (
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"tailscale.com/envknob"
"tailscale.com/health/healthmsg" "tailscale.com/health/healthmsg"
"tailscale.com/ipn" "tailscale.com/ipn"
"tailscale.com/ipn/ipnstate" "tailscale.com/ipn/ipnstate"
@ -33,6 +34,10 @@ import (
// and at least one thing that's not (darwin, freebsd). // and at least one thing that's not (darwin, freebsd).
var geese = []string{"linux", "darwin", "windows", "freebsd"} var geese = []string{"linux", "darwin", "windows", "freebsd"}
func TestPanicIfAnyEnvCheckedInInit(t *testing.T) {
envknob.PanicIfAnyEnvCheckedInInit()
}
// Test that checkForAccidentalSettingReverts's updateMaskedPrefsFromUpFlag can handle // Test that checkForAccidentalSettingReverts's updateMaskedPrefsFromUpFlag can handle
// all flags. This will panic if a new flag creeps in that's unhandled. // all flags. This will panic if a new flag creeps in that's unhandled.
// //

@ -20,45 +20,47 @@ import (
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
) )
var exitNodeCmd = &ffcli.Command{ func exitNodeCmd() *ffcli.Command {
Name: "exit-node", return &ffcli.Command{
ShortUsage: "exit-node [flags]", Name: "exit-node",
ShortHelp: "Show machines on your tailnet configured as exit nodes", ShortUsage: "exit-node [flags]",
LongHelp: "Show machines on your tailnet configured as exit nodes", ShortHelp: "Show machines on your tailnet configured as exit nodes",
Exec: func(context.Context, []string) error { LongHelp: "Show machines on your tailnet configured as exit nodes",
return errors.New("exit-node subcommand required; run 'tailscale exit-node -h' for details") Exec: func(context.Context, []string) error {
}, return errors.New("exit-node subcommand required; run 'tailscale exit-node -h' for details")
Subcommands: append([]*ffcli.Command{ },
{ Subcommands: append([]*ffcli.Command{
Name: "list", {
ShortUsage: "exit-node list [flags]", Name: "list",
ShortHelp: "Show exit nodes", ShortUsage: "exit-node list [flags]",
Exec: runExitNodeList, ShortHelp: "Show exit nodes",
FlagSet: (func() *flag.FlagSet { Exec: runExitNodeList,
fs := newFlagSet("list") FlagSet: (func() *flag.FlagSet {
fs.StringVar(&exitNodeArgs.filter, "filter", "", "filter exit nodes by country") fs := newFlagSet("list")
return fs fs.StringVar(&exitNodeArgs.filter, "filter", "", "filter exit nodes by country")
})(), return fs
}}, })(),
(func() []*ffcli.Command { }},
if !envknob.UseWIPCode() { (func() []*ffcli.Command {
return nil if !envknob.UseWIPCode() {
} return nil
return []*ffcli.Command{ }
{ return []*ffcli.Command{
Name: "connect", {
ShortUsage: "exit-node connect", Name: "connect",
ShortHelp: "connect to most recently used exit node", ShortUsage: "exit-node connect",
Exec: exitNodeSetUse(true), ShortHelp: "connect to most recently used exit node",
}, Exec: exitNodeSetUse(true),
{ },
Name: "disconnect", {
ShortUsage: "exit-node disconnect", Name: "disconnect",
ShortHelp: "disconnect from current exit node, if any", ShortUsage: "exit-node disconnect",
Exec: exitNodeSetUse(false), ShortHelp: "disconnect from current exit node, if any",
}, Exec: exitNodeSetUse(false),
} },
})()...), }
})()...),
}
} }
var exitNodeArgs struct { var exitNodeArgs struct {

Loading…
Cancel
Save