prevent panic when orbit is run with updates disabled (#12654)

for #11980
This commit is contained in:
Roberto Dip 2023-07-06 14:43:10 -03:00 committed by GitHub
parent c14752e7ce
commit 100b211ba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 0 deletions

View 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.

View file

@ -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

View file

@ -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)

View file

@ -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
}

View 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)
}