mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-20 20:39:08 +02:00
On the first interactive run the GUI persists the autostartInitialized marker before any enable attempt, then enables autostart only when the platform supports it, MDM policy does not disable it, the process was not relaunched by an installer/updater (--post-update), and the installer's fresh-install breadcrumb is present. Upgrading users have no breadcrumb, so an update can never write login items, and a user's disable in Settings is never overridden.
133 lines
3.5 KiB
Go
133 lines
3.5 KiB
Go
//go:build !android && !ios && !freebsd && !js
|
|
|
|
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/netbirdio/netbird/client/mdm"
|
|
)
|
|
|
|
func TestShouldEnableAutostartDefault(t *testing.T) {
|
|
allPass := autostartDefaultState{
|
|
supported: true,
|
|
mdmDisabled: false,
|
|
postUpdateRelaunch: false,
|
|
breadcrumbPresent: true,
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
mutate func(*autostartDefaultState)
|
|
wantEnable bool
|
|
wantReason string
|
|
}{
|
|
{
|
|
name: "fresh install with all guards passing enables",
|
|
mutate: func(*autostartDefaultState) {},
|
|
wantEnable: true,
|
|
},
|
|
{
|
|
name: "unsupported platform skips",
|
|
mutate: func(s *autostartDefaultState) { s.supported = false },
|
|
wantReason: "autostart not supported on this platform",
|
|
},
|
|
{
|
|
name: "MDM disable skips",
|
|
mutate: func(s *autostartDefaultState) { s.mdmDisabled = true },
|
|
wantReason: "autostart disabled by MDM policy",
|
|
},
|
|
{
|
|
name: "post-update relaunch skips",
|
|
mutate: func(s *autostartDefaultState) { s.postUpdateRelaunch = true },
|
|
wantReason: "post-update relaunch",
|
|
},
|
|
{
|
|
name: "missing breadcrumb (upgrade or portable build) skips",
|
|
mutate: func(s *autostartDefaultState) { s.breadcrumbPresent = false },
|
|
wantReason: "no fresh-install breadcrumb",
|
|
},
|
|
{
|
|
name: "unsupported wins over every other guard",
|
|
mutate: func(s *autostartDefaultState) {
|
|
s.supported = false
|
|
s.mdmDisabled = true
|
|
s.postUpdateRelaunch = true
|
|
s.breadcrumbPresent = false
|
|
},
|
|
wantReason: "autostart not supported on this platform",
|
|
},
|
|
{
|
|
name: "breadcrumb present but relaunched after update skips",
|
|
mutate: func(s *autostartDefaultState) {
|
|
s.postUpdateRelaunch = true
|
|
s.breadcrumbPresent = true
|
|
},
|
|
wantReason: "post-update relaunch",
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
state := allPass
|
|
tc.mutate(&state)
|
|
enable, reason := shouldEnableAutostartDefault(state)
|
|
assert.Equal(t, tc.wantEnable, enable, "enable decision should match for state %+v", state)
|
|
assert.Equal(t, tc.wantReason, reason, "skip reason should identify the failing guard")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAutostartDisabledByMDM(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
values map[string]any
|
|
want bool
|
|
}{
|
|
{
|
|
name: "empty policy does not disable",
|
|
values: nil,
|
|
want: false,
|
|
},
|
|
{
|
|
name: "unrelated managed keys do not disable",
|
|
values: map[string]any{mdm.KeyDisableAutoConnect: true},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "disableAutostart true disables",
|
|
values: map[string]any{mdm.KeyDisableAutostart: true},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "disableAutostart registry DWORD 1 disables",
|
|
values: map[string]any{mdm.KeyDisableAutostart: int64(1)},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "disableAutostart string true disables",
|
|
values: map[string]any{mdm.KeyDisableAutostart: "true"},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "disableAutostart explicit false allows",
|
|
values: map[string]any{mdm.KeyDisableAutostart: false},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "unparseable managed value is treated as disabled",
|
|
values: map[string]any{mdm.KeyDisableAutostart: "not-a-bool"},
|
|
want: true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := autostartDisabledByMDM(mdm.NewPolicy(tc.values))
|
|
assert.Equal(t, tc.want, got, "MDM disable decision should match for values %v", tc.values)
|
|
})
|
|
}
|
|
}
|