Skip to content

Commit

Permalink
fix: policy severity test correct test criteria (#1614)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Cadorette authored Apr 22, 2024
1 parent 5440c57 commit ef808de
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions integration/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package integration

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -326,12 +327,31 @@ func TestPolicyBadSeverity(t *testing.T) {

}

type PolicyDetail struct {
Severity string `json:"severity"`
PolicyID string `json:"policyId"`
}

func TestPolicySeverityCritical(t *testing.T) {
out, err, exitcode := LaceworkCLIWithTOMLConfig("policy", "list", "--severity", "critical")
assert.Contains(t, out.String(), "lacework-global-8")
assert.NotContains(t, out.String(), "high")
out, err, exitcode := LaceworkCLIWithTOMLConfig("policy", "list", "--severity", "critical", "--json")
assert.Empty(t, err.String(), "STDERR should be empty")
assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one")

var details []PolicyDetail
assert.NoError(t, json.Unmarshal(out.Bytes(), &details))

found := false
notCritical := false
for _, policy := range details {
if policy.PolicyID == "lacework-global-8" {
found = true
}
if policy.Severity != "critical" {
notCritical = true
}
}
assert.True(t, found, "lacework-global-8 should have been found in policy list of severity critical")
assert.False(t, notCritical, "only policies with severity critical should have been found")
}

func TestPolicyShowHelp(t *testing.T) {
Expand Down

0 comments on commit ef808de

Please sign in to comment.