fix: cyclonedx component type for binaries (#1406)

This commit is contained in:
Keith Zantow 2022-12-19 19:49:27 -05:00 committed by GitHub
parent b1d6dae203
commit 4ffbeeeea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 1 deletions

View File

@ -27,8 +27,13 @@ func encodeComponent(p pkg.Package) cyclonedx.Component {
properties = &props properties = &props
} }
componentType := cyclonedx.ComponentTypeLibrary
if p.Type == pkg.BinaryPkg {
componentType = cyclonedx.ComponentTypeApplication
}
return cyclonedx.Component{ return cyclonedx.Component{
Type: cyclonedx.ComponentTypeLibrary, Type: componentType,
Name: p.Name, Name: p.Name,
Group: encodeGroup(p), Group: encodeGroup(p),
Version: p.Version, Version: p.Version,

View File

@ -144,6 +144,60 @@ func Test_encodeComponentProperties(t *testing.T) {
} }
} }
func Test_encodeCompomentType(t *testing.T) {
tests := []struct {
name string
pkg pkg.Package
want cyclonedx.Component
}{
{
name: "non-binary package",
pkg: pkg.Package{
Name: "pkg1",
Version: "1.9.2",
Type: pkg.GoModulePkg,
},
want: cyclonedx.Component{
Name: "pkg1",
Version: "1.9.2",
Type: cyclonedx.ComponentTypeLibrary,
Properties: &[]cyclonedx.Property{
{
Name: "syft:package:type",
Value: "go-module",
},
},
},
},
{
name: "non-binary package",
pkg: pkg.Package{
Name: "pkg1",
Version: "3.1.2",
Type: pkg.BinaryPkg,
},
want: cyclonedx.Component{
Name: "pkg1",
Version: "3.1.2",
Type: cyclonedx.ComponentTypeApplication,
Properties: &[]cyclonedx.Property{
{
Name: "syft:package:type",
Value: "binary",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.pkg.ID()
p := encodeComponent(tt.pkg)
assert.Equal(t, tt.want, p)
})
}
}
func Test_deriveBomRef(t *testing.T) { func Test_deriveBomRef(t *testing.T) {
pkgWithPurl := pkg.Package{ pkgWithPurl := pkg.Package{
Name: "django", Name: "django",