diff --git a/ipn/ipnlocal/profiles.go b/ipn/ipnlocal/profiles.go index 1467f9b46..335d63930 100644 --- a/ipn/ipnlocal/profiles.go +++ b/ipn/ipnlocal/profiles.go @@ -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. diff --git a/ipn/ipnlocal/profiles_test.go b/ipn/ipnlocal/profiles_test.go index bae081d59..4b2324424 100644 --- a/ipn/ipnlocal/profiles_test.go +++ b/ipn/ipnlocal/profiles_test.go @@ -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() }