mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-19 05:02:34 +00:00
cmd/tailscale: fix up --reset, again
Also fix a somewhat related printing bug in the process where some paths would print "Success." inconsistently even when there otherwise was no output (in the EditPrefs path) Fixes #3830 Updates #3702 (which broke it once while trying to fix it) Change-Id: Ic51e14526ad75be61ba00084670aa6a98221daa5 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
70d71ba1e7
commit
02bdc654d5
@ -794,7 +794,24 @@ func TestUpdatePrefs(t *testing.T) {
|
|||||||
Persist: &persist.Persist{LoginName: "crawshaw.github"},
|
Persist: &persist.Persist{LoginName: "crawshaw.github"},
|
||||||
},
|
},
|
||||||
env: upCheckEnv{backendState: "Running"},
|
env: upCheckEnv{backendState: "Running"},
|
||||||
wantJustEditMP: &ipn.MaskedPrefs{WantRunningSet: true},
|
wantJustEditMP: &ipn.MaskedPrefs{
|
||||||
|
AdvertiseRoutesSet: true,
|
||||||
|
AdvertiseTagsSet: true,
|
||||||
|
AllowSingleHostsSet: true,
|
||||||
|
ControlURLSet: true,
|
||||||
|
CorpDNSSet: true,
|
||||||
|
ExitNodeAllowLANAccessSet: true,
|
||||||
|
ExitNodeIDSet: true,
|
||||||
|
ExitNodeIPSet: true,
|
||||||
|
HostnameSet: true,
|
||||||
|
NetfilterModeSet: true,
|
||||||
|
NoSNATSet: true,
|
||||||
|
OperatorUserSet: true,
|
||||||
|
RouteAllSet: true,
|
||||||
|
RunSSHSet: true,
|
||||||
|
ShieldsUpSet: true,
|
||||||
|
WantRunningSet: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "control_synonym",
|
name: "control_synonym",
|
||||||
@ -860,16 +877,23 @@ func TestUpdatePrefs(t *testing.T) {
|
|||||||
if simpleUp != tt.wantSimpleUp {
|
if simpleUp != tt.wantSimpleUp {
|
||||||
t.Fatalf("simpleUp=%v, want %v", simpleUp, tt.wantSimpleUp)
|
t.Fatalf("simpleUp=%v, want %v", simpleUp, tt.wantSimpleUp)
|
||||||
}
|
}
|
||||||
|
var oldEditPrefs ipn.Prefs
|
||||||
if justEditMP != nil {
|
if justEditMP != nil {
|
||||||
|
oldEditPrefs = justEditMP.Prefs
|
||||||
justEditMP.Prefs = ipn.Prefs{} // uninteresting
|
justEditMP.Prefs = ipn.Prefs{} // uninteresting
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(justEditMP, tt.wantJustEditMP) {
|
if !reflect.DeepEqual(justEditMP, tt.wantJustEditMP) {
|
||||||
t.Fatalf("justEditMP: %v", cmp.Diff(justEditMP, tt.wantJustEditMP))
|
t.Logf("justEditMP != wantJustEditMP; following diff omits the Prefs field, which was %+v", oldEditPrefs)
|
||||||
|
t.Fatalf("justEditMP: %v\n\n: ", cmp.Diff(justEditMP, tt.wantJustEditMP, cmpIP))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cmpIP = cmp.Comparer(func(a, b netaddr.IP) bool {
|
||||||
|
return a == b
|
||||||
|
})
|
||||||
|
|
||||||
func TestExitNodeIPOfArg(t *testing.T) {
|
func TestExitNodeIPOfArg(t *testing.T) {
|
||||||
mustIP := netaddr.MustParseIP
|
mustIP := netaddr.MustParseIP
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
@ -387,7 +387,8 @@ func prefsFromUpArgs(upArgs upArgsT, warnf logger.Logf, st *ipnstate.Status, goo
|
|||||||
return prefs, nil
|
return prefs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// updatePrefs updates prefs based on curPrefs
|
// updatePrefs returns how to edit preferences based on the
|
||||||
|
// flag-provided 'prefs' and the currently active 'curPrefs'.
|
||||||
//
|
//
|
||||||
// It returns a non-nil justEditMP if we're already running and none of
|
// It returns a non-nil justEditMP if we're already running and none of
|
||||||
// the flags require a restart, so we can just do an EditPrefs call and
|
// the flags require a restart, so we can just do an EditPrefs call and
|
||||||
@ -424,11 +425,16 @@ func updatePrefs(prefs, curPrefs *ipn.Prefs, env upCheckEnv) (simpleUp bool, jus
|
|||||||
env.upArgs.authKeyOrFile == "" &&
|
env.upArgs.authKeyOrFile == "" &&
|
||||||
!controlURLChanged &&
|
!controlURLChanged &&
|
||||||
!tagsChanged
|
!tagsChanged
|
||||||
|
|
||||||
if justEdit {
|
if justEdit {
|
||||||
justEditMP = new(ipn.MaskedPrefs)
|
justEditMP = new(ipn.MaskedPrefs)
|
||||||
justEditMP.WantRunningSet = true
|
justEditMP.WantRunningSet = true
|
||||||
justEditMP.Prefs = *prefs
|
justEditMP.Prefs = *prefs
|
||||||
env.flagSet.Visit(func(f *flag.Flag) {
|
visitFlags := env.flagSet.Visit
|
||||||
|
if env.upArgs.reset {
|
||||||
|
visitFlags = env.flagSet.VisitAll
|
||||||
|
}
|
||||||
|
visitFlags(func(f *flag.Flag) {
|
||||||
updateMaskedPrefsFromUpFlag(justEditMP, f.Name)
|
updateMaskedPrefsFromUpFlag(justEditMP, f.Name)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -520,7 +526,7 @@ func runUp(ctx context.Context, args []string) error {
|
|||||||
pumpErr := make(chan error, 1)
|
pumpErr := make(chan error, 1)
|
||||||
go func() { pumpErr <- pump(pumpCtx, bc, c) }()
|
go func() { pumpErr <- pump(pumpCtx, bc, c) }()
|
||||||
|
|
||||||
printed := !simpleUp
|
var printed bool // whether we've yet printed anything to stdout or stderr
|
||||||
var loginOnce sync.Once
|
var loginOnce sync.Once
|
||||||
startLoginInteractive := func() { loginOnce.Do(func() { bc.StartLoginInteractive() }) }
|
startLoginInteractive := func() { loginOnce.Do(func() { bc.StartLoginInteractive() }) }
|
||||||
|
|
||||||
@ -546,7 +552,6 @@ func runUp(ctx context.Context, args []string) error {
|
|||||||
if s := n.State; s != nil {
|
if s := n.State; s != nil {
|
||||||
switch *s {
|
switch *s {
|
||||||
case ipn.NeedsLogin:
|
case ipn.NeedsLogin:
|
||||||
printed = true
|
|
||||||
startLoginInteractive()
|
startLoginInteractive()
|
||||||
case ipn.NeedsMachineAuth:
|
case ipn.NeedsMachineAuth:
|
||||||
printed = true
|
printed = true
|
||||||
|
@ -376,6 +376,7 @@ func (h *Harness) testDistro(t *testing.T, d Distro, ipm ipMapping) {
|
|||||||
t.Run("login", func(t *testing.T) {
|
t.Run("login", func(t *testing.T) {
|
||||||
runTestCommands(t, timeout, cli, []expect.Batcher{
|
runTestCommands(t, timeout, cli, []expect.Batcher{
|
||||||
&expect.BSnd{S: fmt.Sprintf("tailscale up --login-server=%s\n", loginServer)},
|
&expect.BSnd{S: fmt.Sprintf("tailscale up --login-server=%s\n", loginServer)},
|
||||||
|
&expect.BSnd{S: "echo Success.\n"},
|
||||||
&expect.BExp{R: `Success.`},
|
&expect.BExp{R: `Success.`},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user