mirror of
https://github.com/netbirdio/netbird.git
synced 2025-04-16 15:38:42 +02:00
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/wiretrustee/wiretrustee/client/internal"
|
|
"github.com/wiretrustee/wiretrustee/iface"
|
|
mgmt "github.com/wiretrustee/wiretrustee/management/server"
|
|
"github.com/wiretrustee/wiretrustee/util"
|
|
)
|
|
|
|
var mgmAddr string
|
|
|
|
func TestLogin_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)
|
|
}
|
|
_, listener := startManagement(t, config)
|
|
mgmAddr = listener.Addr().String()
|
|
}
|
|
|
|
func TestLogin(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
confPath := tempDir + "/config.json"
|
|
mgmtURL := fmt.Sprintf("http://%s", mgmAddr)
|
|
rootCmd.SetArgs([]string{
|
|
"login",
|
|
"--config",
|
|
confPath,
|
|
"--log-file",
|
|
"console",
|
|
"--setup-key",
|
|
strings.ToUpper("a2c8e62b-38f5-4553-b31e-dd66c696cebb"),
|
|
"--management-url",
|
|
mgmtURL,
|
|
})
|
|
err := rootCmd.Execute()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// validate generated config
|
|
actualConf := &internal.Config{}
|
|
_, err = util.ReadJson(confPath, actualConf)
|
|
if err != nil {
|
|
t.Errorf("expected proper config file written, got broken %v", err)
|
|
}
|
|
|
|
if actualConf.ManagementURL.String() != mgmtURL {
|
|
t.Errorf("expected management URL %s got %s", mgmtURL, actualConf.ManagementURL.String())
|
|
}
|
|
|
|
if actualConf.WgIface != iface.WgInterfaceDefault {
|
|
t.Errorf("expected WgIfaceName %s got %s", iface.WgInterfaceDefault, actualConf.WgIface)
|
|
}
|
|
|
|
if len(actualConf.PrivateKey) == 0 {
|
|
t.Errorf("expected non empty Private key, got empty")
|
|
}
|
|
}
|