mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-02 11:39:06 +02:00
[client] Test remote-jobs config default and MDM application
Cover the opt-in defaulting off for both new and legacy configs (the key difference from the SSH default), and that applyMDMPolicy enables the flag from allowRemoteJobs and applies debugBundleUploadURL, rejecting a non-https override.
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/netbirdio/netbird/client/iface"
|
"github.com/netbirdio/netbird/client/iface"
|
||||||
"github.com/netbirdio/netbird/client/internal/routemanager/dynamic"
|
"github.com/netbirdio/netbird/client/internal/routemanager/dynamic"
|
||||||
|
"github.com/netbirdio/netbird/client/mdm"
|
||||||
"github.com/netbirdio/netbird/util"
|
"github.com/netbirdio/netbird/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -271,6 +272,60 @@ func TestUpdateConfigServerSSHAllowedNotSet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUpdateConfigRemoteJobsAllowed(t *testing.T) {
|
||||||
|
// Unlike SSH (which defaults on for legacy configs), remote jobs are an
|
||||||
|
// explicit opt-in: a pre-existing config with no value materializes to off.
|
||||||
|
t.Run("legacy config defaults off", func(t *testing.T) {
|
||||||
|
configPath := filepath.Join(t.TempDir(), "config.json")
|
||||||
|
require.NoError(t, os.WriteFile(configPath, []byte("{}"), 0600))
|
||||||
|
|
||||||
|
config, err := UpdateConfig(ConfigInput{ConfigPath: configPath})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, config.RemoteJobsAllowed, "RemoteJobsAllowed should be materialized")
|
||||||
|
assert.False(t, *config.RemoteJobsAllowed, "remote jobs must default off")
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, tt := range []struct {
|
||||||
|
name string
|
||||||
|
input *bool
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{"enable", util.True(), true},
|
||||||
|
{"disable", util.False(), false},
|
||||||
|
} {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
configPath := filepath.Join(t.TempDir(), "config.json")
|
||||||
|
require.NoError(t, os.WriteFile(configPath, []byte("{}"), 0600))
|
||||||
|
|
||||||
|
config, err := UpdateConfig(ConfigInput{ConfigPath: configPath, RemoteJobsAllowed: tt.input})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, config.RemoteJobsAllowed)
|
||||||
|
assert.Equal(t, tt.want, *config.RemoteJobsAllowed)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApplyMDMPolicyRemoteJobs(t *testing.T) {
|
||||||
|
t.Run("enables remote jobs and sets the upload URL override", func(t *testing.T) {
|
||||||
|
cfg := &Config{}
|
||||||
|
cfg.applyMDMPolicy(mdm.NewPolicy(map[string]any{
|
||||||
|
mdm.KeyRemoteJobsAllowed: true,
|
||||||
|
mdm.KeyBundleUploadURL: "https://upload.example.com",
|
||||||
|
}))
|
||||||
|
require.NotNil(t, cfg.RemoteJobsAllowed)
|
||||||
|
assert.True(t, *cfg.RemoteJobsAllowed, "MDM allowRemoteJobs must enable the flag")
|
||||||
|
assert.Equal(t, "https://upload.example.com", cfg.DebugBundleUploadURL, "MDM upload URL override must be applied")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("a non-https upload URL is rejected", func(t *testing.T) {
|
||||||
|
cfg := &Config{}
|
||||||
|
cfg.applyMDMPolicy(mdm.NewPolicy(map[string]any{
|
||||||
|
mdm.KeyBundleUploadURL: "http://insecure.example.com",
|
||||||
|
}))
|
||||||
|
assert.Empty(t, cfg.DebugBundleUploadURL, "a non-https upload URL must be skipped")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestUpdateOldManagementURL(t *testing.T) {
|
func TestUpdateOldManagementURL(t *testing.T) {
|
||||||
origProber := newMgmProber
|
origProber := newMgmProber
|
||||||
newMgmProber = func(_ context.Context, _ string, _ wgtypes.Key, _ bool) (mgmProber, error) {
|
newMgmProber = func(_ context.Context, _ string, _ wgtypes.Key, _ bool) (mgmProber, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user