mirror of
https://github.com/anchore/syft.git
synced 2026-02-12 02:26:42 +01:00
fix: extract file ids correctly for spdx-json (#1156)
Previously, extracting relationships between packages and files was not completing correctly, as SPDXRef- ElementIDs were being compared to raw IDs, and so never matched. This patch ensures that we always compare ElementIDs, to ensure that the hasFiles field is correctly populated. Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
parent
2693a8c19a
commit
3db6911865
@ -112,8 +112,10 @@ func fileIDsForPackage(packageSpdxID string, relationships []artifact.Relationsh
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(relationship.From.ID()) == packageSpdxID {
|
from := model.ElementID(relationship.From.ID()).String()
|
||||||
fileIDs = append(fileIDs, string(relationship.To.ID()))
|
to := model.ElementID(relationship.To.ID()).String()
|
||||||
|
if from == packageSpdxID {
|
||||||
|
fileIDs = append(fileIDs, to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fileIDs
|
return fileIDs
|
||||||
|
|||||||
@ -188,7 +188,7 @@ func Test_fileIDsForPackage(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "find file IDs for packages with package-file relationships",
|
name: "find file IDs for packages with package-file relationships",
|
||||||
id: string(p.ID()),
|
id: model.ElementID(p.ID()).String(),
|
||||||
relationships: []artifact.Relationship{
|
relationships: []artifact.Relationship{
|
||||||
{
|
{
|
||||||
From: p,
|
From: p,
|
||||||
@ -197,12 +197,12 @@ func Test_fileIDsForPackage(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: []string{
|
expected: []string{
|
||||||
string(c.ID()),
|
model.ElementID(c.ID()).String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ignore package-to-package",
|
name: "ignore package-to-package",
|
||||||
id: string(p.ID()),
|
id: model.ElementID(p.ID()).String(),
|
||||||
relationships: []artifact.Relationship{
|
relationships: []artifact.Relationship{
|
||||||
{
|
{
|
||||||
From: p,
|
From: p,
|
||||||
@ -214,7 +214,7 @@ func Test_fileIDsForPackage(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ignore file-to-file",
|
name: "ignore file-to-file",
|
||||||
id: string(p.ID()),
|
id: model.ElementID(p.ID()).String(),
|
||||||
relationships: []artifact.Relationship{
|
relationships: []artifact.Relationship{
|
||||||
{
|
{
|
||||||
From: c,
|
From: c,
|
||||||
@ -226,7 +226,7 @@ func Test_fileIDsForPackage(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ignore file-to-package",
|
name: "ignore file-to-package",
|
||||||
id: string(p.ID()),
|
id: model.ElementID(p.ID()).String(),
|
||||||
relationships: []artifact.Relationship{
|
relationships: []artifact.Relationship{
|
||||||
{
|
{
|
||||||
From: c,
|
From: c,
|
||||||
@ -238,7 +238,7 @@ func Test_fileIDsForPackage(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "filter by relationship type",
|
name: "filter by relationship type",
|
||||||
id: string(p.ID()),
|
id: model.ElementID(p.ID()).String(),
|
||||||
relationships: []artifact.Relationship{
|
relationships: []artifact.Relationship{
|
||||||
{
|
{
|
||||||
From: p,
|
From: p,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user