Skip to content

Commit 729c324

Browse files
Avoid panics on VPP install command errors when command not initiated by Fleet VPP install -> 4.81.0 (#40395)
Pointing work from #40386 at 4.81.0. Resolves #40388 on 4.81.x (fix is implemented slightly differently in 4.82+). Co-authored-by: Jordan Montgomery <elijah.jordan.montgomery@gmail.com>
1 parent ac06880 commit 729c324

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

server/service/apple_mdm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3787,7 +3787,7 @@ func (svc *MDMAppleCheckinAndCommandService) CommandAndReportResults(r *mdm.Requ
37873787
if err != nil {
37883788
return nil, ctxerr.Wrap(r.Context, err, "fetching host vpp install by command uuid")
37893789
}
3790-
if vppInstall.RetryCount < 3 {
3790+
if vppInstall != nil && vppInstall.RetryCount < 3 {
37913791
// Requeue the app for installation
37923792
if err := svc.ds.RetryVPPInstall(r.Context, vppInstall); err != nil {
37933793
return nil, ctxerr.Wrap(r.Context, err, "retrying VPP install for host")

server/service/apple_mdm_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6531,3 +6531,38 @@ func TestToValidSemVer(t *testing.T) {
65316531
}
65326532
}
65336533
}
6534+
6535+
// Verify that CommandAndReportResults does not crash on a non-VPP InstallApplication command result
6536+
func TestMDMCommandAndReportResultsNonVPPInstallApplication(t *testing.T) {
6537+
ctx := context.Background()
6538+
hostUUID := "ABC-DEF-GHI"
6539+
commandUUID := "UUID-1234"
6540+
6541+
ds := new(mock.Store)
6542+
svc := MDMAppleCheckinAndCommandService{ds: ds, logger: kitlog.NewNopLogger()}
6543+
6544+
ds.GetHostVPPInstallByCommandUUIDFunc = func(ctx context.Context, commandUUID string) (*fleet.HostVPPSoftwareInstallLite, error) {
6545+
return nil, nil
6546+
}
6547+
ds.GetMDMAppleCommandRequestTypeFunc = func(ctx context.Context, targetCmd string) (string, error) {
6548+
require.Equal(t, commandUUID, targetCmd)
6549+
return "InstallApplication", nil
6550+
}
6551+
ds.MaybeUpdateSetupExperienceVPPStatusFunc = func(ctx context.Context, hostUUID string, commandUUID string, status fleet.SetupExperienceStatusResultStatus) (bool, error) {
6552+
return false, nil
6553+
}
6554+
ds.GetPastActivityDataForVPPAppInstallFunc = func(ctx context.Context, commandResults *mdm.CommandResults) (*fleet.User, *fleet.ActivityInstalledAppStoreApp, error) {
6555+
return nil, nil, newNotFoundError()
6556+
}
6557+
_, err := svc.CommandAndReportResults(&mdm.Request{Context: ctx},
6558+
&mdm.CommandResults{
6559+
Enrollment: mdm.Enrollment{UDID: hostUUID},
6560+
CommandUUID: commandUUID,
6561+
Status: fleet.MDMAppleStatusError,
6562+
ErrorChain: []mdm.ErrorChain{
6563+
{ErrorCode: apple_mdm.VPPLicenseNotFound, ErrorDomain: "testDomain", USEnglishDescription: "testMessage"},
6564+
},
6565+
},
6566+
)
6567+
require.NoError(t, err)
6568+
}

0 commit comments

Comments
 (0)