-
Notifications
You must be signed in to change notification settings - Fork 567
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
Pick up CycloneDX BOM components from metadata as well #3092
Merged
kzantow
merged 7 commits into
anchore:main
from
dervoeti:fix/cyclonedx-bom-components-from-metadata
Aug 12, 2024
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7021337
feat: pick up CycloneDX BOM components from metadata as well
dervoeti 671684e
fix: change var name to camel case
dervoeti 390fc91
feat: added integration test
dervoeti a49f8ab
fix: only include .metadata.component as package if it has a certain …
dervoeti 730b877
refactor: simplified the change
dervoeti 2e460bb
fix: metadata nil check
dervoeti 8658eeb
Merge remote-tracking branch 'upstream/main' into fix/cyclonedx-bom-c…
kzantow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
cmd/syft/internal/test/integration/sbom_metadata_component_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package integration | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/anchore/syft/syft/pkg" | ||
"github.com/anchore/syft/syft/source" | ||
) | ||
|
||
func TestSbomMetadataComponent(t *testing.T) { | ||
sbom, _ := catalogFixtureImage(t, "image-sbom-metadata-component", source.SquashedScope, "+sbom-cataloger") | ||
|
||
expectedPkgs := []string{"first-subcomponent", "main-component"} | ||
foundPkgs := []string{} | ||
|
||
for sbomPkg := range sbom.Artifacts.Packages.Enumerate(pkg.JavaPkg) { | ||
foundPkgs = append(foundPkgs, sbomPkg.Name) | ||
} | ||
|
||
// check if both the package in `.metadata.component` and the one in `.components` were found | ||
if !reflect.DeepEqual(expectedPkgs, foundPkgs) { | ||
t.Errorf("expected packages %v, got %v", expectedPkgs, foundPkgs) | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
cmd/syft/internal/test/integration/test-fixtures/image-sbom-metadata-component/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM scratch | ||
COPY test.cdx.json / |
32 changes: 32 additions & 0 deletions
32
cmd/syft/internal/test/integration/test-fixtures/image-sbom-metadata-component/test.cdx.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"bomFormat" : "CycloneDX", | ||
"specVersion" : "1.5", | ||
"serialNumber" : "urn:uuid:dc807d4b-0415-35ab-ba61-49b5d39bc2d9", | ||
"version" : 1, | ||
"metadata" : { | ||
"component" : { | ||
"name" : "main-component", | ||
"version" : "1.2.3", | ||
"purl" : "pkg:maven/org.example/main-component@1.2.3", | ||
"type" : "library", | ||
"bom-ref" : "pkg:maven/org.example/main-component@1.2.3" | ||
} | ||
}, | ||
"components" : [ | ||
{ | ||
"name" : "first-subcomponent", | ||
"version" : "2.3.4", | ||
"purl" : "pkg:maven/org.example/first-subcomponent@2.3.4", | ||
"type" : "library", | ||
"bom-ref" : "pkg:maven/org.example/first-subcomponent@2.3.4" | ||
} | ||
], | ||
"dependencies" : [ | ||
{ | ||
"ref" : "pkg:maven/org.example/main-component-assembly@1.2.3", | ||
"dependsOn" : [ | ||
"pkg:maven/org.example/first-subcomponent@2.3.4" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change could be simplified to just adding this block:
... and in the
collectPackages
, we should be recursively adding sub-components, and checking for the type being one of the right types, which it looks like it's doing alreadyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I should have looked at exactly what the code was doing there before sending you down a path to implement an unnecessary thing 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, I also didn't see the logic was already present. Good thing you spotted it, I refactored it, the change is much simpler now 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may have missed suggesting a
bom.Metadata != nil
bitThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, fixed