2020-03-03 17:15:11 +00:00
|
|
|
// 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/safesocket"
|
|
|
|
"tailscale.com/wgengine"
|
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
2020-10-02 23:42:56 +01:00
|
|
|
td := t.TempDir()
|
2020-03-03 17:15:11 +00:00
|
|
|
socketPath := filepath.Join(td, "tailscale.sock")
|
|
|
|
|
2020-05-15 21:13:44 +01:00
|
|
|
logf := func(format string, args ...interface{}) {
|
2020-03-03 17:15:11 +00:00
|
|
|
format = strings.TrimRight(format, "\n")
|
|
|
|
println(fmt.Sprintf(format, args...))
|
|
|
|
t.Logf(format, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
connect := func() {
|
|
|
|
for i := 1; i <= 2; i++ {
|
|
|
|
logf("connect %d ...", i)
|
|
|
|
c, err := safesocket.Connect(socketPath, 0)
|
|
|
|
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 ...interface{}) {
|
|
|
|
logf(format, args...)
|
|
|
|
if strings.HasPrefix(format, "Listening on ") {
|
|
|
|
connect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:45:41 +01:00
|
|
|
eng, err := wgengine.NewFakeUserspaceEngine(logf, 0, nil)
|
2020-03-03 17:15:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer eng.Close()
|
|
|
|
|
|
|
|
opts := ipnserver.Options{
|
|
|
|
SocketPath: socketPath,
|
|
|
|
}
|
|
|
|
t.Logf("pre-Run")
|
2020-07-29 21:38:09 +01:00
|
|
|
err = ipnserver.Run(ctx, logTriggerTestf, "dummy_logid", ipnserver.FixedEngine(eng), opts)
|
2020-03-03 17:15:11 +00:00
|
|
|
t.Logf("ipnserver.Run = %v", err)
|
|
|
|
}
|