fleet/pkg/patch_policy/patch_policy_test.go
Ian Littman 65030e905f
Fix mis-assigned FMA bundle identifiers, switch to fuzzy matching on queries where Windows apps include version number in the name (incl. special fixes for Firefox ESR) (#42628)
Resolves #42714.

Zed + Opus 4.6; initial prompts (see additional ones in follow-on
commits):

---

Audit our existing Fleet Maintained App catalog. Look for:

1. Software that has the wrong identifiers associated (e.g. Abstract),
e.g. in `exists` queries
2. Software that has the version number in the name that leaks into the
`exists` query, e.g. 7-zip or 010 Editor or Airtame. These should be
fuzzy-matched.

For each affected app, revise input manifests to fix the issues. For
(1), revise apps.json if needed as well. Don't modify apps.json for (2)
cases.

---

Are there any discrepancies between bundle identifiers in input
manifests for Darwin apps and apps.json? If so, fix them.

---

Outputs will get overwritten by the ingester if neither the ingester nor
the input JSON files are changed. Make whatever changes need to be made
so that these edits survive an FMA ingestion cycle.

---

Revise `fuzzy` to allow specifying a custom value e.g. `Mozilal Firefox
% (ESR)` in addition to the existing true/false, then use that new
functionality to build unique queries for Firefox ESR.

---

Commit these changes, across multiple commits (there will be cases where
a changes to a single file will be spread across multiple commits, most
notably apps.json). Split commits out as follows:

1. All darwin-related changes
2. Windows switches to fuzzy matching + associated unique_identifier
changes
3. Revised handling for Firefox ESR

Prefix commit messages with "🤖 ".

---

The ingester and test changes should've gone in commit 3. Move them
there from commit 2.

---



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Updated application identifiers for Abstract, Amazon Chime, Beyond
Compare, and Teleport Suite to use correct bundle and package
identifiers.
* Enhanced Windows and macOS installation detection queries to match
multiple application versions using pattern matching instead of exact
version strings.

* **New Features**
* Added support for configurable fuzzy matching patterns to improve
application name matching flexibility.

* **Tests**
* Added tests validating fuzzy matching configuration unmarshaling and
behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-10 14:13:59 -05:00

60 lines
2.1 KiB
Go

package patch_policy_test
import (
"testing"
"github.com/fleetdm/fleet/v4/pkg/patch_policy"
"github.com/stretchr/testify/require"
)
func TestGenerateQueryForManifest(t *testing.T) {
tests := []struct {
name string
want string
p patch_policy.PolicyData
}{
{
name: "darwin from exists query",
p: patch_policy.PolicyData{
Platform: "darwin",
Version: "1.0",
ExistsQuery: "SELECT 1 FROM apps WHERE bundle_identifier = 'com.foo';",
},
want: "SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM apps WHERE bundle_identifier = 'com.foo' AND version_compare(bundle_short_version, '1.0') < 0);",
},
{
name: "windows from exists query",
p: patch_policy.PolicyData{
Platform: "windows",
Version: "1.0",
ExistsQuery: "SELECT 1 FROM programs WHERE name = 'Foo x64' AND publisher = 'Bar, Inc.';",
},
want: "SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM programs WHERE name = 'Foo x64' AND publisher = 'Bar, Inc.' AND version_compare(version, '1.0') < 0);",
},
{
name: "windows from exists query with LIKE percent wildcard",
p: patch_policy.PolicyData{
Platform: "windows",
Version: "12.5.6",
ExistsQuery: "SELECT 1 FROM programs WHERE name LIKE 'Postman x64 %' AND publisher = 'Postman';",
},
want: "SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM programs WHERE name LIKE 'Postman x64 %' AND publisher = 'Postman' AND version_compare(version, '12.5.6') < 0);",
},
{
name: "windows from exists query with multiple LIKE percent wildcards",
p: patch_policy.PolicyData{
Platform: "windows",
Version: "139.0.0",
ExistsQuery: "SELECT 1 FROM programs WHERE name LIKE 'Mozilla Firefox % ESR %' AND publisher = 'Mozilla';",
},
want: "SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM programs WHERE name LIKE 'Mozilla Firefox % ESR %' AND publisher = 'Mozilla' AND version_compare(version, '139.0.0') < 0);",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
query, err := patch_policy.GenerateQueryForManifest(tt.p)
require.NoError(t, err)
require.Equal(t, tt.want, query)
})
}
}