mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #42492 Includes changes from running ingestions on all FMAs # Checklist for submitter If some of the following don't apply, delete the relevant line. - [ ] 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/guides/committing-changes.md#changes-files) for more information. - [ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters. - [ ] If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes ## Testing - [x] Added/updated automated tests - [ ] Where appropriate, [automated tests simulate multiple hosts and test for host isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing) (updates to one hosts's records do not affect another) - [x] QA'd all new/changed functionality manually
42 lines
1.2 KiB
Go
42 lines
1.2 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);",
|
|
},
|
|
}
|
|
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)
|
|
})
|
|
}
|
|
}
|