Files
netbird/client/internal/engine_bundle_test.go
T
riccardom cac6cba096 [management,client] Carry the debug upload destination on PeerConfig
A destination set from the dashboard never reached a connected peer. The peer
fan-out that follows a settings change builds its sync with a nil server config,
and toNetbirdConfig returns nil for that, so no NetbirdConfig went out at all and
the peer kept whatever it had. The new URL only arrived when the peer
reconnected, and until then its bundles kept going to NetBird's upload service —
which is the disclosure this PR exists to close.

PeerConfig is the message the fan-out already fills from the account settings,
alongside the other knobs an operator flips at runtime: lazy connection, MTU,
routing-peer DNS resolution, auto-update. The destination belongs with them.
Sending a partial NetbirdConfig from the fan-out instead would be worse: clients
treat a non-nil one as authoritative for relay and would drop their relay URLs.

Start now reads the destination off the PeerConfig it was given in the previous
commit, for the same reason it used to read it off NetbirdConfig: without it, a
bundle collected between login and the first sync sees no destination, and the
first seconds after a start are exactly when someone collects a bundle about a
start that went wrong.

DebugConfig is removed rather than deprecated. It was added earlier in this
branch and has never been in a release, so no deployed client reads it.
2026-10-09 11:06:29 +02:00

64 lines
2.5 KiB
Go

package internal
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
mgmProto "github.com/netbirdio/netbird/shared/management/proto"
)
// TestValidateBundleUploadURL covers the sanity check applied to a
// management-supplied upload URL before a remote debug bundle is generated.
func TestValidateBundleUploadURL(t *testing.T) {
for _, tc := range []struct {
name string
raw string
wantErr bool
}{
{name: "empty defers to the deployment destination", raw: ""},
{name: "https with host", raw: "https://upload.debug.netbird.io/upload"},
{name: "https self-hosted host", raw: "https://upload.example.com"},
{name: "plaintext rejected", raw: "http://upload.example.com", wantErr: true},
{name: "missing host rejected", raw: "https:///upload", wantErr: true},
{name: "port-only authority rejected", raw: "https://:443", wantErr: true},
{name: "non-url scheme rejected", raw: "ftp://upload.example.com", wantErr: true},
{name: "garbage rejected", raw: "://not a url", wantErr: true},
} {
t.Run(tc.name, func(t *testing.T) {
err := validateBundleUploadURL(tc.raw)
if tc.wantErr {
require.Error(t, err, "an invalid upload URL must be rejected")
return
}
assert.NoError(t, err, "a valid or empty upload URL must be accepted")
})
}
}
// TestEngineDebugUploadURL covers the destination the management server
// publishes: the engine keeps the last value it saw so the bundle paths, which
// run off the engine loop, do not have to re-read a sync response.
func TestEngineDebugUploadURL(t *testing.T) {
e := &Engine{}
assert.Empty(t, e.DebugUploadURL(), "a peer that never synced publishes no destination")
e.handleDebugUploadUpdate(nil)
assert.Empty(t, e.DebugUploadURL(), "a management server predating the field publishes none")
e.handleDebugUploadUpdate(&mgmProto.PeerConfig{DebugBundleUploadUrl: "https://upload.example.com/upload-url"})
assert.Equal(t, "https://upload.example.com/upload-url", e.DebugUploadURL())
// A partial update ships a SyncResponse with no PeerConfig at all. Treating
// that as "no destination" would drop the operator's choice.
e.handleDebugUploadUpdate(nil)
assert.Equal(t, "https://upload.example.com/upload-url", e.DebugUploadURL(),
"a partial update must not clear the published destination")
// An operator that removes the destination sends a PeerConfig with an empty
// URL, and that does reach the peer.
e.handleDebugUploadUpdate(&mgmProto.PeerConfig{})
assert.Empty(t, e.DebugUploadURL())
}