mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-23 15:37:50 -08:00
BREAKING: support exclude kinds/namespaces and include kinds/namespaces (#6323)
Signed-off-by: chenk <hen.keinan@gmail.com>
This commit is contained in:
@@ -31,7 +31,7 @@ func TestK8s(t *testing.T) {
|
||||
"--cache-dir",
|
||||
cacheDir,
|
||||
"k8s",
|
||||
"cluster",
|
||||
"kind-kind-test",
|
||||
"--report",
|
||||
"summary",
|
||||
"-q",
|
||||
@@ -39,10 +39,6 @@ func TestK8s(t *testing.T) {
|
||||
"5m0s",
|
||||
"--format",
|
||||
"json",
|
||||
"--components",
|
||||
"workload",
|
||||
"--context",
|
||||
"kind-kind-test",
|
||||
"--output",
|
||||
outputFile,
|
||||
}
|
||||
@@ -79,12 +75,10 @@ func TestK8s(t *testing.T) {
|
||||
outputFile := filepath.Join(t.TempDir(), "output.json")
|
||||
osArgs := []string{
|
||||
"k8s",
|
||||
"cluster",
|
||||
"kind-kind-test",
|
||||
"--format",
|
||||
"cyclonedx",
|
||||
"-q",
|
||||
"--context",
|
||||
"kind-kind-test",
|
||||
"--output",
|
||||
outputFile,
|
||||
}
|
||||
@@ -111,51 +105,5 @@ func TestK8s(t *testing.T) {
|
||||
assert.True(t, lo.SomeBy(*got.Dependencies, func(r cdx.Dependency) bool {
|
||||
return len(*r.Dependencies) > 0
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
t.Run("specific resource scan", func(t *testing.T) {
|
||||
// Set up the output file
|
||||
outputFile := filepath.Join(t.TempDir(), "output.json")
|
||||
|
||||
osArgs := []string{
|
||||
"k8s",
|
||||
"-n",
|
||||
"default",
|
||||
"deployments/nginx-deployment",
|
||||
"-q",
|
||||
"--timeout",
|
||||
"5m0s",
|
||||
"--format",
|
||||
"json",
|
||||
"--components",
|
||||
"workload",
|
||||
"--context",
|
||||
"kind-kind-test",
|
||||
"--output",
|
||||
outputFile,
|
||||
}
|
||||
|
||||
// Run Trivy
|
||||
err := execute(osArgs)
|
||||
require.NoError(t, err)
|
||||
|
||||
var got report.Report
|
||||
f, err := os.Open(outputFile)
|
||||
require.NoError(t, err)
|
||||
defer f.Close()
|
||||
|
||||
err = json.NewDecoder(f).Decode(&got)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Flatten findings
|
||||
results := lo.FlatMap(got.Resources, func(resource report.Resource, _ int) []types.Result {
|
||||
return resource.Results
|
||||
})
|
||||
|
||||
// Has vulnerabilities
|
||||
assert.True(t, lo.SomeBy(results, func(r types.Result) bool {
|
||||
return len(r.Vulnerabilities) > 0
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user