mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 21:15:39 +00:00
a9b4bf1535
We weren't wiring up netstack.Impl to the LocalBackend in some cases on Windows. This fixes Windows 7 when run as a service. Updates #4750 (fixes after pull in to corp repo) Change-Id: I9ce51b797710f2bedfa90545776b7628c7528e99 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ipnserver_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"tailscale.com/ipn"
|
|
"tailscale.com/ipn/ipnserver"
|
|
"tailscale.com/ipn/store/mem"
|
|
"tailscale.com/net/tsdial"
|
|
"tailscale.com/safesocket"
|
|
"tailscale.com/wgengine"
|
|
"tailscale.com/wgengine/netstack"
|
|
)
|
|
|
|
func TestRunMultipleAccepts(t *testing.T) {
|
|
t.Skipf("TODO(bradfitz): finish this test, once other fires are out")
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
td := t.TempDir()
|
|
socketPath := filepath.Join(td, "tailscale.sock")
|
|
|
|
logf := func(format string, args ...any) {
|
|
format = strings.TrimRight(format, "\n")
|
|
println(fmt.Sprintf(format, args...))
|
|
t.Logf(format, args...)
|
|
}
|
|
|
|
s := safesocket.DefaultConnectionStrategy(socketPath)
|
|
connect := func() {
|
|
for i := 1; i <= 2; i++ {
|
|
logf("connect %d ...", i)
|
|
c, err := safesocket.Connect(s)
|
|
if err != nil {
|
|
t.Fatalf("safesocket.Connect: %v\n", err)
|
|
}
|
|
clientToServer := func(b []byte) {
|
|
ipn.WriteMsg(c, b)
|
|
}
|
|
bc := ipn.NewBackendClient(logf, clientToServer)
|
|
prefs := ipn.NewPrefs()
|
|
bc.SetPrefs(prefs)
|
|
c.Close()
|
|
}
|
|
}
|
|
|
|
logTriggerTestf := func(format string, args ...any) {
|
|
logf(format, args...)
|
|
if strings.HasPrefix(format, "Listening on ") {
|
|
connect()
|
|
}
|
|
}
|
|
|
|
eng, err := wgengine.NewFakeUserspaceEngine(logf, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(eng.Close)
|
|
|
|
opts := ipnserver.Options{}
|
|
t.Logf("pre-Run")
|
|
store := new(mem.Store)
|
|
|
|
ln, _, err := safesocket.Listen(socketPath, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer ln.Close()
|
|
|
|
err = ipnserver.Run(ctx, logTriggerTestf, ln, store, nil /* mon */, new(tsdial.Dialer), "dummy_logid", FixedEngine(eng), opts)
|
|
t.Logf("ipnserver.Run = %v", err)
|
|
}
|
|
|
|
// FixedEngine returns a func that returns eng and a nil error.
|
|
func FixedEngine(eng wgengine.Engine) func() (wgengine.Engine, *netstack.Impl, error) {
|
|
return func() (wgengine.Engine, *netstack.Impl, error) { return eng, nil, nil }
|
|
}
|