2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2021-04-30 03:18:50 +00:00
|
|
|
|
|
|
|
package ipnlocal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"sync"
|
2022-08-04 04:51:02 +00:00
|
|
|
"sync/atomic"
|
2021-04-30 03:18:50 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-04-30 21:47:16 +00:00
|
|
|
qt "github.com/frankban/quicktest"
|
2021-04-30 03:18:50 +00:00
|
|
|
|
|
|
|
"tailscale.com/control/controlclient"
|
2022-11-12 12:39:29 +00:00
|
|
|
"tailscale.com/envknob"
|
2021-04-30 03:18:50 +00:00
|
|
|
"tailscale.com/ipn"
|
2022-02-28 21:08:45 +00:00
|
|
|
"tailscale.com/ipn/store/mem"
|
2021-04-30 03:18:50 +00:00
|
|
|
"tailscale.com/tailcfg"
|
2023-05-03 20:57:17 +00:00
|
|
|
"tailscale.com/tsd"
|
2022-11-02 19:45:20 +00:00
|
|
|
"tailscale.com/tstest"
|
2021-09-03 20:17:46 +00:00
|
|
|
"tailscale.com/types/key"
|
2021-04-30 03:18:50 +00:00
|
|
|
"tailscale.com/types/logger"
|
2023-03-23 17:49:56 +00:00
|
|
|
"tailscale.com/types/logid"
|
2021-04-30 03:18:50 +00:00
|
|
|
"tailscale.com/types/netmap"
|
2021-04-30 07:47:21 +00:00
|
|
|
"tailscale.com/types/persist"
|
2021-04-30 03:18:50 +00:00
|
|
|
"tailscale.com/wgengine"
|
|
|
|
)
|
|
|
|
|
|
|
|
// notifyThrottler receives notifications from an ipn.Backend, blocking
|
|
|
|
// (with eventual timeout and t.Fatal) if there are too many and complaining
|
|
|
|
// (also with t.Fatal) if they are too few.
|
|
|
|
type notifyThrottler struct {
|
|
|
|
t *testing.T
|
|
|
|
|
|
|
|
// ch gets replaced frequently. Lock the mutex before getting or
|
|
|
|
// setting it, but not while waiting on it.
|
|
|
|
mu sync.Mutex
|
|
|
|
ch chan ipn.Notify
|
|
|
|
}
|
|
|
|
|
|
|
|
// expect tells the throttler to expect count upcoming notifications.
|
|
|
|
func (nt *notifyThrottler) expect(count int) {
|
|
|
|
nt.mu.Lock()
|
|
|
|
nt.ch = make(chan ipn.Notify, count)
|
|
|
|
nt.mu.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// put adds one notification into the throttler's queue.
|
|
|
|
func (nt *notifyThrottler) put(n ipn.Notify) {
|
2022-10-24 00:15:04 +00:00
|
|
|
nt.t.Helper()
|
2021-04-30 03:18:50 +00:00
|
|
|
nt.mu.Lock()
|
|
|
|
ch := nt.ch
|
|
|
|
nt.mu.Unlock()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case ch <- n:
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
nt.t.Fatalf("put: channel full: %v", n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// drain pulls the notifications out of the queue, asserting that there are
|
|
|
|
// exactly count notifications that have been put so far.
|
|
|
|
func (nt *notifyThrottler) drain(count int) []ipn.Notify {
|
2022-03-27 03:12:12 +00:00
|
|
|
nt.t.Helper()
|
2021-04-30 03:18:50 +00:00
|
|
|
nt.mu.Lock()
|
|
|
|
ch := nt.ch
|
|
|
|
nt.mu.Unlock()
|
|
|
|
|
|
|
|
nn := []ipn.Notify{}
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
select {
|
|
|
|
case n := <-ch:
|
|
|
|
nn = append(nn, n)
|
|
|
|
case <-time.After(6 * time.Second):
|
|
|
|
nt.t.Fatalf("drain: channel empty after %d/%d", i, count)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// no more notifications expected
|
|
|
|
close(ch)
|
|
|
|
|
2022-11-12 12:39:29 +00:00
|
|
|
nt.t.Log(nn)
|
2021-04-30 03:18:50 +00:00
|
|
|
return nn
|
|
|
|
}
|
|
|
|
|
|
|
|
// mockControl is a mock implementation of controlclient.Client.
|
|
|
|
// Much of the backend state machine depends on callbacks and state
|
|
|
|
// in the controlclient.Client, so by controlling it, we can check that
|
|
|
|
// the state machine works as expected.
|
|
|
|
type mockControl struct {
|
2022-11-15 04:17:28 +00:00
|
|
|
tb testing.TB
|
|
|
|
logf logger.Logf
|
|
|
|
opts controlclient.Options
|
|
|
|
paused atomic.Bool
|
2021-04-30 03:18:50 +00:00
|
|
|
|
|
|
|
mu sync.Mutex
|
2022-11-15 04:17:28 +00:00
|
|
|
machineKey key.MachinePrivate
|
|
|
|
persist *persist.Persist
|
2021-04-30 03:18:50 +00:00
|
|
|
calls []string
|
|
|
|
authBlocked bool
|
2022-11-15 04:17:28 +00:00
|
|
|
shutdown chan struct{}
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 04:17:28 +00:00
|
|
|
func newClient(tb testing.TB, opts controlclient.Options) *mockControl {
|
2021-04-30 03:18:50 +00:00
|
|
|
return &mockControl{
|
2021-09-15 23:05:10 +00:00
|
|
|
tb: tb,
|
2021-04-30 03:18:50 +00:00
|
|
|
authBlocked: true,
|
2022-11-15 04:17:28 +00:00
|
|
|
logf: opts.Logf,
|
|
|
|
opts: opts,
|
|
|
|
shutdown: make(chan struct{}),
|
|
|
|
persist: opts.Persist.Clone(),
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 04:17:28 +00:00
|
|
|
func (cc *mockControl) assertShutdown(wasPaused bool) {
|
|
|
|
cc.tb.Helper()
|
|
|
|
select {
|
|
|
|
case <-cc.shutdown:
|
|
|
|
// ok
|
|
|
|
case <-time.After(500 * time.Millisecond):
|
|
|
|
cc.tb.Fatalf("timed out waiting for shutdown")
|
|
|
|
}
|
|
|
|
if wasPaused {
|
|
|
|
cc.assertCalls("unpause", "Shutdown")
|
|
|
|
} else {
|
|
|
|
cc.assertCalls("Shutdown")
|
2021-12-15 19:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-30 08:29:22 +00:00
|
|
|
func (cc *mockControl) populateKeys() (newKeys bool) {
|
2021-04-30 07:47:21 +00:00
|
|
|
cc.mu.Lock()
|
|
|
|
defer cc.mu.Unlock()
|
|
|
|
|
|
|
|
if cc.machineKey.IsZero() {
|
|
|
|
cc.logf("Copying machineKey.")
|
|
|
|
cc.machineKey, _ = cc.opts.GetMachinePrivateKey()
|
2021-04-30 08:29:22 +00:00
|
|
|
newKeys = true
|
2021-04-30 07:47:21 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 12:39:29 +00:00
|
|
|
if cc.persist == nil {
|
|
|
|
cc.persist = &persist.Persist{}
|
|
|
|
}
|
2022-11-09 05:58:10 +00:00
|
|
|
if cc.persist != nil && cc.persist.PrivateNodeKey.IsZero() {
|
2021-04-30 07:47:21 +00:00
|
|
|
cc.logf("Generating a new nodekey.")
|
|
|
|
cc.persist.OldPrivateNodeKey = cc.persist.PrivateNodeKey
|
2021-10-28 16:50:58 +00:00
|
|
|
cc.persist.PrivateNodeKey = key.NewNode()
|
2021-04-30 08:29:22 +00:00
|
|
|
newKeys = true
|
2021-04-30 07:47:21 +00:00
|
|
|
}
|
2021-04-30 08:29:22 +00:00
|
|
|
|
|
|
|
return newKeys
|
2021-04-30 07:47:21 +00:00
|
|
|
}
|
|
|
|
|
2021-04-30 03:18:50 +00:00
|
|
|
// send publishes a controlclient.Status notification upstream.
|
|
|
|
// (In our tests here, upstream is the ipnlocal.Local instance.)
|
|
|
|
func (cc *mockControl) send(err error, url string, loginFinished bool, nm *netmap.NetworkMap) {
|
2022-11-15 04:17:28 +00:00
|
|
|
if loginFinished {
|
|
|
|
cc.mu.Lock()
|
|
|
|
cc.authBlocked = false
|
|
|
|
cc.mu.Unlock()
|
|
|
|
}
|
2023-08-28 22:27:39 +00:00
|
|
|
if cc.opts.Observer != nil {
|
2021-04-30 03:18:50 +00:00
|
|
|
s := controlclient.Status{
|
2021-04-30 07:47:21 +00:00
|
|
|
URL: url,
|
|
|
|
NetMap: nm,
|
2023-08-30 18:35:43 +00:00
|
|
|
Persist: cc.persist.View(),
|
2021-10-26 17:19:35 +00:00
|
|
|
Err: err,
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
if loginFinished {
|
2023-08-30 18:09:36 +00:00
|
|
|
s.SetStateForTest(controlclient.StateAuthenticated)
|
ipnlocal: don't assume NeedsLogin immediately after StartLogout().
Previously, there was no server round trip required to log out, so when
you asked ipnlocal to Logout(), it could clear the netmap immediately
and switch to NeedsLogin state.
In v1.8, we added a true Logout operation. ipn.Logout() would trigger
an async cc.StartLogout() and *also* immediately switch to NeedsLogin.
Unfortunately, some frontends would see NeedsLogin and immediately
trigger a new StartInteractiveLogin() operation, before the
controlclient auth state machine actually acted on the Logout command,
thus accidentally invalidating the entire logout operation, retaining
the netmap, and violating the user's expectations.
Instead, add a new LogoutFinished signal from controlclient
(paralleling LoginFinished) and, upon starting a logout, don't update
the ipn state machine until it's received.
Updates: #1918 (BUG-2)
Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2021-05-20 06:46:57 +00:00
|
|
|
} else if url == "" && err == nil && nm == nil {
|
2023-08-30 18:09:36 +00:00
|
|
|
s.SetStateForTest(controlclient.StateNotAuthenticated)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
2023-09-02 19:04:03 +00:00
|
|
|
cc.opts.Observer.SetControlClientStatus(cc, s)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// called records that a particular function name was called.
|
|
|
|
func (cc *mockControl) called(s string) {
|
|
|
|
cc.mu.Lock()
|
|
|
|
defer cc.mu.Unlock()
|
|
|
|
|
|
|
|
cc.calls = append(cc.calls, s)
|
|
|
|
}
|
|
|
|
|
2021-09-15 23:05:10 +00:00
|
|
|
// assertCalls fails the test if the list of functions that have been called since the
|
|
|
|
// last time assertCall was run does not match want.
|
|
|
|
func (cc *mockControl) assertCalls(want ...string) {
|
|
|
|
cc.tb.Helper()
|
2021-04-30 03:18:50 +00:00
|
|
|
cc.mu.Lock()
|
|
|
|
defer cc.mu.Unlock()
|
2021-09-15 23:05:10 +00:00
|
|
|
qt.Assert(cc.tb, cc.calls, qt.DeepEquals, want)
|
|
|
|
cc.calls = nil
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Shutdown disconnects the client.
|
|
|
|
func (cc *mockControl) Shutdown() {
|
|
|
|
cc.logf("Shutdown")
|
|
|
|
cc.called("Shutdown")
|
2022-11-15 04:17:28 +00:00
|
|
|
close(cc.shutdown)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 04:17:28 +00:00
|
|
|
// Login starts a login process. Note that in this mock, we don't automatically
|
|
|
|
// generate notifications about the progress of the login operation. You have to
|
|
|
|
// call send() as required by the test.
|
2021-04-30 03:18:50 +00:00
|
|
|
func (cc *mockControl) Login(t *tailcfg.Oauth2Token, flags controlclient.LoginFlags) {
|
|
|
|
cc.logf("Login token=%v flags=%v", t, flags)
|
|
|
|
cc.called("Login")
|
2021-04-30 08:29:22 +00:00
|
|
|
newKeys := cc.populateKeys()
|
|
|
|
|
|
|
|
interact := (flags & controlclient.LoginInteractive) != 0
|
|
|
|
cc.logf("Login: interact=%v newKeys=%v", interact, newKeys)
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.mu.Lock()
|
|
|
|
defer cc.mu.Unlock()
|
|
|
|
cc.authBlocked = interact || newKeys
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cc *mockControl) Logout(ctx context.Context) error {
|
|
|
|
cc.logf("Logout")
|
|
|
|
cc.called("Logout")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cc *mockControl) SetPaused(paused bool) {
|
2022-11-15 04:17:28 +00:00
|
|
|
was := cc.paused.Swap(paused)
|
|
|
|
if was == paused {
|
|
|
|
return
|
|
|
|
}
|
2021-04-30 03:18:50 +00:00
|
|
|
cc.logf("SetPaused=%v", paused)
|
|
|
|
if paused {
|
|
|
|
cc.called("pause")
|
|
|
|
} else {
|
|
|
|
cc.called("unpause")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cc *mockControl) AuthCantContinue() bool {
|
|
|
|
cc.mu.Lock()
|
|
|
|
defer cc.mu.Unlock()
|
|
|
|
|
|
|
|
return cc.authBlocked
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cc *mockControl) SetHostinfo(hi *tailcfg.Hostinfo) {
|
|
|
|
cc.logf("SetHostinfo: %v", *hi)
|
|
|
|
cc.called("SetHostinfo")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cc *mockControl) SetNetInfo(ni *tailcfg.NetInfo) {
|
|
|
|
cc.called("SetNetinfo")
|
|
|
|
cc.logf("SetNetInfo: %v", *ni)
|
|
|
|
cc.called("SetNetInfo")
|
|
|
|
}
|
|
|
|
|
2022-10-27 20:40:31 +00:00
|
|
|
func (cc *mockControl) SetTKAHead(head string) {
|
|
|
|
cc.logf("SetTKAHead: %s", head)
|
|
|
|
}
|
|
|
|
|
2022-06-19 23:31:54 +00:00
|
|
|
func (cc *mockControl) UpdateEndpoints(endpoints []tailcfg.Endpoint) {
|
2021-04-30 03:18:50 +00:00
|
|
|
// validate endpoint information here?
|
2022-06-19 23:31:54 +00:00
|
|
|
cc.logf("UpdateEndpoints: ep=%v", endpoints)
|
2021-04-30 03:18:50 +00:00
|
|
|
cc.called("UpdateEndpoints")
|
|
|
|
}
|
|
|
|
|
|
|
|
// A very precise test of the sequence of function calls generated by
|
|
|
|
// ipnlocal.Local into its controlclient instance, and the events it
|
|
|
|
// produces upstream into the UI.
|
|
|
|
//
|
|
|
|
// [apenwarr] Normally I'm not a fan of "mock" style tests, but the precise
|
|
|
|
// sequence of this state machine is so important for writing our multiple
|
|
|
|
// frontends, that it's worth validating it all in one place.
|
|
|
|
//
|
|
|
|
// Any changes that affect this test will most likely require carefully
|
|
|
|
// re-testing all our GUIs (and the CLI) to make sure we didn't break
|
|
|
|
// anything.
|
|
|
|
//
|
|
|
|
// Note also that this test doesn't have any timers, goroutines, or duplicate
|
|
|
|
// detection. It expects messages to be produced in exactly the right order,
|
|
|
|
// with no duplicates, without doing network activity (other than through
|
|
|
|
// controlclient, which we fake, so there's no network activity there either).
|
|
|
|
//
|
|
|
|
// TODO: A few messages that depend on magicsock (which actually might have
|
|
|
|
// network delays) are just ignored for now, which makes the test
|
|
|
|
// predictable, but maybe a bit less thorough. This is more of an overall
|
|
|
|
// state machine test than a test of the wgengine+magicsock integration.
|
|
|
|
func TestStateMachine(t *testing.T) {
|
2022-11-12 12:39:29 +00:00
|
|
|
envknob.Setenv("TAILSCALE_USE_WIP_CODE", "1")
|
|
|
|
defer envknob.Setenv("TAILSCALE_USE_WIP_CODE", "")
|
2021-04-30 21:47:16 +00:00
|
|
|
c := qt.New(t)
|
2021-04-30 03:18:50 +00:00
|
|
|
|
2022-11-02 19:45:20 +00:00
|
|
|
logf := tstest.WhileTestRunningLogger(t)
|
2023-05-03 20:57:17 +00:00
|
|
|
sys := new(tsd.System)
|
2021-07-12 03:10:02 +00:00
|
|
|
store := new(testStateStorage)
|
2023-05-03 20:57:17 +00:00
|
|
|
sys.Set(store)
|
|
|
|
e, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set)
|
2021-04-30 03:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("NewFakeUserspaceEngine: %v", err)
|
|
|
|
}
|
2021-09-15 18:48:49 +00:00
|
|
|
t.Cleanup(e.Close)
|
2023-05-03 20:57:17 +00:00
|
|
|
sys.Set(e)
|
2021-04-30 03:18:50 +00:00
|
|
|
|
2023-05-03 20:57:17 +00:00
|
|
|
b, err := NewLocalBackend(logf, logid.PublicID{}, sys, 0)
|
2021-04-30 14:23:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("NewLocalBackend: %v", err)
|
|
|
|
}
|
2022-06-20 01:14:45 +00:00
|
|
|
|
2022-11-15 04:17:28 +00:00
|
|
|
var cc, previousCC *mockControl
|
2021-04-30 14:23:22 +00:00
|
|
|
b.SetControlClientGetterForTesting(func(opts controlclient.Options) (controlclient.Client, error) {
|
2022-11-15 04:17:28 +00:00
|
|
|
previousCC = cc
|
|
|
|
cc = newClient(t, opts)
|
2021-04-30 03:18:50 +00:00
|
|
|
|
2022-11-12 12:39:29 +00:00
|
|
|
t.Logf("ccGen: new mockControl.")
|
2021-04-30 03:18:50 +00:00
|
|
|
cc.called("New")
|
|
|
|
return cc, nil
|
2021-04-30 14:23:22 +00:00
|
|
|
})
|
2021-04-30 03:18:50 +00:00
|
|
|
|
|
|
|
notifies := ¬ifyThrottler{t: t}
|
|
|
|
notifies.expect(0)
|
|
|
|
|
|
|
|
b.SetNotifyCallback(func(n ipn.Notify) {
|
|
|
|
if n.State != nil ||
|
2022-11-03 22:46:17 +00:00
|
|
|
(n.Prefs != nil && n.Prefs.Valid()) ||
|
2021-04-30 03:18:50 +00:00
|
|
|
n.BrowseToURL != nil ||
|
|
|
|
n.LoginFinished != nil {
|
2023-08-31 01:33:58 +00:00
|
|
|
logf("%v\n\n", n)
|
2021-04-30 03:18:50 +00:00
|
|
|
notifies.put(n)
|
|
|
|
} else {
|
2023-08-31 01:33:58 +00:00
|
|
|
logf("(ignored) %v\n\n", n)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Check that it hasn't called us right away.
|
|
|
|
// The state machine should be idle until we call Start().
|
2022-11-15 04:17:28 +00:00
|
|
|
c.Assert(cc, qt.IsNil)
|
2021-04-30 03:18:50 +00:00
|
|
|
|
|
|
|
// Start the state machine.
|
|
|
|
// Since !WantRunning by default, it'll create a controlclient,
|
|
|
|
// but not ask it to do anything yet.
|
2021-04-30 07:47:21 +00:00
|
|
|
t.Logf("\n\nStart")
|
2021-04-30 03:18:50 +00:00
|
|
|
notifies.expect(2)
|
2022-11-09 05:58:10 +00:00
|
|
|
c.Assert(b.Start(ipn.Options{}), qt.IsNil)
|
2021-04-30 03:18:50 +00:00
|
|
|
{
|
|
|
|
// BUG: strictly, it should pause, not unpause, here, since !WantRunning.
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls("New")
|
2021-04-30 03:18:50 +00:00
|
|
|
|
|
|
|
nn := notifies.drain(2)
|
2021-09-15 23:05:10 +00:00
|
|
|
cc.assertCalls()
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].Prefs, qt.IsNotNil)
|
|
|
|
c.Assert(nn[1].State, qt.IsNotNil)
|
2022-10-23 17:07:10 +00:00
|
|
|
prefs := nn[0].Prefs
|
2021-04-30 07:56:11 +00:00
|
|
|
// Note: a totally fresh system has Prefs.LoggedOut=false by
|
|
|
|
// default. We are logged out, but not because the user asked
|
|
|
|
// for it, so it doesn't count as Prefs.LoggedOut==true.
|
2023-09-01 00:44:13 +00:00
|
|
|
c.Assert(prefs.LoggedOut(), qt.IsTrue)
|
2022-10-23 17:07:10 +00:00
|
|
|
c.Assert(prefs.WantRunning(), qt.IsFalse)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, *nn[1].State)
|
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Restart the state machine.
|
|
|
|
// It's designed to handle frontends coming and going sporadically.
|
|
|
|
// Make the sure the restart not only works, but generates the same
|
|
|
|
// events as the first time, so UIs always know what to expect.
|
|
|
|
t.Logf("\n\nStart2")
|
|
|
|
notifies.expect(2)
|
2022-11-09 05:58:10 +00:00
|
|
|
c.Assert(b.Start(ipn.Options{}), qt.IsNil)
|
2021-04-30 03:18:50 +00:00
|
|
|
{
|
2022-11-15 04:17:28 +00:00
|
|
|
previousCC.assertShutdown(false)
|
|
|
|
cc.assertCalls("New")
|
2021-04-30 03:18:50 +00:00
|
|
|
|
|
|
|
nn := notifies.drain(2)
|
2021-09-15 23:05:10 +00:00
|
|
|
cc.assertCalls()
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].Prefs, qt.IsNotNil)
|
|
|
|
c.Assert(nn[1].State, qt.IsNotNil)
|
2023-09-01 00:44:13 +00:00
|
|
|
c.Assert(nn[0].Prefs.LoggedOut(), qt.IsTrue)
|
2022-10-23 17:07:10 +00:00
|
|
|
c.Assert(nn[0].Prefs.WantRunning(), qt.IsFalse)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, *nn[1].State)
|
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start non-interactive login with no token.
|
|
|
|
// This will ask controlclient to start its own Login() process,
|
|
|
|
// then wait for us to respond.
|
|
|
|
t.Logf("\n\nLogin (noninteractive)")
|
|
|
|
notifies.expect(0)
|
|
|
|
b.Login(nil)
|
|
|
|
{
|
2021-09-15 23:05:10 +00:00
|
|
|
cc.assertCalls("Login")
|
2021-04-30 03:18:50 +00:00
|
|
|
notifies.drain(0)
|
2021-05-06 03:28:29 +00:00
|
|
|
// Note: WantRunning isn't true yet. It'll switch to true
|
|
|
|
// after a successful login finishes.
|
|
|
|
// (This behaviour is needed so that b.Login() won't
|
|
|
|
// start connecting to an old account right away, if one
|
|
|
|
// exists when you launch another login.)
|
2022-11-15 04:17:28 +00:00
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Attempted non-interactive login with no key; indicate that
|
|
|
|
// the user needs to visit a login URL.
|
|
|
|
t.Logf("\n\nLogin (url response)")
|
|
|
|
notifies.expect(1)
|
2022-11-16 16:18:28 +00:00
|
|
|
url1 := "https://localhost:1/1"
|
2021-04-30 03:18:50 +00:00
|
|
|
cc.send(nil, url1, false, nil)
|
|
|
|
{
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls()
|
2021-04-30 03:18:50 +00:00
|
|
|
|
|
|
|
// ...but backend eats that notification, because the user
|
|
|
|
// didn't explicitly request interactive login yet, and
|
|
|
|
// we're already in NeedsLogin state.
|
|
|
|
nn := notifies.drain(1)
|
|
|
|
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].Prefs, qt.IsNotNil)
|
2023-09-01 00:44:13 +00:00
|
|
|
c.Assert(nn[0].Prefs.LoggedOut(), qt.IsTrue)
|
2022-10-23 17:07:10 +00:00
|
|
|
c.Assert(nn[0].Prefs.WantRunning(), qt.IsFalse)
|
2022-11-15 04:17:28 +00:00
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now we'll try an interactive login.
|
|
|
|
// Since we provided an interactive URL earlier, this shouldn't
|
|
|
|
// ask control to do anything. Instead backend will emit an event
|
|
|
|
// indicating that the UI should browse to the given URL.
|
|
|
|
t.Logf("\n\nLogin (interactive)")
|
|
|
|
notifies.expect(1)
|
|
|
|
b.StartLoginInteractive()
|
|
|
|
{
|
|
|
|
nn := notifies.drain(1)
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls()
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].BrowseToURL, qt.IsNotNil)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(url1, qt.Equals, *nn[0].BrowseToURL)
|
2022-11-15 04:17:28 +00:00
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sometimes users press the Login button again, in the middle of
|
|
|
|
// a login sequence. For example, they might have closed their
|
|
|
|
// browser window without logging in, or they waited too long and
|
|
|
|
// the login URL expired. If they start another interactive login,
|
|
|
|
// we must always get a *new* login URL first.
|
|
|
|
t.Logf("\n\nLogin2 (interactive)")
|
|
|
|
notifies.expect(0)
|
|
|
|
b.StartLoginInteractive()
|
|
|
|
{
|
|
|
|
notifies.drain(0)
|
|
|
|
// backend asks control for another login sequence
|
2021-09-15 23:05:10 +00:00
|
|
|
cc.assertCalls("Login")
|
2022-11-15 04:17:28 +00:00
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Provide a new interactive login URL.
|
|
|
|
t.Logf("\n\nLogin2 (url response)")
|
|
|
|
notifies.expect(1)
|
2022-11-16 16:18:28 +00:00
|
|
|
url2 := "https://localhost:1/2"
|
2021-04-30 03:18:50 +00:00
|
|
|
cc.send(nil, url2, false, nil)
|
|
|
|
{
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls()
|
2021-04-30 03:18:50 +00:00
|
|
|
|
|
|
|
// This time, backend should emit it to the UI right away,
|
|
|
|
// because the UI is anxiously awaiting a new URL to visit.
|
|
|
|
nn := notifies.drain(1)
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].BrowseToURL, qt.IsNotNil)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(url2, qt.Equals, *nn[0].BrowseToURL)
|
2022-11-15 04:17:28 +00:00
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pretend that the interactive login actually happened.
|
|
|
|
// Controlclient always sends the netmap and LoginFinished at the
|
|
|
|
// same time.
|
|
|
|
// The backend should propagate this upward for the UI.
|
|
|
|
t.Logf("\n\nLoginFinished")
|
2021-05-06 03:28:29 +00:00
|
|
|
notifies.expect(3)
|
2022-11-17 14:05:02 +00:00
|
|
|
cc.persist.UserProfile.LoginName = "user1"
|
2023-02-07 05:18:21 +00:00
|
|
|
cc.persist.NodeID = "node1"
|
2021-04-30 03:18:50 +00:00
|
|
|
cc.send(nil, "", true, &netmap.NetworkMap{})
|
|
|
|
{
|
2021-05-06 03:28:29 +00:00
|
|
|
nn := notifies.drain(3)
|
2021-04-30 03:18:50 +00:00
|
|
|
// Arguably it makes sense to unpause now, since the machine
|
|
|
|
// authorization status is part of the netmap.
|
|
|
|
//
|
|
|
|
// BUG: backend unblocks wgengine at this point, even though
|
|
|
|
// our machine key is not authorized. It probably should
|
|
|
|
// wait until it gets into Starting.
|
|
|
|
// TODO: (Currently this test doesn't detect that bug, but
|
|
|
|
// it's visible in the logs)
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls()
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].LoginFinished, qt.IsNotNil)
|
|
|
|
c.Assert(nn[1].Prefs, qt.IsNotNil)
|
|
|
|
c.Assert(nn[2].State, qt.IsNotNil)
|
2023-08-04 00:38:28 +00:00
|
|
|
c.Assert(nn[1].Prefs.Persist().UserProfile().LoginName(), qt.Equals, "user1")
|
2021-05-06 03:28:29 +00:00
|
|
|
c.Assert(ipn.NeedsMachineAuth, qt.Equals, *nn[2].State)
|
2022-11-15 04:17:28 +00:00
|
|
|
c.Assert(ipn.NeedsMachineAuth, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pretend that the administrator has authorized our machine.
|
|
|
|
t.Logf("\n\nMachineAuthorized")
|
|
|
|
notifies.expect(1)
|
|
|
|
// BUG: the real controlclient sends LoginFinished with every
|
|
|
|
// notification while it's in StateAuthenticated, but not StateSynced.
|
2021-07-17 06:06:14 +00:00
|
|
|
// It should send it exactly once, or every time we're authenticated,
|
2021-04-30 03:18:50 +00:00
|
|
|
// but the current code is brittle.
|
|
|
|
// (ie. I suspect it would be better to change false->true in send()
|
|
|
|
// below, and do the same in the real controlclient.)
|
|
|
|
cc.send(nil, "", false, &netmap.NetworkMap{
|
|
|
|
MachineStatus: tailcfg.MachineAuthorized,
|
|
|
|
})
|
|
|
|
{
|
|
|
|
nn := notifies.drain(1)
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls()
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].State, qt.IsNotNil)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(ipn.Starting, qt.Equals, *nn[0].State)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: add a fake DERP server to our fake netmap, so we can
|
|
|
|
// transition to the Running state here.
|
|
|
|
|
|
|
|
// TODO: test what happens when the admin forcibly deletes our key.
|
|
|
|
// (ie. unsolicited logout)
|
|
|
|
|
|
|
|
// TODO: test what happens when our key expires, client side.
|
|
|
|
// (and when it gets close to expiring)
|
|
|
|
|
|
|
|
// The user changes their preference to !WantRunning.
|
|
|
|
t.Logf("\n\nWantRunning -> false")
|
|
|
|
notifies.expect(2)
|
|
|
|
b.EditPrefs(&ipn.MaskedPrefs{
|
|
|
|
WantRunningSet: true,
|
|
|
|
Prefs: ipn.Prefs{WantRunning: false},
|
|
|
|
})
|
|
|
|
{
|
|
|
|
nn := notifies.drain(2)
|
2021-09-15 23:05:10 +00:00
|
|
|
cc.assertCalls("pause")
|
2021-04-30 03:18:50 +00:00
|
|
|
// BUG: I would expect Prefs to change first, and state after.
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].State, qt.IsNotNil)
|
|
|
|
c.Assert(nn[1].Prefs, qt.IsNotNil)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(ipn.Stopped, qt.Equals, *nn[0].State)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The user changes their preference to WantRunning after all.
|
|
|
|
t.Logf("\n\nWantRunning -> true")
|
2021-07-12 03:10:02 +00:00
|
|
|
store.awaitWrite()
|
2021-04-30 03:18:50 +00:00
|
|
|
notifies.expect(2)
|
|
|
|
b.EditPrefs(&ipn.MaskedPrefs{
|
|
|
|
WantRunningSet: true,
|
|
|
|
Prefs: ipn.Prefs{WantRunning: true},
|
|
|
|
})
|
|
|
|
{
|
|
|
|
nn := notifies.drain(2)
|
|
|
|
// BUG: Login isn't needed here. We never logged out.
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls("Login", "unpause")
|
2021-04-30 03:18:50 +00:00
|
|
|
// BUG: I would expect Prefs to change first, and state after.
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].State, qt.IsNotNil)
|
|
|
|
c.Assert(nn[1].Prefs, qt.IsNotNil)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(ipn.Starting, qt.Equals, *nn[0].State)
|
2021-07-12 03:10:02 +00:00
|
|
|
c.Assert(store.sawWrite(), qt.IsTrue)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test the fast-path frontend reconnection.
|
2021-07-17 06:06:14 +00:00
|
|
|
// This one is very finicky, so we have to force State==Running
|
|
|
|
// or it won't use the fast path.
|
2021-04-30 03:18:50 +00:00
|
|
|
// TODO: actually get to State==Running, rather than cheating.
|
2021-04-30 07:47:21 +00:00
|
|
|
// That'll require spinning up a fake DERP server and putting it in
|
|
|
|
// the netmap.
|
2021-04-30 03:18:50 +00:00
|
|
|
t.Logf("\n\nFastpath Start()")
|
|
|
|
notifies.expect(1)
|
|
|
|
b.state = ipn.Running
|
2022-11-09 05:58:10 +00:00
|
|
|
c.Assert(b.Start(ipn.Options{}), qt.IsNil)
|
2021-04-30 03:18:50 +00:00
|
|
|
{
|
|
|
|
nn := notifies.drain(1)
|
2021-09-15 23:05:10 +00:00
|
|
|
cc.assertCalls()
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].State, qt.IsNotNil)
|
|
|
|
c.Assert(nn[0].LoginFinished, qt.IsNotNil)
|
|
|
|
c.Assert(nn[0].NetMap, qt.IsNotNil)
|
|
|
|
c.Assert(nn[0].Prefs, qt.IsNotNil)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// undo the state hack above.
|
|
|
|
b.state = ipn.Starting
|
|
|
|
|
|
|
|
// User wants to logout.
|
2021-07-12 03:10:02 +00:00
|
|
|
store.awaitWrite()
|
2023-08-31 01:33:58 +00:00
|
|
|
t.Logf("\n\nLogout")
|
2023-09-01 00:44:13 +00:00
|
|
|
notifies.expect(5)
|
2023-09-01 02:11:20 +00:00
|
|
|
b.Logout(context.Background())
|
2021-04-30 03:18:50 +00:00
|
|
|
{
|
2023-09-01 00:44:13 +00:00
|
|
|
nn := notifies.drain(5)
|
|
|
|
previousCC.assertCalls("pause", "Logout", "unpause", "Shutdown")
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].State, qt.IsNotNil)
|
2023-09-01 00:44:13 +00:00
|
|
|
c.Assert(*nn[0].State, qt.Equals, ipn.Stopped)
|
|
|
|
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[1].Prefs, qt.IsNotNil)
|
2022-10-23 17:07:10 +00:00
|
|
|
c.Assert(nn[1].Prefs.LoggedOut(), qt.IsTrue)
|
|
|
|
c.Assert(nn[1].Prefs.WantRunning(), qt.IsFalse)
|
2021-04-30 03:18:50 +00:00
|
|
|
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls("New")
|
2022-11-12 12:39:29 +00:00
|
|
|
c.Assert(nn[2].State, qt.IsNotNil)
|
2023-09-01 00:44:13 +00:00
|
|
|
c.Assert(*nn[2].State, qt.Equals, ipn.NoState)
|
|
|
|
|
|
|
|
c.Assert(nn[3].Prefs, qt.IsNotNil) // emptyPrefs
|
|
|
|
c.Assert(nn[3].Prefs.LoggedOut(), qt.IsTrue)
|
|
|
|
c.Assert(nn[3].Prefs.WantRunning(), qt.IsFalse)
|
|
|
|
|
|
|
|
c.Assert(nn[4].State, qt.IsNotNil)
|
|
|
|
c.Assert(*nn[4].State, qt.Equals, ipn.NeedsLogin)
|
|
|
|
|
2022-11-12 12:39:29 +00:00
|
|
|
c.Assert(b.State(), qt.Equals, ipn.NeedsLogin)
|
2021-04-30 03:18:50 +00:00
|
|
|
|
2023-09-01 00:44:13 +00:00
|
|
|
c.Assert(store.sawWrite(), qt.IsTrue)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
2023-09-01 00:44:13 +00:00
|
|
|
// A second logout should be a no-op as we are in the NeedsLogin state.
|
|
|
|
t.Logf("\n\nLogout2")
|
2021-05-06 03:28:29 +00:00
|
|
|
notifies.expect(0)
|
2023-09-01 02:11:20 +00:00
|
|
|
b.Logout(context.Background())
|
2021-04-30 03:18:50 +00:00
|
|
|
{
|
2021-05-06 03:28:29 +00:00
|
|
|
notifies.drain(0)
|
2022-11-12 12:39:29 +00:00
|
|
|
cc.assertCalls()
|
2022-10-24 00:15:04 +00:00
|
|
|
c.Assert(b.Prefs().LoggedOut(), qt.IsTrue)
|
|
|
|
c.Assert(b.Prefs().WantRunning(), qt.IsFalse)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
2023-09-01 00:44:13 +00:00
|
|
|
// A third logout should also be a no-op as the cc should be in
|
|
|
|
// AuthCantContinue state.
|
|
|
|
t.Logf("\n\nLogout3")
|
|
|
|
notifies.expect(3)
|
2023-09-01 02:11:20 +00:00
|
|
|
b.Logout(context.Background())
|
2021-04-30 03:18:50 +00:00
|
|
|
{
|
2021-05-06 03:28:29 +00:00
|
|
|
notifies.drain(0)
|
2022-11-12 12:39:29 +00:00
|
|
|
cc.assertCalls()
|
2022-10-24 00:15:04 +00:00
|
|
|
c.Assert(b.Prefs().LoggedOut(), qt.IsTrue)
|
|
|
|
c.Assert(b.Prefs().WantRunning(), qt.IsFalse)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Oh, you thought we were done? Ha! Now we have to test what
|
|
|
|
// happens if the user exits and restarts while logged out.
|
|
|
|
// Note that it's explicitly okay to call b.Start() over and over
|
|
|
|
// again, every time the frontend reconnects.
|
|
|
|
|
|
|
|
// TODO: test user switching between statekeys.
|
|
|
|
|
|
|
|
// The frontend restarts!
|
|
|
|
t.Logf("\n\nStart3")
|
|
|
|
notifies.expect(2)
|
2022-11-09 05:58:10 +00:00
|
|
|
c.Assert(b.Start(ipn.Options{}), qt.IsNil)
|
2021-04-30 03:18:50 +00:00
|
|
|
{
|
2022-11-15 04:17:28 +00:00
|
|
|
previousCC.assertShutdown(false)
|
2021-04-30 03:18:50 +00:00
|
|
|
// BUG: We already called Shutdown(), no need to do it again.
|
2021-04-30 07:56:11 +00:00
|
|
|
// BUG: don't unpause because we're not logged in.
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls("New")
|
2021-04-30 03:18:50 +00:00
|
|
|
|
|
|
|
nn := notifies.drain(2)
|
2021-09-15 23:05:10 +00:00
|
|
|
cc.assertCalls()
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].Prefs, qt.IsNotNil)
|
|
|
|
c.Assert(nn[1].State, qt.IsNotNil)
|
2022-10-23 17:07:10 +00:00
|
|
|
c.Assert(nn[0].Prefs.LoggedOut(), qt.IsTrue)
|
|
|
|
c.Assert(nn[0].Prefs.WantRunning(), qt.IsFalse)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, *nn[1].State)
|
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 12:39:29 +00:00
|
|
|
b.Login(nil)
|
2021-04-30 03:18:50 +00:00
|
|
|
t.Logf("\n\nLoginFinished3")
|
2021-04-30 07:56:11 +00:00
|
|
|
notifies.expect(3)
|
2022-11-17 14:05:02 +00:00
|
|
|
cc.persist.UserProfile.LoginName = "user2"
|
2023-02-07 05:18:21 +00:00
|
|
|
cc.persist.NodeID = "node2"
|
2021-04-30 03:18:50 +00:00
|
|
|
cc.send(nil, "", true, &netmap.NetworkMap{
|
|
|
|
MachineStatus: tailcfg.MachineAuthorized,
|
|
|
|
})
|
|
|
|
{
|
2021-04-30 07:56:11 +00:00
|
|
|
nn := notifies.drain(3)
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls("Login")
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].LoginFinished, qt.IsNotNil)
|
|
|
|
c.Assert(nn[1].Prefs, qt.IsNotNil)
|
2022-11-12 12:39:29 +00:00
|
|
|
c.Assert(nn[1].Prefs.Persist(), qt.IsNotNil)
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[2].State, qt.IsNotNil)
|
2021-05-06 03:28:29 +00:00
|
|
|
// Prefs after finishing the login, so LoginName updated.
|
2023-08-04 00:38:28 +00:00
|
|
|
c.Assert(nn[1].Prefs.Persist().UserProfile().LoginName(), qt.Equals, "user2")
|
2022-10-23 17:07:10 +00:00
|
|
|
c.Assert(nn[1].Prefs.LoggedOut(), qt.IsFalse)
|
|
|
|
c.Assert(nn[1].Prefs.WantRunning(), qt.IsTrue)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(ipn.Starting, qt.Equals, *nn[2].State)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now we've logged in successfully. Let's disconnect.
|
|
|
|
t.Logf("\n\nWantRunning -> false")
|
|
|
|
notifies.expect(2)
|
|
|
|
b.EditPrefs(&ipn.MaskedPrefs{
|
|
|
|
WantRunningSet: true,
|
|
|
|
Prefs: ipn.Prefs{WantRunning: false},
|
|
|
|
})
|
|
|
|
{
|
|
|
|
nn := notifies.drain(2)
|
2021-09-15 23:05:10 +00:00
|
|
|
cc.assertCalls("pause")
|
2021-04-30 03:18:50 +00:00
|
|
|
// BUG: I would expect Prefs to change first, and state after.
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].State, qt.IsNotNil)
|
|
|
|
c.Assert(nn[1].Prefs, qt.IsNotNil)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(ipn.Stopped, qt.Equals, *nn[0].State)
|
2022-10-23 17:07:10 +00:00
|
|
|
c.Assert(nn[1].Prefs.LoggedOut(), qt.IsFalse)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// One more restart, this time with a valid key, but WantRunning=false.
|
|
|
|
t.Logf("\n\nStart4")
|
|
|
|
notifies.expect(2)
|
2022-11-09 05:58:10 +00:00
|
|
|
c.Assert(b.Start(ipn.Options{}), qt.IsNil)
|
2021-04-30 03:18:50 +00:00
|
|
|
{
|
|
|
|
// NOTE: cc.Shutdown() is correct here, since we didn't call
|
|
|
|
// b.Shutdown() explicitly ourselves.
|
2022-11-15 04:17:28 +00:00
|
|
|
previousCC.assertShutdown(false)
|
|
|
|
|
2021-04-30 10:08:26 +00:00
|
|
|
// Note: unpause happens because ipn needs to get at least one netmap
|
|
|
|
// on startup, otherwise UIs can't show the node list, login
|
|
|
|
// name, etc when in state ipn.Stopped.
|
|
|
|
// Arguably they shouldn't try. But they currently do.
|
2021-04-30 03:18:50 +00:00
|
|
|
nn := notifies.drain(2)
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls("New", "Login")
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].Prefs, qt.IsNotNil)
|
|
|
|
c.Assert(nn[1].State, qt.IsNotNil)
|
2022-10-23 17:07:10 +00:00
|
|
|
c.Assert(nn[0].Prefs.WantRunning(), qt.IsFalse)
|
|
|
|
c.Assert(nn[0].Prefs.LoggedOut(), qt.IsFalse)
|
2022-11-12 12:39:29 +00:00
|
|
|
c.Assert(*nn[1].State, qt.Equals, ipn.Stopped)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
2021-07-17 06:06:14 +00:00
|
|
|
// When logged in but !WantRunning, ipn leaves us unpaused to retrieve
|
|
|
|
// the first netmap. Simulate that netmap being received, after which
|
|
|
|
// it should pause us, to avoid wasting CPU retrieving unnecessarily
|
|
|
|
// additional netmap updates.
|
|
|
|
//
|
|
|
|
// TODO: really the various GUIs and prefs should be refactored to
|
|
|
|
// not require the netmap structure at all when starting while
|
|
|
|
// !WantRunning. That would remove the need for this (or contacting
|
|
|
|
// the control server at all when stopped).
|
|
|
|
t.Logf("\n\nStart4 -> netmap")
|
|
|
|
notifies.expect(0)
|
|
|
|
cc.send(nil, "", true, &netmap.NetworkMap{
|
|
|
|
MachineStatus: tailcfg.MachineAuthorized,
|
|
|
|
})
|
|
|
|
{
|
|
|
|
notifies.drain(0)
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls("pause")
|
2021-07-17 06:06:14 +00:00
|
|
|
}
|
|
|
|
|
2021-04-30 07:56:11 +00:00
|
|
|
// Request connection.
|
|
|
|
// The state machine didn't call Login() earlier, so now it needs to.
|
|
|
|
t.Logf("\n\nWantRunning4 -> true")
|
|
|
|
notifies.expect(2)
|
|
|
|
b.EditPrefs(&ipn.MaskedPrefs{
|
|
|
|
WantRunningSet: true,
|
|
|
|
Prefs: ipn.Prefs{WantRunning: true},
|
|
|
|
})
|
|
|
|
{
|
|
|
|
nn := notifies.drain(2)
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls("Login", "unpause")
|
2021-04-30 07:56:11 +00:00
|
|
|
// BUG: I would expect Prefs to change first, and state after.
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].State, qt.IsNotNil)
|
|
|
|
c.Assert(nn[1].Prefs, qt.IsNotNil)
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(ipn.Starting, qt.Equals, *nn[0].State)
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 03:28:29 +00:00
|
|
|
// Disconnect.
|
|
|
|
t.Logf("\n\nStop")
|
|
|
|
notifies.expect(2)
|
|
|
|
b.EditPrefs(&ipn.MaskedPrefs{
|
|
|
|
WantRunningSet: true,
|
|
|
|
Prefs: ipn.Prefs{WantRunning: false},
|
|
|
|
})
|
|
|
|
{
|
|
|
|
nn := notifies.drain(2)
|
2021-09-15 23:05:10 +00:00
|
|
|
cc.assertCalls("pause")
|
2021-05-06 03:28:29 +00:00
|
|
|
// BUG: I would expect Prefs to change first, and state after.
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].State, qt.IsNotNil)
|
|
|
|
c.Assert(nn[1].Prefs, qt.IsNotNil)
|
2021-05-06 03:28:29 +00:00
|
|
|
c.Assert(ipn.Stopped, qt.Equals, *nn[0].State)
|
|
|
|
}
|
|
|
|
|
|
|
|
// We want to try logging in as a different user, while Stopped.
|
|
|
|
// First, start the login process (without logging out first).
|
|
|
|
t.Logf("\n\nLoginDifferent")
|
2021-07-17 06:06:14 +00:00
|
|
|
notifies.expect(1)
|
2021-05-06 03:28:29 +00:00
|
|
|
b.StartLoginInteractive()
|
2022-11-16 16:18:28 +00:00
|
|
|
url3 := "https://localhost:1/3"
|
2021-05-06 03:28:29 +00:00
|
|
|
cc.send(nil, url3, false, nil)
|
|
|
|
{
|
2021-07-17 06:06:14 +00:00
|
|
|
nn := notifies.drain(1)
|
2021-05-06 03:28:29 +00:00
|
|
|
// It might seem like WantRunning should switch to true here,
|
|
|
|
// but that would be risky since we already have a valid
|
|
|
|
// user account. It might try to reconnect to the old account
|
|
|
|
// before the new one is ready. So no change yet.
|
2021-07-17 06:06:14 +00:00
|
|
|
//
|
|
|
|
// Because the login hasn't yet completed, the old login
|
|
|
|
// is still valid, so it's correct that we stay paused.
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls("Login")
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].BrowseToURL, qt.IsNotNil)
|
2021-05-06 03:28:29 +00:00
|
|
|
c.Assert(*nn[0].BrowseToURL, qt.Equals, url3)
|
|
|
|
}
|
|
|
|
|
2021-07-17 06:06:14 +00:00
|
|
|
// Now, let's complete the interactive login, using a different
|
|
|
|
// user account than before. WantRunning changes to true after an
|
|
|
|
// interactive login, so we end up unpaused.
|
2021-05-06 03:28:29 +00:00
|
|
|
t.Logf("\n\nLoginDifferent URL visited")
|
|
|
|
notifies.expect(3)
|
2022-11-17 14:05:02 +00:00
|
|
|
cc.persist.UserProfile.LoginName = "user3"
|
2023-02-07 05:18:21 +00:00
|
|
|
cc.persist.NodeID = "node3"
|
2021-05-06 03:28:29 +00:00
|
|
|
cc.send(nil, "", true, &netmap.NetworkMap{
|
|
|
|
MachineStatus: tailcfg.MachineAuthorized,
|
|
|
|
})
|
|
|
|
{
|
|
|
|
nn := notifies.drain(3)
|
2021-07-17 06:06:14 +00:00
|
|
|
// BUG: pause() being called here is a bad sign.
|
|
|
|
// It means that either the state machine ran at least once
|
|
|
|
// with the old netmap, or it ran with the new login+netmap
|
|
|
|
// and !WantRunning. But since it's a fresh and successful
|
|
|
|
// new login, WantRunning is true, so there was never a
|
|
|
|
// reason to pause().
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls("unpause")
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].LoginFinished, qt.IsNotNil)
|
|
|
|
c.Assert(nn[1].Prefs, qt.IsNotNil)
|
|
|
|
c.Assert(nn[2].State, qt.IsNotNil)
|
2021-05-06 03:28:29 +00:00
|
|
|
// Prefs after finishing the login, so LoginName updated.
|
2023-08-04 00:38:28 +00:00
|
|
|
c.Assert(nn[1].Prefs.Persist().UserProfile().LoginName(), qt.Equals, "user3")
|
2022-10-23 17:07:10 +00:00
|
|
|
c.Assert(nn[1].Prefs.LoggedOut(), qt.IsFalse)
|
|
|
|
c.Assert(nn[1].Prefs.WantRunning(), qt.IsTrue)
|
2021-05-06 03:28:29 +00:00
|
|
|
c.Assert(ipn.Starting, qt.Equals, *nn[2].State)
|
|
|
|
}
|
|
|
|
|
2021-04-30 03:18:50 +00:00
|
|
|
// The last test case is the most common one: restarting when both
|
|
|
|
// logged in and WantRunning.
|
|
|
|
t.Logf("\n\nStart5")
|
2022-11-15 04:17:28 +00:00
|
|
|
notifies.expect(2)
|
2022-11-09 05:58:10 +00:00
|
|
|
c.Assert(b.Start(ipn.Options{}), qt.IsNil)
|
2021-04-30 03:18:50 +00:00
|
|
|
{
|
|
|
|
// NOTE: cc.Shutdown() is correct here, since we didn't call
|
|
|
|
// b.Shutdown() ourselves.
|
2022-11-15 04:17:28 +00:00
|
|
|
previousCC.assertShutdown(false)
|
|
|
|
cc.assertCalls("New", "Login")
|
2021-04-30 03:18:50 +00:00
|
|
|
|
2022-11-15 04:17:28 +00:00
|
|
|
nn := notifies.drain(2)
|
2021-09-15 23:05:10 +00:00
|
|
|
cc.assertCalls()
|
2021-09-15 22:16:19 +00:00
|
|
|
c.Assert(nn[0].Prefs, qt.IsNotNil)
|
2022-10-23 17:07:10 +00:00
|
|
|
c.Assert(nn[0].Prefs.LoggedOut(), qt.IsFalse)
|
|
|
|
c.Assert(nn[0].Prefs.WantRunning(), qt.IsTrue)
|
2022-11-15 04:17:28 +00:00
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Control server accepts our valid key from before.
|
|
|
|
t.Logf("\n\nLoginFinished5")
|
2022-11-15 04:17:28 +00:00
|
|
|
notifies.expect(2)
|
2021-04-30 03:18:50 +00:00
|
|
|
cc.send(nil, "", true, &netmap.NetworkMap{
|
|
|
|
MachineStatus: tailcfg.MachineAuthorized,
|
|
|
|
})
|
|
|
|
{
|
2022-11-15 04:17:28 +00:00
|
|
|
nn := notifies.drain(2)
|
|
|
|
cc.assertCalls()
|
2021-05-06 03:28:29 +00:00
|
|
|
// NOTE: No LoginFinished message since no interactive
|
|
|
|
// login was needed.
|
2022-11-15 04:17:28 +00:00
|
|
|
c.Assert(nn[1].State, qt.IsNotNil)
|
|
|
|
c.Assert(ipn.Starting, qt.Equals, *nn[1].State)
|
2021-04-30 03:18:50 +00:00
|
|
|
// NOTE: No prefs change this time. WantRunning stays true.
|
2021-04-30 07:56:11 +00:00
|
|
|
// We were in Starting in the first place, so that doesn't
|
|
|
|
// change either.
|
2021-04-30 21:47:16 +00:00
|
|
|
c.Assert(ipn.Starting, qt.Equals, b.State())
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
2021-11-04 19:19:00 +00:00
|
|
|
t.Logf("\n\nExpireKey")
|
|
|
|
notifies.expect(1)
|
|
|
|
cc.send(nil, "", false, &netmap.NetworkMap{
|
|
|
|
Expiry: time.Now().Add(-time.Minute),
|
|
|
|
MachineStatus: tailcfg.MachineAuthorized,
|
|
|
|
})
|
|
|
|
{
|
|
|
|
nn := notifies.drain(1)
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls()
|
2021-11-04 19:19:00 +00:00
|
|
|
c.Assert(nn[0].State, qt.IsNotNil)
|
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, *nn[0].State)
|
|
|
|
c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
|
|
|
|
c.Assert(b.isEngineBlocked(), qt.IsTrue)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("\n\nExtendKey")
|
|
|
|
notifies.expect(1)
|
|
|
|
cc.send(nil, "", false, &netmap.NetworkMap{
|
|
|
|
Expiry: time.Now().Add(time.Minute),
|
|
|
|
MachineStatus: tailcfg.MachineAuthorized,
|
|
|
|
})
|
|
|
|
{
|
|
|
|
nn := notifies.drain(1)
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls()
|
2021-11-04 19:19:00 +00:00
|
|
|
c.Assert(nn[0].State, qt.IsNotNil)
|
|
|
|
c.Assert(ipn.Starting, qt.Equals, *nn[0].State)
|
|
|
|
c.Assert(ipn.Starting, qt.Equals, b.State())
|
|
|
|
c.Assert(b.isEngineBlocked(), qt.IsFalse)
|
|
|
|
}
|
|
|
|
notifies.expect(1)
|
|
|
|
// Fake a DERP connection.
|
2022-03-27 03:12:12 +00:00
|
|
|
b.setWgengineStatus(&wgengine.Status{DERPs: 1, AsOf: time.Now()}, nil)
|
2021-11-04 19:19:00 +00:00
|
|
|
{
|
|
|
|
nn := notifies.drain(1)
|
2022-11-15 04:17:28 +00:00
|
|
|
cc.assertCalls()
|
2021-11-04 19:19:00 +00:00
|
|
|
c.Assert(nn[0].State, qt.IsNotNil)
|
|
|
|
c.Assert(ipn.Running, qt.Equals, *nn[0].State)
|
|
|
|
c.Assert(ipn.Running, qt.Equals, b.State())
|
|
|
|
}
|
2021-04-30 03:18:50 +00:00
|
|
|
}
|
2021-07-12 03:10:02 +00:00
|
|
|
|
2022-10-24 00:15:04 +00:00
|
|
|
func TestEditPrefsHasNoKeys(t *testing.T) {
|
2022-11-02 19:45:20 +00:00
|
|
|
logf := tstest.WhileTestRunningLogger(t)
|
2023-05-03 20:57:17 +00:00
|
|
|
sys := new(tsd.System)
|
|
|
|
sys.Set(new(mem.Store))
|
|
|
|
e, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set)
|
2022-10-24 00:15:04 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("NewFakeUserspaceEngine: %v", err)
|
|
|
|
}
|
|
|
|
t.Cleanup(e.Close)
|
2023-05-03 20:57:17 +00:00
|
|
|
sys.Set(e)
|
2022-10-24 00:15:04 +00:00
|
|
|
|
2023-05-03 20:57:17 +00:00
|
|
|
b, err := NewLocalBackend(logf, logid.PublicID{}, sys, 0)
|
2022-10-24 00:15:04 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("NewLocalBackend: %v", err)
|
|
|
|
}
|
|
|
|
b.hostinfo = &tailcfg.Hostinfo{OS: "testos"}
|
2022-11-09 05:58:10 +00:00
|
|
|
b.pm.SetPrefs((&ipn.Prefs{
|
2022-10-24 00:15:04 +00:00
|
|
|
Persist: &persist.Persist{
|
|
|
|
PrivateNodeKey: key.NewNode(),
|
|
|
|
OldPrivateNodeKey: key.NewNode(),
|
|
|
|
|
|
|
|
LegacyFrontendPrivateMachineKey: key.NewMachine(),
|
|
|
|
},
|
2022-11-09 05:58:10 +00:00
|
|
|
}).View())
|
2022-11-29 20:00:40 +00:00
|
|
|
if p := b.pm.CurrentPrefs().Persist(); !p.Valid() || p.PrivateNodeKey().IsZero() {
|
2022-10-24 00:15:04 +00:00
|
|
|
t.Fatalf("PrivateNodeKey not set")
|
|
|
|
}
|
|
|
|
p, err := b.EditPrefs(&ipn.MaskedPrefs{
|
|
|
|
Prefs: ipn.Prefs{
|
|
|
|
Hostname: "foo",
|
|
|
|
},
|
|
|
|
HostnameSet: true,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("EditPrefs: %v", err)
|
|
|
|
}
|
|
|
|
if p.Hostname() != "foo" {
|
|
|
|
t.Errorf("Hostname = %q; want foo", p.Hostname())
|
|
|
|
}
|
|
|
|
|
2022-11-29 20:00:40 +00:00
|
|
|
if !p.Persist().PrivateNodeKey().IsZero() {
|
|
|
|
t.Errorf("PrivateNodeKey = %v; want zero", p.Persist().PrivateNodeKey())
|
2022-10-24 00:15:04 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 20:00:40 +00:00
|
|
|
if !p.Persist().OldPrivateNodeKey().IsZero() {
|
|
|
|
t.Errorf("OldPrivateNodeKey = %v; want zero", p.Persist().OldPrivateNodeKey())
|
2022-10-24 00:15:04 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 20:00:40 +00:00
|
|
|
if !p.Persist().LegacyFrontendPrivateMachineKey().IsZero() {
|
|
|
|
t.Errorf("LegacyFrontendPrivateMachineKey = %v; want zero", p.Persist().LegacyFrontendPrivateMachineKey())
|
2022-10-24 00:15:04 +00:00
|
|
|
}
|
2022-11-18 19:23:57 +00:00
|
|
|
|
2022-11-29 20:00:40 +00:00
|
|
|
if !p.Persist().NetworkLockKey().IsZero() {
|
|
|
|
t.Errorf("NetworkLockKey= %v; want zero", p.Persist().NetworkLockKey())
|
2022-11-18 19:23:57 +00:00
|
|
|
}
|
2022-10-24 00:15:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-12 03:10:02 +00:00
|
|
|
type testStateStorage struct {
|
2022-02-28 21:08:45 +00:00
|
|
|
mem mem.Store
|
2022-08-04 04:51:02 +00:00
|
|
|
written atomic.Bool
|
2021-07-12 03:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *testStateStorage) ReadState(id ipn.StateKey) ([]byte, error) {
|
|
|
|
return s.mem.ReadState(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *testStateStorage) WriteState(id ipn.StateKey, bs []byte) error {
|
2022-08-04 04:51:02 +00:00
|
|
|
s.written.Store(true)
|
2021-07-12 03:10:02 +00:00
|
|
|
return s.mem.WriteState(id, bs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// awaitWrite clears the "I've seen writes" bit, in prep for a future
|
|
|
|
// call to sawWrite to see if a write arrived.
|
2022-08-04 04:51:02 +00:00
|
|
|
func (s *testStateStorage) awaitWrite() { s.written.Store(false) }
|
2021-07-12 03:10:02 +00:00
|
|
|
|
|
|
|
// sawWrite reports whether there's been a WriteState call since the most
|
|
|
|
// recent awaitWrite call.
|
|
|
|
func (s *testStateStorage) sawWrite() bool {
|
2022-08-04 04:51:02 +00:00
|
|
|
v := s.written.Load()
|
2021-07-12 03:10:02 +00:00
|
|
|
s.awaitWrite()
|
|
|
|
return v
|
|
|
|
}
|
2021-09-15 18:57:12 +00:00
|
|
|
|
|
|
|
func TestWGEngineStatusRace(t *testing.T) {
|
|
|
|
t.Skip("test fails")
|
|
|
|
c := qt.New(t)
|
2022-11-02 19:45:20 +00:00
|
|
|
logf := tstest.WhileTestRunningLogger(t)
|
2023-05-03 20:57:17 +00:00
|
|
|
sys := new(tsd.System)
|
|
|
|
sys.Set(new(mem.Store))
|
|
|
|
|
|
|
|
eng, err := wgengine.NewFakeUserspaceEngine(logf, sys.Set)
|
2021-09-15 18:57:12 +00:00
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
t.Cleanup(eng.Close)
|
2023-05-03 20:57:17 +00:00
|
|
|
sys.Set(eng)
|
|
|
|
b, err := NewLocalBackend(logf, logid.PublicID{}, sys, 0)
|
2021-09-15 18:57:12 +00:00
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
|
2022-11-15 04:17:28 +00:00
|
|
|
var cc *mockControl
|
2021-09-15 18:57:12 +00:00
|
|
|
b.SetControlClientGetterForTesting(func(opts controlclient.Options) (controlclient.Client, error) {
|
2022-11-15 04:17:28 +00:00
|
|
|
cc = newClient(t, opts)
|
2021-09-15 18:57:12 +00:00
|
|
|
return cc, nil
|
|
|
|
})
|
|
|
|
|
|
|
|
var state ipn.State
|
|
|
|
b.SetNotifyCallback(func(n ipn.Notify) {
|
|
|
|
if n.State != nil {
|
|
|
|
state = *n.State
|
|
|
|
}
|
|
|
|
})
|
|
|
|
wantState := func(want ipn.State) {
|
|
|
|
c.Assert(want, qt.Equals, state)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start with the zero value.
|
|
|
|
wantState(ipn.NoState)
|
|
|
|
|
|
|
|
// Start the backend.
|
2022-11-09 05:58:10 +00:00
|
|
|
err = b.Start(ipn.Options{})
|
2021-09-15 18:57:12 +00:00
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
wantState(ipn.NeedsLogin)
|
|
|
|
|
|
|
|
// Assert that we are logged in and authorized.
|
|
|
|
cc.send(nil, "", true, &netmap.NetworkMap{
|
|
|
|
MachineStatus: tailcfg.MachineAuthorized,
|
|
|
|
})
|
|
|
|
wantState(ipn.Starting)
|
|
|
|
|
|
|
|
// Simulate multiple concurrent callbacks from wgengine.
|
|
|
|
// Any single callback with DERPS > 0 is enough to transition
|
|
|
|
// from Starting to Running, at which point we stay there.
|
|
|
|
// Thus if these callbacks occurred serially, in any order,
|
|
|
|
// we would end up in state ipn.Running.
|
|
|
|
// The same should thus be true if these callbacks occur concurrently.
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func(i int) {
|
|
|
|
defer wg.Done()
|
|
|
|
n := 0
|
|
|
|
if i == 0 {
|
|
|
|
n = 1
|
|
|
|
}
|
2022-03-27 03:12:12 +00:00
|
|
|
b.setWgengineStatus(&wgengine.Status{AsOf: time.Now(), DERPs: n}, nil)
|
2021-09-15 18:57:12 +00:00
|
|
|
}(i)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
wantState(ipn.Running)
|
|
|
|
}
|