fix: Detect file starting with comment in mdm.go as well (#27673)

Addresses
https://github.com/fleetdm/fleet/issues/26443#issuecomment-2749360869
after https://github.com/fleetdm/fleet/pull/27176 was merged. Reading
XML as a string in this way feels wrong, but I don't want to avoid a
refactor, so I'm checking for a "comment" string in this PR.

I tested by building fleetctl locally and running:

```sh
$ make fleetctl; ./build/fleetctl gitops -f it-and-security/teams/test.yml --dry-run
...
Client Version:   tf-mod-addon-monitoring-v1.5.1-1091-g8eb9111c6-dirty
Server Version:  0.0.0-SNAPSHOT-85f4f65
[+] applying MDM profiles for team TEST
Error: applying custom settings for team "TEST": POST /api/latest/fleet/mdm/profiles/batch received status 422 Validation Failed: disable-onedrive is not a valid macOS or Windows configuration profile. macOS profiles must be valid .mobileconfig or .json files. Windows configuration profiles can only have <Replace> or <Add> top level elements.
```

I'm not sure if the error above
([code](8eb9111c67/server/service/mdm.go (L2160)))
is caused by my test environment not yet having the updated server code.
The `--dry-run` passed in my test, as seen by the `[+] applying MDM
profiles for team TEST` line. I can't get any test code to be reflected
in the server response, so my hunch is that the issue should be fixed
after this PR.

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files)
for more information.
- I did this in https://github.com/fleetdm/fleet/pull/27176, same change
message.
- [x] Added/updated automated tests
- [x] Manual QA for all new/changed functionality
This commit is contained in:
Dan Tsekhanskiy 2025-03-31 20:16:13 -04:00 committed by GitHub
parent 00e288afa8
commit 521ecfffa7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View file

@ -65,7 +65,7 @@ func GetRawProfilePlatform(profile []byte) string {
return "darwin"
}
if prefixMatches(trimmedProfile, "<replace") || prefixMatches(trimmedProfile, "<add") {
if prefixMatches(trimmedProfile, "<replace") || prefixMatches(trimmedProfile, "<add") || prefixMatches(trimmedProfile, "<!--") {
return "windows"
}

View file

@ -154,6 +154,11 @@ func TestGetRawProfilePlatform(t *testing.T) {
input: []byte("<Add this=\"that\">"),
expected: "windows",
},
{
name: "Windows xml with comment",
input: []byte("<!-- this is a comment -->"),
expected: "windows",
},
{
name: "Whitespace before prefix",
input: []byte(" <?xml version=\"1.0\"?>"),