Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions syft/formats/common/cyclonedxhelpers/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ func collectPackages(component *cyclonedx.Component, s *sbom.SBOM, idMap map[str
syftID := extractSyftPacakgeID(component.BOMRef)
if syftID != "" {
idMap[syftID] = p
p.OverrideID(artifact.ID(syftID))
} else {
// TODO there must be a better way than needing to call this manually:
p.SetID()
}
// TODO there must be a better way than needing to call this manually:
p.SetID()
Comment thread
wagoodman marked this conversation as resolved.
s.Artifacts.Packages.Add(*p)
}

Expand Down
38 changes: 38 additions & 0 deletions syft/formats/common/cyclonedxhelpers/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,41 @@ func Test_missingComponentsDecode(t *testing.T) {

assert.NoError(t, err)
}

func Test_useSyftIDWhenProvided(t *testing.T) {

packageWithId := cyclonedx.Component{
BOMRef: "pkg:maven/org.springframework.boot/spring-boot-starter-test?package-id=646a5a71a4abeee0",
Type: cyclonedx.ComponentTypeLibrary,
Name: "spring-boot-starter-test",
Version: "",
PackageURL: "pkg:maven/org.springframework.boot/spring-boot-starter-test",
}

packageID := extractSyftPacakgeID(packageWithId.BOMRef)
Comment thread
wagoodman marked this conversation as resolved.
Outdated

packageWithoutId := cyclonedx.Component{
BOMRef: "pkg:maven/org.springframework.boot/spring-boot-starter-webflux",
Comment thread
wagoodman marked this conversation as resolved.
Type: cyclonedx.ComponentTypeLibrary,
Name: "spring-boot-starter-webflux",
Version: "",
PackageURL: "pkg:maven/org.springframework.boot/spring-boot-starter-webflux",
}

bom := cyclonedx.BOM{Metadata: nil,
Components: &[]cyclonedx.Component{
packageWithId,
packageWithoutId,
}}

sbom, err := ToSyftModel(&bom)

assert.Nil(t, err)
assert.NotNil(t, sbom.Artifacts.Packages.Package(artifact.ID(packageID)))

pkgsWithoutID := sbom.Artifacts.Packages.PackagesByName(packageWithoutId.Name)

assert.Len(t, pkgsWithoutID, 1)
assert.NotEqual(t, "", pkgsWithoutID[0].ID())

}