Skip to content

Commit

Permalink
Add download location when cataloging directory npm package lock (#2238)
Browse files Browse the repository at this point in the history
* added download locatoin (resolved) when cataloging a directory - javascript ecosystem- npm - packag-lock
	Signed-off by Auston(Aoxiang) Zhang <[email protected]>

Signed-off-by: Christopher Phillips <[email protected]>

* chore: get DCO to fire

Signed-off-by: Christopher Phillips <[email protected]>

---------

Signed-off-by: Christopher Phillips <[email protected]>
Co-authored-by: Auston-Zhang <[email protected]>
  • Loading branch information
spiffcs and Auston-Zhang authored Oct 20, 2023
1 parent e1ad340 commit ef43294
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions syft/formats/common/spdxhelpers/download_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func DownloadLocation(p pkg.Package) string {
return NoneIfEmpty(metadata.URL)
case pkg.NpmPackageJSONMetadata:
return NoneIfEmpty(metadata.URL)
case pkg.NpmPackageLockJSONMetadata:
return NoneIfEmpty(metadata.Resolved)
}
}
return NOASSERTION
Expand Down
18 changes: 18 additions & 0 deletions syft/formats/common/spdxhelpers/download_location_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ func Test_DownloadLocation(t *testing.T) {
},
expected: NONE,
},
{
name: "from npm package-lock should include resolved",
input: pkg.Package{
Metadata: pkg.NpmPackageLockJSONMetadata{
Resolved: "http://package-lock.test",
},
},
expected: "http://package-lock.test",
},
{
name: "from npm package-lock empty should be NONE",
input: pkg.Package{
Metadata: pkg.NpmPackageLockJSONMetadata{
Resolved: "",
},
},
expected: NONE,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down

0 comments on commit ef43294

Please sign in to comment.