diff options
| author | Brad Fitzpatrick <bradfitz@tailscale.com> | 2022-06-16 13:49:11 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@tailscale.com> | 2022-06-16 13:53:57 -0700 |
| commit | 64bd0fc320fcd7a708bc290991def919895e53db (patch) | |
| tree | 8bba8e2b736bdc8b8463690505d582b198efc1c1 | |
| parent | 36ea837736a07ad3a0ab8fe5735be124aa200202 (diff) | |
| download | tailscale-bradfitz/explicit_empty_test_3808.tar.xz tailscale-bradfitz/explicit_empty_test_3808.zip | |
cmd/tailscale/cli: add failing test for empty --operator= value bugbradfitz/explicit_empty_test_3808
For #3808
Change-Id: I6e8709930f3e0211950157aecb88ad97beedc872
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
| -rw-r--r-- | cmd/tailscale/cli/cli_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/cmd/tailscale/cli/cli_test.go b/cmd/tailscale/cli/cli_test.go index c5546187c..210800360 100644 --- a/cmd/tailscale/cli/cli_test.go +++ b/cmd/tailscale/cli/cli_test.go @@ -784,6 +784,10 @@ func TestUpdatePrefs(t *testing.T) { curPrefs *ipn.Prefs env upCheckEnv // empty goos means "linux" + // checkUpdatePrefsMutations, if non-nil, is run with the new prefs after + // updatePrefs might've mutated them (from applyImplicitPrefs). + checkUpdatePrefsMutations func(t *testing.T, newPrefs *ipn.Prefs) + wantSimpleUp bool wantJustEditMP *ipn.MaskedPrefs wantErrSubtr string @@ -885,6 +889,28 @@ func TestUpdatePrefs(t *testing.T) { }, env: upCheckEnv{backendState: "Running"}, }, + { + // Issue 3808: explicitly empty --operator= should clear value. + name: "explicit_empty_operator", + flags: []string{"--operator="}, + curPrefs: &ipn.Prefs{ + ControlURL: "https://login.tailscale.com", + CorpDNS: true, + AllowSingleHosts: true, + NetfilterMode: preftype.NetfilterOn, + OperatorUser: "somebody", + }, + env: upCheckEnv{user: "somebody", backendState: "Running"}, + wantJustEditMP: &ipn.MaskedPrefs{ + OperatorUserSet: true, + WantRunningSet: true, + }, + checkUpdatePrefsMutations: func(t *testing.T, prefs *ipn.Prefs) { + if prefs.OperatorUser != "" { + t.Errorf("operator sent to backend should be empty; got %q", prefs.OperatorUser) + } + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -909,6 +935,9 @@ func TestUpdatePrefs(t *testing.T) { } t.Fatal(err) } + if tt.checkUpdatePrefsMutations != nil { + tt.checkUpdatePrefsMutations(t, newPrefs) + } if simpleUp != tt.wantSimpleUp { t.Fatalf("simpleUp=%v, want %v", simpleUp, tt.wantSimpleUp) } |
