From 5a988872a7d35062305420068903cc462b240ba4 Mon Sep 17 00:00:00 2001 From: gillespi314 <73313222+gillespi314@users.noreply.github.com> Date: Thu, 23 Feb 2023 14:33:36 -0600 Subject: [PATCH] Filter removed mdm profiles from host details (#10074) --- server/datastore/mysql/apple_mdm.go | 7 +++++-- server/service/integration_mdm_test.go | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) 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() {