mirror of
https://github.com/anchore/syft.git
synced 2026-02-12 10:36:45 +01:00
fix: capture dependencies when parsing SPDX SBOMs (#2869)
Signed-off-by: Russell Haering <russellhaering@gmail.com>
This commit is contained in:
parent
4a18895545
commit
e767bcff4b
@ -381,6 +381,13 @@ func collectDocRelationships(spdxIDMap map[string]any, doc *spdx.Document) (out
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch helpers.RelationshipType(r.Relationship) {
|
switch helpers.RelationshipType(r.Relationship) {
|
||||||
|
case helpers.DependencyOfRelationship:
|
||||||
|
typ = artifact.DependencyOfRelationship
|
||||||
|
to = toPackage
|
||||||
|
case helpers.DependsOnRelationship:
|
||||||
|
typ = artifact.DependencyOfRelationship
|
||||||
|
to = from
|
||||||
|
from = toPackage
|
||||||
case helpers.ContainsRelationship:
|
case helpers.ContainsRelationship:
|
||||||
typ = artifact.ContainsRelationship
|
typ = artifact.ContainsRelationship
|
||||||
to = toPackage
|
to = toPackage
|
||||||
|
|||||||
@ -414,6 +414,66 @@ func Test_toSyftRelationships(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "dependency-of relationship",
|
||||||
|
args: args{
|
||||||
|
spdxIDMap: map[string]any{
|
||||||
|
string(toSPDXID(pkg2)): pkg2,
|
||||||
|
string(toSPDXID(pkg3)): pkg3,
|
||||||
|
},
|
||||||
|
doc: &spdx.Document{
|
||||||
|
Relationships: []*spdx.Relationship{
|
||||||
|
{
|
||||||
|
RefA: common.DocElementID{
|
||||||
|
ElementRefID: toSPDXID(pkg2),
|
||||||
|
},
|
||||||
|
RefB: common.DocElementID{
|
||||||
|
ElementRefID: toSPDXID(pkg3),
|
||||||
|
},
|
||||||
|
Relationship: spdx.RelationshipDependencyOf,
|
||||||
|
RelationshipComment: "dependency-of: indicates that the package in RefA is a dependency of the package in RefB",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []artifact.Relationship{
|
||||||
|
{
|
||||||
|
From: pkg2,
|
||||||
|
To: pkg3,
|
||||||
|
Type: artifact.DependencyOfRelationship,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "dependends-on relationship",
|
||||||
|
args: args{
|
||||||
|
spdxIDMap: map[string]any{
|
||||||
|
string(toSPDXID(pkg2)): pkg2,
|
||||||
|
string(toSPDXID(pkg3)): pkg3,
|
||||||
|
},
|
||||||
|
doc: &spdx.Document{
|
||||||
|
Relationships: []*spdx.Relationship{
|
||||||
|
{
|
||||||
|
RefA: common.DocElementID{
|
||||||
|
ElementRefID: toSPDXID(pkg3),
|
||||||
|
},
|
||||||
|
RefB: common.DocElementID{
|
||||||
|
ElementRefID: toSPDXID(pkg2),
|
||||||
|
},
|
||||||
|
Relationship: spdx.RelationshipDependsOn,
|
||||||
|
RelationshipComment: "dependends-on: indicates that the package in RefA depends on the package in RefB",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []artifact.Relationship{
|
||||||
|
{
|
||||||
|
From: pkg2,
|
||||||
|
To: pkg3,
|
||||||
|
Type: artifact.DependencyOfRelationship,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user