Skip to content

Commit

Permalink
fix: cyclonedx component type for binaries (#1406)
Browse files Browse the repository at this point in the history
  • Loading branch information
kzantow authored Dec 20, 2022
1 parent b1d6dae commit 4ffbeee
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
7 changes: 6 additions & 1 deletion syft/formats/common/cyclonedxhelpers/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ func encodeComponent(p pkg.Package) cyclonedx.Component {
properties = &props
}

componentType := cyclonedx.ComponentTypeLibrary
if p.Type == pkg.BinaryPkg {
componentType = cyclonedx.ComponentTypeApplication
}

return cyclonedx.Component{
Type: cyclonedx.ComponentTypeLibrary,
Type: componentType,
Name: p.Name,
Group: encodeGroup(p),
Version: p.Version,
Expand Down
54 changes: 54 additions & 0 deletions syft/formats/common/cyclonedxhelpers/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
pkgWithPurl := pkg.Package{
Name: "django",
Expand Down

0 comments on commit 4ffbeee

Please sign in to comment.