From f3754e26742d01304d654aba610a2cf5f061a282 Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Fri, 1 Mar 2024 18:22:30 -0500 Subject: [PATCH] fix: use correct copy in fleetctl error when applying profiles (#17318) > Related issue: #16335, fixes issue QA found here: https://github.com/fleetdm/fleet/issues/16335#issuecomment-1971560894 # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/` or `orbit/changes/`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [x] Added/updated tests - [x] Manual QA for all new/changed functionality --- changes/fix-16335-copy | 1 + server/service/integration_mdm_test.go | 8 ++++---- server/service/mdm.go | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 changes/fix-16335-copy diff --git a/changes/fix-16335-copy b/changes/fix-16335-copy new file mode 100644 index 0000000000..69e4d38ce7 --- /dev/null +++ b/changes/fix-16335-copy @@ -0,0 +1 @@ +- Updates copy in `fleetctl` error when attempting to upload malformed profiles. \ No newline at end of file diff --git a/server/service/integration_mdm_test.go b/server/service/integration_mdm_test.go index 80d875cb79..9e88c14bf9 100644 --- a/server/service/integration_mdm_test.go +++ b/server/service/integration_mdm_test.go @@ -11205,14 +11205,14 @@ func (s *integrationMDMTestSuite) TestBatchSetMDMProfiles() { {Name: "N3", Contents: []byte(``)}, }}, http.StatusUnprocessableEntity, "team_id", strconv.Itoa(int(tm.ID))) errMsg = extractServerErrorText(res.Body) - require.Contains(t, errMsg, "Only supported as a top level element") + require.Contains(t, errMsg, "Windows configuration profiles can only have or top level elements.") // invalid xml res = s.Do("POST", "/api/v1/fleet/mdm/profiles/batch", batchSetMDMProfilesRequest{Profiles: []fleet.MDMProfileBatchPayload{ {Name: "N3", Contents: []byte(`foo`)}, }}, http.StatusUnprocessableEntity, "team_id", strconv.Itoa(int(tm.ID))) errMsg = extractServerErrorText(res.Body) - require.Contains(t, errMsg, "Only supported as a top level element") + require.Contains(t, errMsg, "Windows configuration profiles can only have or top level elements.") // successfully apply windows and macOS a profiles for the team, but it's a dry run s.Do("POST", "/api/v1/fleet/mdm/profiles/batch", batchSetMDMProfilesRequest{Profiles: []fleet.MDMProfileBatchPayload{ @@ -11332,14 +11332,14 @@ func (s *integrationMDMTestSuite) TestBatchSetMDMProfilesBackwardsCompat() { "N3": []byte(``), }}, http.StatusUnprocessableEntity, "team_id", strconv.Itoa(int(tm.ID))) errMsg = extractServerErrorText(res.Body) - require.Contains(t, errMsg, "Only supported as a top level element") + require.Contains(t, errMsg, "Windows configuration profiles can only have or top level elements.") // invalid xml res = s.Do("POST", "/api/v1/fleet/mdm/profiles/batch", map[string]any{"profiles": map[string][]byte{ "N3": []byte(`foo`), }}, http.StatusUnprocessableEntity, "team_id", strconv.Itoa(int(tm.ID))) errMsg = extractServerErrorText(res.Body) - require.Contains(t, errMsg, "Only supported as a top level element") + require.Contains(t, errMsg, "Windows configuration profiles can only have or top level elements.") // successfully apply windows and macOS a profiles for the team, but it's a dry run s.Do("POST", "/api/v1/fleet/mdm/profiles/batch", map[string]any{"profiles": map[string][]byte{ diff --git a/server/service/mdm.go b/server/service/mdm.go index 3f1bf6aab0..44eead8dfc 100644 --- a/server/service/mdm.go +++ b/server/service/mdm.go @@ -1695,7 +1695,7 @@ func validateProfiles(profiles []fleet.MDMProfileBatchPayload) error { platform := mdm.GetRawProfilePlatform(profile.Contents) if platform != "darwin" && platform != "windows" { // TODO(roberto): there's ongoing feedback with Marko about improving this message, as it's too windows specific - return fleet.NewInvalidArgumentError("mdm", "Only supported as a top level element. Make sure you don’t have other top level elements.") + return fleet.NewInvalidArgumentError("mdm", "Windows configuration profiles can only have or top level elements.") } }