Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): Bump trivy-checks #7417

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions pkg/iac/scanners/dockerfile/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/aquasecurity/trivy/internal/testutil"
"github.com/aquasecurity/trivy/pkg/iac/framework"
"github.com/aquasecurity/trivy/pkg/iac/rego"
"github.com/aquasecurity/trivy/pkg/iac/rego/schemas"
"github.com/aquasecurity/trivy/pkg/iac/scan"
"github.com/aquasecurity/trivy/pkg/iac/scanners/options"
Expand Down Expand Up @@ -553,27 +552,23 @@ res := true

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
regoMap := make(map[string]string)
libs, err := rego.LoadEmbeddedLibraries()
require.NoError(t, err)
for name, library := range libs {
regoMap["/rules/"+name] = library.String()
}
Comment on lines -557 to -561
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPA has a bug with converting a module to a string and back. https://github.com/open-policy-agent/opa

Especially there is no point in loading the libraries yourself, as Rego scanner can do it.

regoMap["/code/Dockerfile"] = `FROM golang:1.7.3 as dep
fsysMap := make(map[string]string)
fsysMap["/code/Dockerfile"] = `FROM golang:1.7.3 as dep
COPY --from=dep /binary /`
regoMap["/rules/rule.rego"] = tc.inputRegoPolicy
regoMap["/rules/schemas/myfancydockerfile.json"] = string(schemas.Dockerfile) // just use the same for testing
fs := testutil.CreateFS(t, regoMap)
fsysMap["/rules/rule.rego"] = tc.inputRegoPolicy
fsysMap["/rules/schemas/myfancydockerfile.json"] = string(schemas.Dockerfile) // just use the same for testing
fsys := testutil.CreateFS(t, fsysMap)

var traceBuf bytes.Buffer

scanner := NewScanner(
options.ScannerWithPolicyDirs("rules"),
options.ScannerWithEmbeddedLibraries(true),
options.ScannerWithTrace(&traceBuf),
options.ScannerWithRegoErrorLimits(0),
)

results, err := scanner.ScanFS(context.TODO(), fs, "code")
results, err := scanner.ScanFS(context.TODO(), fsys, "code")
if tc.expectedError != "" && err != nil {
require.Equal(t, tc.expectedError, err.Error(), tc.name)
} else {
Expand Down