-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ⭐️ support loading direct dependencies for npm package lock * ⭐️ npm package resource * 🧹 handle package.json version ranges * 🧹 simplify tests * 🧹 ensure that the root package is included when we gather package json dependencies * 🧹 address feedback
- Loading branch information
1 parent
b4b0122
commit 0bb01bd
Showing
11 changed files
with
1,101 additions
and
105 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,31 +274,46 @@ func TestPackageJsonParser(t *testing.T) { | |
require.NoError(t, err) | ||
defer f.Close() | ||
|
||
root, pkgs, err := (&PackageJsonParser{}).Parse(f) | ||
info, err := (&PackageJsonParser{}).Parse(f, "path/package.json") | ||
assert.Nil(t, err) | ||
assert.Equal(t, 30, len(pkgs)) | ||
|
||
root := info.Root() | ||
assert.Equal(t, &Package{ | ||
Name: "express", | ||
Version: "4.16.4", | ||
Purl: "pkg:npm/[email protected]", | ||
Cpes: []string{"cpe:2.3:a:express:express:4.16.4:*:*:*:*:*:*:*"}, | ||
Name: "express", | ||
Version: "4.16.4", | ||
Purl: "pkg:npm/[email protected]", | ||
Cpes: []string{"cpe:2.3:a:express:express:4.16.4:*:*:*:*:*:*:*"}, | ||
EvidenceLocations: []string{"path/package.json"}, | ||
}, root) | ||
|
||
p := findPkg(pkgs, "path-to-regexp") | ||
transitive := info.Transitive() | ||
assert.Equal(t, 31, len(transitive)) | ||
|
||
// ensure the package is in the transitive list | ||
p := findPkg(transitive, "express") | ||
assert.Equal(t, &Package{ | ||
Name: "express", | ||
Version: "4.16.4", | ||
Purl: "pkg:npm/[email protected]", | ||
Cpes: []string{"cpe:2.3:a:express:express:4.16.4:*:*:*:*:*:*:*"}, | ||
EvidenceLocations: []string{"path/package.json"}, | ||
}, p) | ||
|
||
p = findPkg(transitive, "path-to-regexp") | ||
assert.Equal(t, &Package{ | ||
Name: "path-to-regexp", | ||
Version: "0.1.7", | ||
Purl: "pkg:npm/[email protected]", | ||
Cpes: []string{"cpe:2.3:a:path-to-regexp:path-to-regexp:0.1.7:*:*:*:*:*:*:*"}, | ||
Name: "path-to-regexp", | ||
Version: "0.1.7", | ||
Purl: "pkg:npm/[email protected]", | ||
Cpes: []string{"cpe:2.3:a:path-to-regexp:path-to-regexp:0.1.7:*:*:*:*:*:*:*"}, | ||
EvidenceLocations: []string{"path/package.json"}, | ||
}, p) | ||
|
||
p = findPkg(pkgs, "range-parser") | ||
p = findPkg(transitive, "range-parser") | ||
assert.Equal(t, &Package{ | ||
Name: "range-parser", | ||
Version: "~1.2.0", | ||
// TODO: we need to handle the range properly | ||
Purl: "pkg:npm/range-parser@~1.2.0", | ||
Cpes: []string{"cpe:2.3:a:range-parser:range-parser:\\~1.2.0:*:*:*:*:*:*:*"}, | ||
Name: "range-parser", | ||
Version: "~1.2.0", | ||
Purl: "pkg:npm/[email protected]", | ||
Cpes: []string{"cpe:2.3:a:range-parser:range-parser:1.2.0:*:*:*:*:*:*:*"}, | ||
EvidenceLocations: []string{"path/package.json"}, | ||
}, p) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.