mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
ipn/ipnlocal: on fresh lazy-connecting install, start in state NeedsLogin
Fixes #1759 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
a29b0cf55f
commit
09891b9868
@ -597,6 +597,9 @@ func (c *Client) mapRoutine() {
|
||||
}
|
||||
|
||||
func (c *Client) AuthCantContinue() bool {
|
||||
if c == nil {
|
||||
return true
|
||||
}
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
|
@ -603,6 +603,7 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
|
||||
return errors.New("no state key or prefs provided")
|
||||
}
|
||||
|
||||
defer b.stateMachine()
|
||||
if opts.Prefs != nil {
|
||||
b.logf("Start: %v", opts.Prefs.Pretty())
|
||||
} else {
|
||||
|
@ -5,14 +5,20 @@
|
||||
package ipnlocal
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"inet.af/netaddr"
|
||||
"tailscale.com/ipn"
|
||||
"tailscale.com/net/interfaces"
|
||||
"tailscale.com/net/tsaddr"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/netmap"
|
||||
"tailscale.com/wgengine"
|
||||
"tailscale.com/wgengine/wgcfg"
|
||||
)
|
||||
|
||||
@ -419,3 +425,48 @@ func TestPeerAPIBase(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type panicOnUseTransport struct{}
|
||||
|
||||
func (panicOnUseTransport) RoundTrip(*http.Request) (*http.Response, error) {
|
||||
panic("unexpected HTTP request")
|
||||
}
|
||||
|
||||
var nl = []byte("\n")
|
||||
|
||||
func TestStartsInNeedsLoginState(t *testing.T) {
|
||||
var (
|
||||
mu sync.Mutex
|
||||
logBuf bytes.Buffer
|
||||
)
|
||||
logf := func(format string, a ...interface{}) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
fmt.Fprintf(&logBuf, format, a...)
|
||||
if !bytes.HasSuffix(logBuf.Bytes(), nl) {
|
||||
logBuf.Write(nl)
|
||||
}
|
||||
}
|
||||
store := new(ipn.MemoryStore)
|
||||
eng, err := wgengine.NewFakeUserspaceEngine(logf, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("NewFakeUserspaceEngine: %v", err)
|
||||
}
|
||||
lb, err := NewLocalBackend(logf, "logid", store, eng)
|
||||
if err != nil {
|
||||
t.Fatalf("NewLocalBackend: %v", err)
|
||||
}
|
||||
|
||||
lb.SetHTTPTestClient(&http.Client{
|
||||
Transport: panicOnUseTransport{}, // validate we don't send HTTP requests
|
||||
})
|
||||
|
||||
if err := lb.Start(ipn.Options{
|
||||
StateKey: ipn.GlobalDaemonStateKey,
|
||||
}); err != nil {
|
||||
t.Fatalf("Start: %v", err)
|
||||
}
|
||||
if st := lb.State(); st != ipn.NeedsLogin {
|
||||
t.Errorf("State = %v; want NeedsLogin", st)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user