Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
separates test for config file with no kubeuadit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-santos-code committed Jul 25, 2022
1 parent 1687df9 commit 6f633ec
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions internal/sarif/sarif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestCreate(t *testing.T) {
func TestCreateWithResults(t *testing.T) {
capabilitiesAuditable := capabilities.New(capabilities.Config{})
apparmorAuditable := apparmor.New()
imageAuditable := image.New(image.Config{Image: "scratch:1.5"})
Expand Down Expand Up @@ -62,14 +62,6 @@ func TestCreate(t *testing.T) {
"Resource limits not set.",
"https://github.com/Shopify/kubeaudit/blob/main/docs/auditors/limits.md",
},
{
"apparmor-valid.yaml",
[]kubeaudit.Auditable{apparmorAuditable},
"",
"",
"",
"",
},
}

for _, tc := range cases {
Expand All @@ -89,12 +81,6 @@ func TestCreate(t *testing.T) {
assert.Equal(t, "https://github.com/Shopify/kubeaudit",
*sarifReport.Runs[0].Tool.Driver.InformationURI)

// verify that we only add rules to the report
// if vulnerabilities are found
if len(kubeAuditReport.Results()) == 0 {
break
}

// verify that the rules have been added as per report findings
assert.Equal(t, sarifReport.Runs[0].Tool.Driver.Rules[0].ID, tc.expectedRule)

Expand Down Expand Up @@ -156,3 +142,25 @@ func TestValidate(t *testing.T) {
}
}
}

func TestCreateWithNoResults(t *testing.T) {
apparmorAuditable := apparmor.New()

fixture := filepath.Join("fixtures", "apparmor-valid.yaml")
auditor, err := kubeaudit.New([]kubeaudit.Auditable{apparmorAuditable})
require.NoError(t, err)

manifest, openErr := os.Open(fixture)
require.NoError(t, openErr)

kubeAuditReport, err := auditor.AuditManifest(fixture, manifest)
require.NoError(t, err)

sarifReport, err := Create(kubeAuditReport)
require.NoError(t, err)

require.NotEmpty(t, *sarifReport.Runs[0])

// verify that the rules are only added as per report findings
assert.Len(t, sarifReport.Runs[0].Tool.Driver.Rules, 0)
}

0 comments on commit 6f633ec

Please sign in to comment.