diff --git a/server/datastore/mysql/apple_mdm.go b/server/datastore/mysql/apple_mdm.go index 1bb808e34d..d1fcb08456 100644 --- a/server/datastore/mysql/apple_mdm.go +++ b/server/datastore/mysql/apple_mdm.go @@ -141,7 +141,7 @@ func (ds *Datastore) DeleteMDMAppleConfigProfile(ctx context.Context, profileID } func (ds *Datastore) GetHostMDMProfiles(ctx context.Context, hostUUID string) ([]fleet.HostMDMAppleProfile, error) { - stmt := ` + stmt := fmt.Sprintf(` SELECT hmap.profile_id, name, @@ -154,7 +154,10 @@ FROM JOIN mdm_apple_configuration_profiles hmacp ON hmap.profile_id = hmacp.profile_id WHERE - host_uuid = ?` + host_uuid = ? AND NOT (operation_type = '%s' AND status = '%s')`, + fleet.MDMAppleOperationTypeRemove, + fleet.MDMAppleDeliveryApplied, + ) var profiles []fleet.HostMDMAppleProfile if err := sqlx.SelectContext(ctx, ds.reader, &profiles, stmt, hostUUID); err != nil { diff --git a/server/service/integration_mdm_test.go b/server/service/integration_mdm_test.go index 036aab7489..139a386f0e 100644 --- a/server/service/integration_mdm_test.go +++ b/server/service/integration_mdm_test.go @@ -422,6 +422,8 @@ func (s *integrationMDMTestSuite) TestProfileManagement() { var res getHostResponse s.DoJSON("GET", fmt.Sprintf("/api/v1/fleet/hosts/%d", host.ID), getHostRequest{}, http.StatusOK, &res) require.NotEmpty(t, res.Host.MDM.Profiles) + resProfiles := *res.Host.MDM.Profiles + require.Len(t, resProfiles, len(teamProfiles)) } func (s *integrationMDMTestSuite) TestDEPProfileAssignment() {