Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support packument without versions #85

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/advisory.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Advisory {

this[_packument] = packument

const pakuVersions = Object.keys(packument.versions)
const pakuVersions = Object.keys(packument.versions || {})
const allVersions = new Set([...pakuVersions, ...this.versions])
const versionsAdded = []
const versionsRemoved = []
Expand Down Expand Up @@ -242,7 +242,7 @@ class Advisory {
// check the dependency of this version on the vulnerable dep
// if we got a version that's not in the packument, fall back on
// the spec provided, if possible.
const mani = this[_packument].versions[version] || {
const mani = this[_packument]?.versions?.[version] || {
dependencies: {
[this.dependency]: spec,
},
Expand Down
22 changes: 22 additions & 0 deletions test/advisory.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,28 @@ t.test('load with empty packument', t => {
t.end()
})

t.test('load with no package version in packument', t => {
const v = new Advisory('semver', advisories.semver)
v.load({}, { name: 'semver' })
t.match(v, {
constructor: Advisory,
source: 31,
name: 'semver',
dependency: 'semver',
title: 'Regular Expression Denial of Service',
url: 'https://npmjs.com/advisories/31',
severity: 'moderate',
versions: [],
vulnerableVersions: [],
range: '<4.3.2',
id: 'jETG9IyfV60PqVhvt3BAecPdQKL2CvXOXr1GeFeSsTkGn8YHi+dU93h8zcjK/xptcxeaYeUBBKmD83eafSecwA==',
})

t.ok(v.testVersion('4.3.1'), 'version covered by range is vulnerable')
t.match(v, { vulnerableVersions: ['4.3.1'], versions: [] }, 'added to set')
t.end()
})

t.test('a package with a lot of prerelease versions', t => {
const a = advisories['graphql-codegen-plugin-helpers']
const v = new Advisory('@graphql-codegen/plugin-helpers', a)
Expand Down