2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2022-11-09 05:58:10 +00:00
|
|
|
|
|
|
|
package ipnlocal
|
|
|
|
|
|
|
|
import (
|
2022-11-17 14:05:02 +00:00
|
|
|
"fmt"
|
2023-04-15 00:13:06 +01:00
|
|
|
"os/user"
|
2023-02-07 05:18:21 +00:00
|
|
|
"strconv"
|
2022-11-09 05:58:10 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"tailscale.com/ipn"
|
|
|
|
"tailscale.com/ipn/store/mem"
|
2022-11-16 11:17:36 +00:00
|
|
|
"tailscale.com/tailcfg"
|
|
|
|
"tailscale.com/types/key"
|
2022-11-09 05:58:10 +00:00
|
|
|
"tailscale.com/types/logger"
|
|
|
|
"tailscale.com/types/persist"
|
|
|
|
)
|
|
|
|
|
2022-11-22 13:34:28 +00:00
|
|
|
func TestProfileCurrentUserSwitch(t *testing.T) {
|
|
|
|
store := new(mem.Store)
|
|
|
|
|
2023-01-31 01:28:13 +00:00
|
|
|
pm, err := newProfileManagerWithGOOS(store, logger.Discard, "linux")
|
2022-11-22 13:34:28 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
id := 0
|
|
|
|
newProfile := func(t *testing.T, loginName string) ipn.PrefsView {
|
|
|
|
id++
|
|
|
|
t.Helper()
|
|
|
|
pm.NewProfile()
|
|
|
|
p := pm.CurrentPrefs().AsStruct()
|
|
|
|
p.Persist = &persist.Persist{
|
|
|
|
NodeID: tailcfg.StableNodeID(fmt.Sprint(id)),
|
|
|
|
LoginName: loginName,
|
|
|
|
PrivateNodeKey: key.NewNode(),
|
|
|
|
UserProfile: tailcfg.UserProfile{
|
|
|
|
ID: tailcfg.UserID(id),
|
|
|
|
LoginName: loginName,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if err := pm.SetPrefs(p.View()); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return p.View()
|
|
|
|
}
|
|
|
|
|
2022-11-25 14:11:06 +00:00
|
|
|
pm.SetCurrentUserID("user1")
|
2022-11-22 13:34:28 +00:00
|
|
|
newProfile(t, "user1")
|
|
|
|
cp := pm.currentProfile
|
|
|
|
pm.DeleteProfile(cp.ID)
|
|
|
|
if pm.currentProfile == nil {
|
|
|
|
t.Fatal("currentProfile is nil")
|
|
|
|
} else if pm.currentProfile.ID != "" {
|
|
|
|
t.Fatalf("currentProfile.ID = %q, want empty", pm.currentProfile.ID)
|
|
|
|
}
|
2023-01-04 17:34:31 +00:00
|
|
|
if !pm.CurrentPrefs().Equals(defaultPrefs) {
|
2022-11-22 13:34:28 +00:00
|
|
|
t.Fatalf("CurrentPrefs() = %v, want emptyPrefs", pm.CurrentPrefs().Pretty())
|
|
|
|
}
|
|
|
|
|
2023-01-31 01:28:13 +00:00
|
|
|
pm, err = newProfileManagerWithGOOS(store, logger.Discard, "linux")
|
2022-11-22 13:34:28 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-11-25 14:11:06 +00:00
|
|
|
pm.SetCurrentUserID("user1")
|
2022-11-22 13:34:28 +00:00
|
|
|
if pm.currentProfile == nil {
|
|
|
|
t.Fatal("currentProfile is nil")
|
|
|
|
} else if pm.currentProfile.ID != "" {
|
|
|
|
t.Fatalf("currentProfile.ID = %q, want empty", pm.currentProfile.ID)
|
|
|
|
}
|
2023-01-04 17:34:31 +00:00
|
|
|
if !pm.CurrentPrefs().Equals(defaultPrefs) {
|
2022-11-22 13:34:28 +00:00
|
|
|
t.Fatalf("CurrentPrefs() = %v, want emptyPrefs", pm.CurrentPrefs().Pretty())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-22 07:02:16 +00:00
|
|
|
func TestProfileList(t *testing.T) {
|
|
|
|
store := new(mem.Store)
|
|
|
|
|
2023-01-31 01:28:13 +00:00
|
|
|
pm, err := newProfileManagerWithGOOS(store, logger.Discard, "linux")
|
2022-11-22 07:02:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
id := 0
|
|
|
|
newProfile := func(t *testing.T, loginName string) ipn.PrefsView {
|
|
|
|
id++
|
|
|
|
t.Helper()
|
|
|
|
pm.NewProfile()
|
|
|
|
p := pm.CurrentPrefs().AsStruct()
|
|
|
|
p.Persist = &persist.Persist{
|
|
|
|
NodeID: tailcfg.StableNodeID(fmt.Sprint(id)),
|
|
|
|
LoginName: loginName,
|
|
|
|
PrivateNodeKey: key.NewNode(),
|
|
|
|
UserProfile: tailcfg.UserProfile{
|
|
|
|
ID: tailcfg.UserID(id),
|
|
|
|
LoginName: loginName,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if err := pm.SetPrefs(p.View()); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return p.View()
|
|
|
|
}
|
|
|
|
checkProfiles := func(t *testing.T, want ...string) {
|
|
|
|
t.Helper()
|
|
|
|
got := pm.Profiles()
|
|
|
|
if len(got) != len(want) {
|
|
|
|
t.Fatalf("got %d profiles, want %d", len(got), len(want))
|
|
|
|
}
|
|
|
|
for i, w := range want {
|
|
|
|
if got[i].Name != w {
|
|
|
|
t.Errorf("got profile %d name %q, want %q", i, got[i].Name, w)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-25 14:11:06 +00:00
|
|
|
pm.SetCurrentUserID("user1")
|
2022-11-22 07:02:16 +00:00
|
|
|
newProfile(t, "alice")
|
|
|
|
newProfile(t, "bob")
|
|
|
|
checkProfiles(t, "alice", "bob")
|
|
|
|
|
2022-11-25 14:11:06 +00:00
|
|
|
pm.SetCurrentUserID("user2")
|
2022-11-22 07:02:16 +00:00
|
|
|
checkProfiles(t)
|
|
|
|
newProfile(t, "carol")
|
|
|
|
carol := pm.currentProfile
|
|
|
|
checkProfiles(t, "carol")
|
|
|
|
|
2022-11-25 14:11:06 +00:00
|
|
|
pm.SetCurrentUserID("user1")
|
2022-11-22 07:02:16 +00:00
|
|
|
checkProfiles(t, "alice", "bob")
|
|
|
|
if lp := pm.findProfileByKey(carol.Key); lp != nil {
|
|
|
|
t.Fatalf("found profile for user2 in user1's profile list")
|
|
|
|
}
|
|
|
|
if lp := pm.findProfileByName(carol.Name); lp != nil {
|
|
|
|
t.Fatalf("found profile for user2 in user1's profile list")
|
|
|
|
}
|
2022-11-29 23:16:01 +00:00
|
|
|
if lp := pm.findProfilesByNodeID(carol.ControlURL, carol.NodeID); lp != nil {
|
2022-11-22 07:02:16 +00:00
|
|
|
t.Fatalf("found profile for user2 in user1's profile list")
|
|
|
|
}
|
2022-11-29 23:16:01 +00:00
|
|
|
if lp := pm.findProfilesByUserID(carol.ControlURL, carol.UserProfile.ID); lp != nil {
|
2022-11-22 07:02:16 +00:00
|
|
|
t.Fatalf("found profile for user2 in user1's profile list")
|
|
|
|
}
|
|
|
|
|
2022-11-25 14:11:06 +00:00
|
|
|
pm.SetCurrentUserID("user2")
|
2022-11-22 07:02:16 +00:00
|
|
|
checkProfiles(t, "carol")
|
2022-11-29 23:16:01 +00:00
|
|
|
if lp := pm.findProfilesByNodeID(carol.ControlURL, carol.NodeID); lp == nil {
|
|
|
|
t.Fatalf("did not find profile for user2 in user2's profile list")
|
|
|
|
}
|
|
|
|
if lp := pm.findProfilesByUserID(carol.ControlURL, carol.UserProfile.ID); lp == nil {
|
|
|
|
t.Fatalf("did not find profile for user2 in user2's profile list")
|
|
|
|
}
|
|
|
|
|
2022-11-22 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 05:58:10 +00:00
|
|
|
// TestProfileManagement tests creating, loading, and switching profiles.
|
|
|
|
func TestProfileManagement(t *testing.T) {
|
|
|
|
store := new(mem.Store)
|
|
|
|
|
2023-01-31 01:28:13 +00:00
|
|
|
pm, err := newProfileManagerWithGOOS(store, logger.Discard, "linux")
|
2022-11-09 05:58:10 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
wantCurProfile := ""
|
|
|
|
wantProfiles := map[string]ipn.PrefsView{
|
2023-01-04 17:34:31 +00:00
|
|
|
"": defaultPrefs,
|
2022-11-09 05:58:10 +00:00
|
|
|
}
|
|
|
|
checkProfiles := func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
prof := pm.CurrentProfile()
|
|
|
|
t.Logf("\tCurrentProfile = %q", prof)
|
|
|
|
if prof.Name != wantCurProfile {
|
|
|
|
t.Fatalf("CurrentProfile = %q; want %q", prof, wantCurProfile)
|
|
|
|
}
|
|
|
|
profiles := pm.Profiles()
|
|
|
|
wantLen := len(wantProfiles)
|
|
|
|
if _, ok := wantProfiles[""]; ok {
|
|
|
|
wantLen--
|
|
|
|
}
|
|
|
|
if len(profiles) != wantLen {
|
|
|
|
t.Fatalf("Profiles = %v; want %v", profiles, wantProfiles)
|
|
|
|
}
|
|
|
|
p := pm.CurrentPrefs()
|
|
|
|
if !p.Valid() {
|
|
|
|
t.Fatalf("CurrentPrefs = %v; want valid", p)
|
|
|
|
}
|
|
|
|
if !p.Equals(wantProfiles[wantCurProfile]) {
|
|
|
|
t.Fatalf("CurrentPrefs = %v; want %v", p.Pretty(), wantProfiles[wantCurProfile].Pretty())
|
|
|
|
}
|
|
|
|
for _, p := range profiles {
|
|
|
|
got, err := pm.loadSavedPrefs(p.Key)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// Use Hostname as a proxy for all prefs.
|
2022-11-16 11:17:36 +00:00
|
|
|
if !got.Equals(wantProfiles[p.Name]) {
|
|
|
|
t.Fatalf("Prefs for profile %q =\n got=%+v\nwant=%v", p, got.Pretty(), wantProfiles[p.Name].Pretty())
|
2022-11-09 05:58:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-16 11:17:36 +00:00
|
|
|
logins := make(map[string]tailcfg.UserID)
|
2022-11-17 14:05:02 +00:00
|
|
|
nodeIDs := make(map[string]tailcfg.StableNodeID)
|
2022-11-09 05:58:10 +00:00
|
|
|
setPrefs := func(t *testing.T, loginName string) ipn.PrefsView {
|
2022-11-16 11:17:36 +00:00
|
|
|
t.Helper()
|
2022-11-09 05:58:10 +00:00
|
|
|
p := pm.CurrentPrefs().AsStruct()
|
2022-11-17 14:05:02 +00:00
|
|
|
uid := logins[loginName]
|
|
|
|
if uid.IsZero() {
|
|
|
|
uid = tailcfg.UserID(len(logins) + 1)
|
|
|
|
logins[loginName] = uid
|
|
|
|
}
|
|
|
|
nid := nodeIDs[loginName]
|
|
|
|
if nid.IsZero() {
|
|
|
|
nid = tailcfg.StableNodeID(fmt.Sprint(len(nodeIDs) + 1))
|
|
|
|
nodeIDs[loginName] = nid
|
2022-11-16 11:17:36 +00:00
|
|
|
}
|
2022-11-09 05:58:10 +00:00
|
|
|
p.Persist = &persist.Persist{
|
2022-11-16 11:17:36 +00:00
|
|
|
LoginName: loginName,
|
|
|
|
PrivateNodeKey: key.NewNode(),
|
|
|
|
UserProfile: tailcfg.UserProfile{
|
2022-11-17 14:05:02 +00:00
|
|
|
ID: uid,
|
2022-11-16 11:17:36 +00:00
|
|
|
LoginName: loginName,
|
|
|
|
},
|
2022-11-17 14:05:02 +00:00
|
|
|
NodeID: nid,
|
2022-11-09 05:58:10 +00:00
|
|
|
}
|
|
|
|
if err := pm.SetPrefs(p.View()); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return p.View()
|
|
|
|
}
|
|
|
|
t.Logf("Check initial state from empty store")
|
|
|
|
checkProfiles(t)
|
|
|
|
|
|
|
|
{
|
|
|
|
t.Logf("Set prefs for default profile")
|
|
|
|
wantProfiles["user@1.example.com"] = setPrefs(t, "user@1.example.com")
|
|
|
|
wantCurProfile = "user@1.example.com"
|
|
|
|
delete(wantProfiles, "")
|
|
|
|
}
|
|
|
|
checkProfiles(t)
|
|
|
|
|
|
|
|
t.Logf("Create new profile")
|
|
|
|
pm.NewProfile()
|
|
|
|
wantCurProfile = ""
|
2023-01-04 17:34:31 +00:00
|
|
|
wantProfiles[""] = defaultPrefs
|
2022-11-09 05:58:10 +00:00
|
|
|
checkProfiles(t)
|
|
|
|
|
|
|
|
{
|
|
|
|
t.Logf("Set prefs for test profile")
|
|
|
|
wantProfiles["user@2.example.com"] = setPrefs(t, "user@2.example.com")
|
|
|
|
wantCurProfile = "user@2.example.com"
|
|
|
|
delete(wantProfiles, "")
|
|
|
|
}
|
|
|
|
checkProfiles(t)
|
|
|
|
|
|
|
|
t.Logf("Recreate profile manager from store")
|
|
|
|
// Recreate the profile manager to ensure that it can load the profiles
|
|
|
|
// from the store at startup.
|
2023-01-31 01:28:13 +00:00
|
|
|
pm, err = newProfileManagerWithGOOS(store, logger.Discard, "linux")
|
2022-11-09 05:58:10 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
checkProfiles(t)
|
|
|
|
|
|
|
|
t.Logf("Delete default profile")
|
|
|
|
if err := pm.DeleteProfile(pm.findProfileByName("user@1.example.com").ID); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
delete(wantProfiles, "user@1.example.com")
|
|
|
|
checkProfiles(t)
|
|
|
|
|
|
|
|
t.Logf("Recreate profile manager from store after deleting default profile")
|
|
|
|
// Recreate the profile manager to ensure that it can load the profiles
|
|
|
|
// from the store at startup.
|
2023-01-31 01:28:13 +00:00
|
|
|
pm, err = newProfileManagerWithGOOS(store, logger.Discard, "linux")
|
2022-11-09 05:58:10 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
checkProfiles(t)
|
2022-11-16 11:17:36 +00:00
|
|
|
|
2022-11-17 14:05:02 +00:00
|
|
|
t.Logf("Create new profile - 2")
|
2022-11-16 11:17:36 +00:00
|
|
|
pm.NewProfile()
|
|
|
|
wantCurProfile = ""
|
2023-01-04 17:34:31 +00:00
|
|
|
wantProfiles[""] = defaultPrefs
|
2022-11-16 11:17:36 +00:00
|
|
|
checkProfiles(t)
|
|
|
|
|
|
|
|
t.Logf("Login with the existing profile")
|
|
|
|
wantProfiles["user@2.example.com"] = setPrefs(t, "user@2.example.com")
|
|
|
|
delete(wantProfiles, "")
|
|
|
|
wantCurProfile = "user@2.example.com"
|
|
|
|
checkProfiles(t)
|
2022-11-17 14:05:02 +00:00
|
|
|
|
|
|
|
t.Logf("Tag the current the profile")
|
|
|
|
nodeIDs["tagged-node.2.ts.net"] = nodeIDs["user@2.example.com"]
|
|
|
|
wantProfiles["tagged-node.2.ts.net"] = setPrefs(t, "tagged-node.2.ts.net")
|
|
|
|
delete(wantProfiles, "user@2.example.com")
|
|
|
|
wantCurProfile = "tagged-node.2.ts.net"
|
|
|
|
checkProfiles(t)
|
|
|
|
|
|
|
|
t.Logf("Relogin")
|
|
|
|
wantProfiles["user@2.example.com"] = setPrefs(t, "user@2.example.com")
|
|
|
|
delete(wantProfiles, "tagged-node.2.ts.net")
|
|
|
|
wantCurProfile = "user@2.example.com"
|
|
|
|
checkProfiles(t)
|
2022-11-09 05:58:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestProfileManagementWindows tests going into and out of Unattended mode on
|
|
|
|
// Windows.
|
|
|
|
func TestProfileManagementWindows(t *testing.T) {
|
2023-04-15 00:13:06 +01:00
|
|
|
u, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2023-04-14 19:09:21 +01:00
|
|
|
}
|
2023-04-15 00:13:06 +01:00
|
|
|
uid := ipn.WindowsUserID(u.Uid)
|
2023-04-14 19:09:21 +01:00
|
|
|
|
2022-11-09 05:58:10 +00:00
|
|
|
store := new(mem.Store)
|
|
|
|
|
2023-01-31 01:28:13 +00:00
|
|
|
pm, err := newProfileManagerWithGOOS(store, logger.Discard, "windows")
|
2022-11-09 05:58:10 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
wantCurProfile := ""
|
|
|
|
wantProfiles := map[string]ipn.PrefsView{
|
2023-01-04 17:34:31 +00:00
|
|
|
"": defaultPrefs,
|
2022-11-09 05:58:10 +00:00
|
|
|
}
|
|
|
|
checkProfiles := func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
prof := pm.CurrentProfile()
|
|
|
|
t.Logf("\tCurrentProfile = %q", prof)
|
|
|
|
if prof.Name != wantCurProfile {
|
|
|
|
t.Fatalf("CurrentProfile = %q; want %q", prof, wantCurProfile)
|
|
|
|
}
|
|
|
|
if p := pm.CurrentPrefs(); !p.Equals(wantProfiles[wantCurProfile]) {
|
|
|
|
t.Fatalf("CurrentPrefs = %+v; want %+v", p.Pretty(), wantProfiles[wantCurProfile].Pretty())
|
|
|
|
}
|
|
|
|
}
|
2022-11-16 11:17:36 +00:00
|
|
|
logins := make(map[string]tailcfg.UserID)
|
2022-11-09 05:58:10 +00:00
|
|
|
setPrefs := func(t *testing.T, loginName string, forceDaemon bool) ipn.PrefsView {
|
2022-11-16 11:17:36 +00:00
|
|
|
id := logins[loginName]
|
|
|
|
if id.IsZero() {
|
|
|
|
id = tailcfg.UserID(len(logins) + 1)
|
|
|
|
logins[loginName] = id
|
|
|
|
}
|
2022-11-09 05:58:10 +00:00
|
|
|
p := pm.CurrentPrefs().AsStruct()
|
|
|
|
p.ForceDaemon = forceDaemon
|
|
|
|
p.Persist = &persist.Persist{
|
|
|
|
LoginName: loginName,
|
2022-11-16 11:17:36 +00:00
|
|
|
UserProfile: tailcfg.UserProfile{
|
|
|
|
ID: id,
|
|
|
|
LoginName: loginName,
|
|
|
|
},
|
2023-02-07 05:18:21 +00:00
|
|
|
NodeID: tailcfg.StableNodeID(strconv.Itoa(int(id))),
|
2022-11-09 05:58:10 +00:00
|
|
|
}
|
|
|
|
if err := pm.SetPrefs(p.View()); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return p.View()
|
|
|
|
}
|
|
|
|
t.Logf("Check initial state from empty store")
|
|
|
|
checkProfiles(t)
|
|
|
|
|
|
|
|
{
|
|
|
|
t.Logf("Set user1 as logged in user")
|
2023-04-15 00:13:06 +01:00
|
|
|
if err := pm.SetCurrentUserID(uid); err != nil {
|
|
|
|
t.Fatalf("can't set user id: %s", err)
|
2022-11-09 05:58:10 +00:00
|
|
|
}
|
|
|
|
checkProfiles(t)
|
|
|
|
t.Logf("Save prefs for user1")
|
|
|
|
wantProfiles["default"] = setPrefs(t, "default", false)
|
|
|
|
wantCurProfile = "default"
|
|
|
|
}
|
|
|
|
checkProfiles(t)
|
|
|
|
|
|
|
|
{
|
|
|
|
t.Logf("Create new profile")
|
|
|
|
pm.NewProfile()
|
|
|
|
wantCurProfile = ""
|
2023-01-04 17:34:31 +00:00
|
|
|
wantProfiles[""] = defaultPrefs
|
2022-11-09 05:58:10 +00:00
|
|
|
checkProfiles(t)
|
|
|
|
|
|
|
|
t.Logf("Save as test profile")
|
|
|
|
wantProfiles["test"] = setPrefs(t, "test", false)
|
|
|
|
wantCurProfile = "test"
|
|
|
|
checkProfiles(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Recreate profile manager from store, should reset prefs")
|
|
|
|
// Recreate the profile manager to ensure that it can load the profiles
|
|
|
|
// from the store at startup.
|
2023-01-31 01:28:13 +00:00
|
|
|
pm, err = newProfileManagerWithGOOS(store, logger.Discard, "windows")
|
2022-11-09 05:58:10 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
wantCurProfile = ""
|
2023-01-04 17:34:31 +00:00
|
|
|
wantProfiles[""] = defaultPrefs
|
2022-11-09 05:58:10 +00:00
|
|
|
checkProfiles(t)
|
|
|
|
|
|
|
|
{
|
|
|
|
t.Logf("Set user1 as current user")
|
2023-04-15 00:13:06 +01:00
|
|
|
if err := pm.SetCurrentUserID(uid); err != nil {
|
2022-11-09 05:58:10 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
wantCurProfile = "test"
|
|
|
|
}
|
|
|
|
checkProfiles(t)
|
|
|
|
{
|
|
|
|
t.Logf("set unattended mode")
|
|
|
|
wantProfiles["test"] = setPrefs(t, "test", true)
|
|
|
|
}
|
2023-04-15 00:13:06 +01:00
|
|
|
if pm.CurrentUserID() != uid {
|
|
|
|
t.Fatalf("CurrentUserID = %q; want %q", pm.CurrentUserID(), uid)
|
2022-11-09 05:58:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Recreate the profile manager to ensure that it starts with test profile.
|
2023-01-31 01:28:13 +00:00
|
|
|
pm, err = newProfileManagerWithGOOS(store, logger.Discard, "windows")
|
2022-11-09 05:58:10 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
checkProfiles(t)
|
2023-04-15 00:13:06 +01:00
|
|
|
if pm.CurrentUserID() != uid {
|
|
|
|
t.Fatalf("CurrentUserID = %q; want %q", pm.CurrentUserID(), uid)
|
2022-11-09 05:58:10 +00:00
|
|
|
}
|
|
|
|
}
|