Skip to content

Commit

Permalink
fix: capture dependencies when parsing SPDX SBOMs (#2869)
Browse files Browse the repository at this point in the history
Signed-off-by: Russell Haering <[email protected]>
  • Loading branch information
russellhaering authored May 14, 2024
1 parent 4a18895 commit e767bcf
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
7 changes: 7 additions & 0 deletions syft/format/common/spdxhelpers/to_syft_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ func collectDocRelationships(spdxIDMap map[string]any, doc *spdx.Document) (out
}
} else {
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:
typ = artifact.ContainsRelationship
to = toPackage
Expand Down
60 changes: 60 additions & 0 deletions syft/format/common/spdxhelpers/to_syft_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit e767bcf

Please sign in to comment.