Skip to content

Commit

Permalink
Fix GitOps script policy test
Browse files Browse the repository at this point in the history
  • Loading branch information
iansltx committed Oct 2, 2024
1 parent 892baa6 commit f66ea84
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
10 changes: 9 additions & 1 deletion pkg/spec/gitops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func TestValidGitOpsYaml(t *testing.T) {
// Check policies
expectedPoliciesCount := 5
if test.isTeam {
expectedPoliciesCount = 6
expectedPoliciesCount = 8
}
require.Len(t, gitops.Policies, expectedPoliciesCount)
assert.Equal(t, "😊 Failing policy", gitops.Policies[0].Name)
Expand All @@ -255,6 +255,14 @@ func TestValidGitOpsYaml(t *testing.T) {
assert.Equal(t, "Microsoft Teams on macOS installed and up to date", gitops.Policies[5].Name)
assert.NotNil(t, gitops.Policies[5].InstallSoftware)
assert.Equal(t, "./microsoft-teams.pkg.software.yml", gitops.Policies[5].InstallSoftware.PackagePath)

assert.Equal(t, "Script run policy", gitops.Policies[6].Name)
assert.NotNil(t, gitops.Policies[6].RunScript)
assert.Equal(t, "./lib/collect-fleetd-logs.sh", gitops.Policies[6].RunScript.Path)

assert.Equal(t, "🔥 Failing policy with script", gitops.Policies[7].Name)
assert.NotNil(t, gitops.Policies[7].RunScript)
assert.Equal(t, "./lib/collect-fleetd-logs.sh", gitops.Policies[7].RunScript.Path)
}
},
)
Expand Down
1 change: 1 addition & 0 deletions pkg/spec/testdata/lib/collect-fleetd-logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# collect fleetd logs
7 changes: 7 additions & 0 deletions pkg/spec/testdata/script-policy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: 🔥 Failing policy with script
platform: $LINUX_OS
description: This policy should always fail.
resolution: There is no resolution for this policy.
query: SELECT 1 FROM osquery_info WHERE start_time < 0;
run_script:
path: ./lib/collect-fleetd-logs.sh
3 changes: 2 additions & 1 deletion pkg/spec/testdata/team_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ policies:
description: This should run a script on failure
query: SELECT * from osquery_info;
run_script:
- path: ./lib/collect-fleetd-logs.sh
path: ./lib/collect-fleetd-logs.sh
- path: ./script-policy.yml
software:
packages:
- path: ./microsoft-teams.pkg.software.yml
Expand Down
13 changes: 13 additions & 0 deletions pkg/spec/testdata/team_config_no_paths.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ policies:
query: SELECT 1 FROM apps WHERE name = 'Microsoft Teams.app' AND version_compare(bundle_short_version, '24193.1707.3028.4282') >= 0;
install_software:
package_path: ./microsoft-teams.pkg.software.yml
- name: Script run policy
platform: linux
description: This should run a script on failure
query: SELECT * from osquery_info;
run_script:
path: ./lib/collect-fleetd-logs.sh
- name: 🔥 Failing policy with script
platform: linux
description: This policy should always fail.
resolution: There is no resolution for this policy.
query: SELECT 1 FROM osquery_info WHERE start_time < 0;
run_script:
path: ./lib/collect-fleetd-logs.sh
software:
packages:
- path: ./microsoft-teams.pkg.software.yml
Expand Down
4 changes: 1 addition & 3 deletions pkg/spec/testdata/top.policies2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
platform: $LINUX_OS
description: This policy should always fail.
resolution: There is no resolution for this policy.
query: SELECT 1 FROM osquery_info WHERE start_time < 0;
run_script:
- path: ./lib/collect-fleetd-logs.sh
query: SELECT 1 FROM osquery_info WHERE start_time < 0;

0 comments on commit f66ea84

Please sign in to comment.