@@ -493,14 +493,16 @@ func TestCheckForAccidentalSettingReverts(t *testing.T) {
493
493
if err != nil {
494
494
t .Fatal (err )
495
495
}
496
- applyImplicitPrefs (newPrefs , tt .curPrefs , tt .curUser )
497
- var got string
498
- if err := checkForAccidentalSettingReverts (newPrefs , tt .curPrefs , upCheckEnv {
496
+ upEnv := upCheckEnv {
499
497
goos : goos ,
500
498
flagSet : flagSet ,
501
499
curExitNodeIP : tt .curExitNodeIP ,
502
500
distro : tt .distro ,
503
- }); err != nil {
501
+ user : tt .curUser ,
502
+ }
503
+ applyImplicitPrefs (newPrefs , tt .curPrefs , upEnv )
504
+ var got string
505
+ if err := checkForAccidentalSettingReverts (newPrefs , tt .curPrefs , upEnv ); err != nil {
504
506
got = err .Error ()
505
507
}
506
508
if strings .TrimSpace (got ) != tt .want {
@@ -784,6 +786,10 @@ func TestUpdatePrefs(t *testing.T) {
784
786
curPrefs * ipn.Prefs
785
787
env upCheckEnv // empty goos means "linux"
786
788
789
+ // checkUpdatePrefsMutations, if non-nil, is run with the new prefs after
790
+ // updatePrefs might've mutated them (from applyImplicitPrefs).
791
+ checkUpdatePrefsMutations func (t * testing.T , newPrefs * ipn.Prefs )
792
+
787
793
wantSimpleUp bool
788
794
wantJustEditMP * ipn.MaskedPrefs
789
795
wantErrSubtr string
@@ -885,6 +891,28 @@ func TestUpdatePrefs(t *testing.T) {
885
891
},
886
892
env : upCheckEnv {backendState : "Running" },
887
893
},
894
+ {
895
+ // Issue 3808: explicitly empty --operator= should clear value.
896
+ name : "explicit_empty_operator" ,
897
+ flags : []string {"--operator=" },
898
+ curPrefs : & ipn.Prefs {
899
+ ControlURL : "https://login.tailscale.com" ,
900
+ CorpDNS : true ,
901
+ AllowSingleHosts : true ,
902
+ NetfilterMode : preftype .NetfilterOn ,
903
+ OperatorUser : "somebody" ,
904
+ },
905
+ env : upCheckEnv {user : "somebody" , backendState : "Running" },
906
+ wantJustEditMP : & ipn.MaskedPrefs {
907
+ OperatorUserSet : true ,
908
+ WantRunningSet : true ,
909
+ },
910
+ checkUpdatePrefsMutations : func (t * testing.T , prefs * ipn.Prefs ) {
911
+ if prefs .OperatorUser != "" {
912
+ t .Errorf ("operator sent to backend should be empty; got %q" , prefs .OperatorUser )
913
+ }
914
+ },
915
+ },
888
916
}
889
917
for _ , tt := range tests {
890
918
t .Run (tt .name , func (t * testing.T ) {
@@ -909,6 +937,9 @@ func TestUpdatePrefs(t *testing.T) {
909
937
}
910
938
t .Fatal (err )
911
939
}
940
+ if tt .checkUpdatePrefsMutations != nil {
941
+ tt .checkUpdatePrefsMutations (t , newPrefs )
942
+ }
912
943
if simpleUp != tt .wantSimpleUp {
913
944
t .Fatalf ("simpleUp=%v, want %v" , simpleUp , tt .wantSimpleUp )
914
945
}
0 commit comments