From 7dd70dcf3e3b0b49af7f375d1ca20777ef6e28e2 Mon Sep 17 00:00:00 2001 From: Aqua Security automated builds <54269356+aqua-bot@users.noreply.github.com> Date: Mon, 18 Nov 2024 02:30:47 -0700 Subject: [PATCH] fix(redhat): don't return error if `root/buildinfo/content_manifests/` contains files that are not `contentSets` files [backport: release/v0.57] (#7939) Co-authored-by: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com> Co-authored-by: DmitriyLewen --- pkg/fanal/analyzer/buildinfo/content_manifest.go | 4 ++++ pkg/fanal/analyzer/buildinfo/content_manifest_test.go | 5 +++++ .../buildinfo/testdata/content_manifests/sbom-purl.json | 9 +++++++++ 3 files changed, 18 insertions(+) create mode 100644 pkg/fanal/analyzer/buildinfo/testdata/content_manifests/sbom-purl.json diff --git a/pkg/fanal/analyzer/buildinfo/content_manifest.go b/pkg/fanal/analyzer/buildinfo/content_manifest.go index 1c99a9783ebe..7d5372dc7266 100644 --- a/pkg/fanal/analyzer/buildinfo/content_manifest.go +++ b/pkg/fanal/analyzer/buildinfo/content_manifest.go @@ -31,6 +31,10 @@ func (a contentManifestAnalyzer) Analyze(_ context.Context, target analyzer.Anal return nil, xerrors.Errorf("invalid content manifest: %w", err) } + if len(manifest.ContentSets) == 0 { + return nil, nil + } + return &analyzer.AnalysisResult{ BuildInfo: &types.BuildInfo{ ContentSets: manifest.ContentSets, diff --git a/pkg/fanal/analyzer/buildinfo/content_manifest_test.go b/pkg/fanal/analyzer/buildinfo/content_manifest_test.go index c7d8b880f5a1..61ad8ebde1cb 100644 --- a/pkg/fanal/analyzer/buildinfo/content_manifest_test.go +++ b/pkg/fanal/analyzer/buildinfo/content_manifest_test.go @@ -31,6 +31,11 @@ func Test_contentManifestAnalyzer_Analyze(t *testing.T) { }, }, }, + { + name: "happy path for non-contentSets file", + input: "testdata/content_manifests/sbom-purl.json", + want: nil, + }, { name: "broken json", input: "testdata/content_manifests/broken.json", diff --git a/pkg/fanal/analyzer/buildinfo/testdata/content_manifests/sbom-purl.json b/pkg/fanal/analyzer/buildinfo/testdata/content_manifests/sbom-purl.json new file mode 100644 index 000000000000..8e73ade1d8f3 --- /dev/null +++ b/pkg/fanal/analyzer/buildinfo/testdata/content_manifests/sbom-purl.json @@ -0,0 +1,9 @@ +{ + "image_contents": { + "dependencies": [ + { + "purl": "pkg:rpm/redhat/zstd@1.5.1-2.el9?arch=src&checksum=sha256:f1ddea14d19746b867e69b48d128dd9c2d3e8cc021a5ea7b0674b48356ad3341&repository_id=rhel-9-base-source" + } + ] + } +} \ No newline at end of file