2021-08-18 13:35:42 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/wiretrustee/wiretrustee/iface"
|
|
|
|
mgmt "github.com/wiretrustee/wiretrustee/management/server"
|
|
|
|
"github.com/wiretrustee/wiretrustee/util"
|
|
|
|
"net/url"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var signalAddr string
|
|
|
|
|
|
|
|
func TestUp_Start(t *testing.T) {
|
|
|
|
config := &mgmt.Config{}
|
|
|
|
_, err := util.ReadJson("../testdata/management.json", config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
testDir := t.TempDir()
|
|
|
|
config.Datadir = testDir
|
|
|
|
err = util.CopyFileContents("../testdata/store.json", filepath.Join(testDir, "store.json"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, signalLis := startSignal(t)
|
|
|
|
signalAddr = signalLis.Addr().String()
|
|
|
|
config.Signal.URI = signalAddr
|
|
|
|
|
|
|
|
_, mgmLis := startManagement(config, t)
|
|
|
|
mgmAddr = mgmLis.Addr().String()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUp(t *testing.T) {
|
|
|
|
|
2022-01-17 14:01:58 +01:00
|
|
|
//defer iface.Close("wt0")
|
2021-08-18 13:35:42 +02:00
|
|
|
|
|
|
|
tempDir := t.TempDir()
|
|
|
|
confPath := tempDir + "/config.json"
|
|
|
|
mgmtURL, err := url.Parse("http://" + mgmAddr)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-10-17 21:34:07 +02:00
|
|
|
|
2021-08-18 13:35:42 +02:00
|
|
|
rootCmd.SetArgs([]string{
|
2021-10-17 21:34:07 +02:00
|
|
|
"up",
|
2021-08-18 13:35:42 +02:00
|
|
|
"--config",
|
|
|
|
confPath,
|
|
|
|
"--setup-key",
|
2021-08-20 15:55:28 +02:00
|
|
|
"A2C8E62B-38F5-4553-B31E-DD66C696CEBB",
|
2021-08-18 13:35:42 +02:00
|
|
|
"--management-url",
|
|
|
|
mgmtURL.String(),
|
2022-01-17 14:01:58 +01:00
|
|
|
"--log-level",
|
|
|
|
"debug",
|
2021-10-17 21:34:07 +02:00
|
|
|
"--log-file",
|
|
|
|
"console",
|
2021-08-18 13:35:42 +02:00
|
|
|
})
|
|
|
|
go func() {
|
|
|
|
err = rootCmd.Execute()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("expected no error while running up command, got %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2022-01-17 14:01:58 +01:00
|
|
|
timeout := 15 * time.Second
|
|
|
|
timeoutChannel := time.After(timeout)
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-timeoutChannel:
|
|
|
|
t.Fatalf("expected wireguard interface %s to be created before %s", iface.WgInterfaceDefault, timeout.String())
|
|
|
|
default:
|
|
|
|
}
|
2021-08-18 13:35:42 +02:00
|
|
|
e, err := iface.Exists(iface.WgInterfaceDefault)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2022-01-17 14:01:58 +01:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2021-08-18 13:35:42 +02:00
|
|
|
if *e {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|