mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-13 02:10:56 +01:00
0c039274a4
This update adds new relay integration for NetBird clients. The new relay is based on web sockets and listens on a single port. - Adds new relay implementation with websocket with single port relaying mechanism - refactor peer connection logic, allowing upgrade and downgrade from/to P2P connection - peer connections are faster since it connects first to relay and then upgrades to P2P - maintains compatibility with old clients by not using the new relay - updates infrastructure scripts with new relay service
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
const (
|
|
exampleConfig = `{
|
|
"Relay": {
|
|
"Addresses": [
|
|
"rel://192.168.100.1:8085",
|
|
"rel://192.168.100.1:8086"
|
|
],
|
|
"CredentialsTTL": "12h0m0s",
|
|
"Secret": "8f7e9d6c5b4a3f2e1d0c9b8a7f6e5d4c3b2a1f0e9d8c7b6a5f4e3d2c1b0a9f8"
|
|
},
|
|
"HttpConfig": {
|
|
"AuthAudience": "https://stageapp/",
|
|
"AuthIssuer": "https://something.eu.auth0.com/",
|
|
"OIDCConfigEndpoint": "https://something.eu.auth0.com/.well-known/openid-configuration"
|
|
}
|
|
}`
|
|
)
|
|
|
|
func Test_loadMgmtConfig(t *testing.T) {
|
|
tmpFile, err := createConfig()
|
|
if err != nil {
|
|
t.Fatalf("failed to create config: %s", err)
|
|
}
|
|
|
|
cfg, err := loadMgmtConfig(context.Background(), tmpFile)
|
|
if err != nil {
|
|
t.Fatalf("failed to load management config: %s", err)
|
|
}
|
|
if cfg.Relay == nil {
|
|
t.Fatalf("config is nil")
|
|
}
|
|
if len(cfg.Relay.Addresses) == 0 {
|
|
t.Fatalf("relay address is empty")
|
|
}
|
|
}
|
|
|
|
func createConfig() (string, error) {
|
|
tmpfile, err := os.CreateTemp("", "config.json")
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
_, err = tmpfile.Write([]byte(exampleConfig))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if err := tmpfile.Close(); err != nil {
|
|
return "", err
|
|
}
|
|
return tmpfile.Name(), nil
|
|
}
|