-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
fix(sbom): fix panic when scanning SBOM file without root component into SBOM format #7051
Changes from 3 commits
cbeabe1
afb0428
90f88ad
c4c413a
9afe959
70cd355
32ad23f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"testing" | ||
|
||
"github.com/package-url/packageurl-go" | ||
"github.com/samber/lo" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
|
@@ -581,6 +582,53 @@ func TestEncoder_Encode(t *testing.T) { | |
}, | ||
wantVulns: make(map[uuid.UUID][]core.Vulnerability), | ||
}, | ||
{ | ||
name: "SBOM file without root component", | ||
report: types.Report{ | ||
SchemaVersion: 2, | ||
ArtifactName: "report.cdx.json", | ||
ArtifactType: artifact.TypeCycloneDX, | ||
Results: []types.Result{ | ||
{ | ||
Target: "Java", | ||
Type: ftypes.Jar, | ||
Class: types.ClassLangPkg, | ||
Packages: []ftypes.Package{ | ||
{ | ||
ID: "org.apache.logging.log4j:log4j-core:2.23.1", | ||
Name: "org.apache.logging.log4j:log4j-core", | ||
Version: "2.23.1", | ||
Identifier: ftypes.PkgIdentifier{ | ||
UID: "6C0AE96901617503", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it needed? UID is not used in encode.go for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh.. right. Thanks! Removed in 9afe959 |
||
PURL: &packageurl.PackageURL{ | ||
Type: packageurl.TypeMaven, | ||
Namespace: "org.apache.logging.log4j", | ||
Name: "log4j-core", | ||
Version: "2.23.1", | ||
}, | ||
}, | ||
FilePath: "log4j-core-2.23.1.jar", | ||
}, | ||
}, | ||
}, | ||
}, | ||
BOM: newTestBOM2(t), | ||
}, | ||
wantComponents: map[uuid.UUID]*core.Component{ | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000001"): fsComponent, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000002"): libComponentWithUID(), | ||
}, | ||
wantRels: map[uuid.UUID][]core.Relationship{ | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000001"): { | ||
{ | ||
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000002"), | ||
Type: core.RelationshipContains, | ||
}, | ||
}, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000002"): nil, | ||
}, | ||
wantVulns: make(map[uuid.UUID][]core.Vulnerability), | ||
}, | ||
{ | ||
name: "json file created from SBOM file (BOM is empty)", | ||
report: types.Report{ | ||
|
@@ -728,9 +776,23 @@ var ( | |
} | ||
) | ||
|
||
func libComponentWithUID() *core.Component { | ||
component := lo.FromPtr(libComponent) | ||
component.PkgIdentifier.UID = "6C0AE96901617503" | ||
return lo.ToPtr(component) | ||
} | ||
|
||
func newTestBOM(t *testing.T) *core.BOM { | ||
uuid.SetFakeUUID(t, "2ff14136-e09f-4df9-80ea-%012d") | ||
bom := core.NewBOM(core.Options{}) | ||
bom.AddComponent(appComponent) | ||
return bom | ||
} | ||
|
||
// BOM without root component | ||
func newTestBOM2(t *testing.T) *core.BOM { | ||
uuid.SetFakeUUID(t, "2ff14136-e09f-4df9-80ea-%012d") | ||
bom := core.NewBOM(core.Options{}) | ||
bom.AddComponent(libComponent) | ||
return bom | ||
} |
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.
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.
updated in c4c413a