mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-06 00:22:20 -08:00
read routes when switching profiles
This commit is contained in:
1 parent
9f0bb29912
commit
28bba7b3db
2 files changed
+43
-5
No files matched your search
@@ -61,8 +61,12 @@ func (pm *profileManager) WriteRoutesForCurrentProfile() error {
|
||||
}
|
||||
|
||||
func (pm *profileManager) ReadRoutesForCurrentProfile() error {
|
||||
// TODO(fran) key should be a const somewhere
|
||||
routeInfoInBytes, err := pm.readStateForCurrentProfile("_routes")
|
||||
if err != nil {
|
||||
if err == ipn.ErrStateNotExist || len(routeInfoInBytes) == 0 {
|
||||
pm.currentRoutes = &ipn.RouteInfo{}
|
||||
return nil
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -141,6 +145,10 @@ func (pm *profileManager) SetCurrentUserID(uid ipn.WindowsUserID) error {
|
||||
}
|
||||
pm.currentProfile = prof
|
||||
pm.prefs = prefs
|
||||
|
||||
if err := pm.ReadRoutesForCurrentProfile(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -376,6 +384,9 @@ func (pm *profileManager) SwitchProfile(id ipn.ProfileID) error {
|
||||
}
|
||||
pm.prefs = prefs
|
||||
pm.currentProfile = kp
|
||||
if err := pm.ReadRoutesForCurrentProfile(); err != nil {
|
||||
return err
|
||||
}
|
||||
return pm.setAsUserSelectedProfileLocked()
|
||||
}
|
||||
|
||||
@@ -588,6 +599,9 @@ func newProfileManagerWithGOOS(store ipn.StateStore, logf logger.Logf, goos stri
|
||||
if err := pm.setPrefsLocked(prefs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := pm.ReadRoutesForCurrentProfile(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Most platform behavior is controlled by the goos parameter, however
|
||||
// some behavior is implied by build tag and fails when run on Windows,
|
||||
// so we explicitly avoid that behavior when running on Windows.
|
||||
|
||||
@@ -707,12 +707,36 @@ func TestKevin(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assertIsUser1Routes := func() {
|
||||
if pm.currentRoutes.Corp[0] != Prefix_1 {
|
||||
t.Fatal("That's not right")
|
||||
}
|
||||
if pm.currentRoutes.Discovered["Home.dom"].Route != Prefix_3 {
|
||||
t.Fatal("That's not right: discovered")
|
||||
}
|
||||
}
|
||||
assertIsUser2Routes := func() {
|
||||
if pm.currentRoutes.Corp[0] != Prefix_3 {
|
||||
t.Fatal("That's not right")
|
||||
}
|
||||
if pm.currentRoutes.Discovered["Home.dom"].Route != Prefix_2 {
|
||||
t.Fatal("That's not right: discovered")
|
||||
}
|
||||
}
|
||||
assertIsUser1Routes()
|
||||
|
||||
pm.SetCurrentUserID("user2")
|
||||
newProfile(t, "user2")
|
||||
pm.currentRoutes = &fakeRouteInfo2
|
||||
if err := pm.ReadRoutesForCurrentProfile(); err != nil {
|
||||
if err := pm.WriteRoutesForCurrentProfile(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertIsUser2Routes()
|
||||
|
||||
if pm.currentRoutes.Corp[0] != Prefix_1 {
|
||||
t.Fatal("That's not right")
|
||||
}
|
||||
pm.SetCurrentUserID("user1")
|
||||
// should have read out the other route info
|
||||
assertIsUser1Routes()
|
||||
|
||||
pm.SetCurrentUserID("user2")
|
||||
assertIsUser2Routes()
|
||||
}
|
||||
Reference in new issue
Block a user