mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
prevent panic when orbit is run with updates disabled (#12654)
for #11980
This commit is contained in:
parent
c14752e7ce
commit
100b211ba5
5 changed files with 57 additions and 0 deletions
1
orbit/changes/11980-updates-panic
Normal file
1
orbit/changes/11980-updates-panic
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Fixed a crash that happened when updates where disabled and certain conditions (Nudge configuration set or host elegible for MDM migration) were met.
|
||||
|
|
@ -71,6 +71,11 @@ func (n *NudgeConfigFetcher) GetConfig() (*fleet.OrbitConfig, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if n.opt.UpdateRunner == nil {
|
||||
log.Debug().Msg("NudgeConfigFetcher received nil UpdateRunner, this probably indicates that updates are turned off. Skipping any actions related to Nudge")
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
if cfg.NudgeConfig == nil {
|
||||
log.Debug().Msg("empty nudge config, removing nudge as target")
|
||||
// TODO(roberto): by early returning and removing the target from the
|
||||
|
|
|
|||
|
|
@ -25,6 +25,29 @@ type nudgeTestSuite struct {
|
|||
withTUF
|
||||
}
|
||||
|
||||
func (s *nudgeTestSuite) TestUpdatesDisabled() {
|
||||
t := s.T()
|
||||
var err error
|
||||
cfg := &fleet.OrbitConfig{}
|
||||
cfg.NudgeConfig, err = fleet.NewNudgeConfig(fleet.MacOSUpdates{MinimumVersion: optjson.SetString("11"), Deadline: optjson.SetString("2022-01-04")})
|
||||
require.NoError(t, err)
|
||||
runNudgeFn := func(execPath, configPath string) error {
|
||||
return nil
|
||||
}
|
||||
var f OrbitConfigFetcher = &dummyConfigFetcher{cfg: cfg}
|
||||
f = ApplyNudgeConfigFetcherMiddleware(f, NudgeConfigFetcherOptions{
|
||||
UpdateRunner: nil,
|
||||
RootDir: t.TempDir(),
|
||||
Interval: time.Minute,
|
||||
runNudgeFn: runNudgeFn,
|
||||
})
|
||||
|
||||
// we used to get a panic if updates were disabled (see #11980)
|
||||
gotCfg, err := f.GetConfig()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, cfg, gotCfg)
|
||||
}
|
||||
|
||||
func (s *nudgeTestSuite) TestNudgeConfigFetcherAddNudge() {
|
||||
t := s.T()
|
||||
tmpDir := t.TempDir()
|
||||
|
|
@ -69,6 +92,8 @@ func (s *nudgeTestSuite) TestNudgeConfigFetcherAddNudge() {
|
|||
// add nuge to the remote
|
||||
s.addRemoteTarget(nudgePath)
|
||||
|
||||
// nothing happens if a nil runner is provided
|
||||
|
||||
// nudge is added to targets when nudge config is present
|
||||
gotCfg, err = f.GetConfig()
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@ func (s *SwiftDialogDownloader) GetConfig() (*fleet.OrbitConfig, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if s.UpdateRunner == nil {
|
||||
log.Debug().Msg("SwiftDialogDownloader received nil UpdateRunner, this probably indicates that updates are turned off. Skipping any actions related to swiftDialog")
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
if !cfg.Notifications.NeedsMDMMigration && !cfg.Notifications.RenewEnrollmentProfile {
|
||||
return cfg, nil
|
||||
}
|
||||
|
|
|
|||
21
orbit/pkg/update/swift_dialog_test.go
Normal file
21
orbit/pkg/update/swift_dialog_test.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package update
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/fleetdm/fleet/v4/server/fleet"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSwiftDialogUpdatesDisabled(t *testing.T) {
|
||||
cfg := &fleet.OrbitConfig{}
|
||||
cfg.Notifications.NeedsMDMMigration = true
|
||||
cfg.Notifications.RenewEnrollmentProfile = true
|
||||
var f OrbitConfigFetcher = &dummyConfigFetcher{cfg: cfg}
|
||||
f = ApplySwiftDialogDownloaderMiddleware(f, nil)
|
||||
|
||||
// we used to get a panic if updates were disabled (see #11980)
|
||||
gotCfg, err := f.GetConfig()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, cfg, gotCfg)
|
||||
}
|
||||
Loading…
Reference in a new issue