Correct CycloneDX distro decoding (#745)

This commit is contained in:
Keith Zantow 2022-03-11 09:27:18 -05:00 committed by GitHub
parent 7789506dc6
commit 6c8102bf28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 23 deletions

View File

@ -5,6 +5,8 @@ import (
"io"
"github.com/CycloneDX/cyclonedx-go"
"github.com/anchore/syft/internal/formats/common"
"github.com/anchore/syft/syft/artifact"
"github.com/anchore/syft/syft/linux"
"github.com/anchore/syft/syft/pkg"
@ -157,6 +159,14 @@ func linuxReleaseFromOSComponent(component *cyclonedx.Component) *linux.Release
}
}
if component.Properties != nil {
values := map[string]string{}
for _, p := range *component.Properties {
values[p.Name] = p.Value
}
common.DecodeInto(&rel, values, "syft:distro", CycloneDXFields)
}
return rel
}

View File

@ -54,7 +54,9 @@ func TestEncodeDecodeEncodeCycleComparison(t *testing.T) {
for _, test := range tests {
t.Run(string(test.formatOption), func(t *testing.T) {
originalSBOM, _ := catalogFixtureImage(t, "image-pkg-coverage")
// use second image for relationships
for _, image := range []string{"image-pkg-coverage", "image-owning-package"} {
originalSBOM, _ := catalogFixtureImage(t, image)
format := syft.FormatByID(test.formatOption)
require.NotNil(t, format)
@ -85,6 +87,7 @@ func TestEncodeDecodeEncodeCycleComparison(t *testing.T) {
t.Errorf("diff: %s", dmp.DiffPrettyText(diffs))
}
}
}
})
}
}