fix issues when MDM info is empty during migration (#13320)

for #13319
This commit is contained in:
Roberto Dip
2023-08-14 19:21:06 -03:00
committed by GitHub
parent 34bacf5312
commit 998e1dfb6b
7 changed files with 11 additions and 113 deletions
+6 -7
View File
@@ -12,7 +12,7 @@ import (
type runCmdFunc func() error
type checkEnrollmentFunc func(url string) (bool, error)
type checkEnrollmentFunc func() (bool, string, error)
type checkAssignedEnrollmentProfileFunc func(url string) error
@@ -71,20 +71,19 @@ func (h *renewEnrollmentProfileConfigFetcher) GetConfig() (*fleet.OrbitConfig, e
// See https://github.com/fleetdm/fleet/pull/9409#discussion_r1084382455
if time.Since(h.lastRun) > h.Frequency {
// we perform this check locally on the client too to avoid showing the
// dialog if the client has already migrated but the Fleet server
// doesn't know about this state yet.
// dialog if the client is enrolled to an MDM server.
enrollFn := h.checkEnrollmentFn
if enrollFn == nil {
enrollFn = profiles.IsEnrolledIntoMatchingURL
enrollFn = profiles.IsEnrolledInMDM
}
enrolled, err := enrollFn(h.fleetURL)
enrolled, mdmServerURL, err := enrollFn()
if err != nil {
log.Error().Err(err).Msg("fetching enrollment status")
return cfg, nil
}
if enrolled {
log.Info().Msg("a request to renew the enrollment profile was processed but not executed because the host is already enrolled into Fleet.")
h.lastRun = time.Now()
log.Info().Msgf("a request to renew the enrollment profile was processed but not executed because the host is enrolled into an MDM server with URL: %s", mdmServerURL)
h.lastRun = time.Now().Add(-h.Frequency).Add(2 * time.Minute)
return cfg, nil
}
+4 -4
View File
@@ -50,8 +50,8 @@ func TestRenewEnrollmentProfile(t *testing.T) {
cmdGotCalled = true
return c.cmdErr
},
checkEnrollmentFn: func(url string) (bool, error) {
return false, nil
checkEnrollmentFn: func() (bool, string, error) {
return false, "", nil
},
checkAssignedEnrollmentProfileFn: func(url string) error {
depAssignedCheckGotCalled = true
@@ -92,9 +92,9 @@ func TestRenewEnrollmentProfilePrevented(t *testing.T) {
cmdCallCount++ // no need for sync, single-threaded call of this func is guaranteed by the fetcher's mutex
return nil
},
checkEnrollmentFn: func(url string) (bool, error) {
checkEnrollmentFn: func() (bool, string, error) {
<-chProceed // will be unblocked only when allowed
return isEnrolled, nil
return isEnrolled, "", nil
},
checkAssignedEnrollmentProfileFn: func(url string) error {
<-chProceed // will be unblocked only when allowed