Skip to content

Commit

Permalink
When severity missing, treat as 'high' severity
Browse files Browse the repository at this point in the history
PR-URL: #4
Credit: @isaacs
Close: #4
Reviewed-by: @nlf
  • Loading branch information
isaacs committed Feb 18, 2021
1 parent ab7a40f commit a2dcf13
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/advisory.js
Expand Up @@ -35,7 +35,7 @@ class Advisory {
this.url = null
}

this.severity = source.severity
this.severity = source.severity || 'high'
this.versions = []
this.vulnerableVersions = []

Expand Down
18 changes: 18 additions & 0 deletions test/advisory.js
Expand Up @@ -339,3 +339,21 @@ t.test('default to * when no vulnerable_versions specified', t => {
}, 'default to all versions being considered vulnerable')
t.end()
})

t.test('default to "high" when no severity specified', t => {
const name = 'no-severity-specified'
const v = new Advisory(name, advisories[name])
t.same(v, {
source: 123456789,
name: 'no-severity-specified',
dependency: 'no-severity-specified',
title: 'No severity, so high severity',
url: 'https://npmjs.com/advisories/123456789',
severity: 'high',
versions: [],
vulnerableVersions: [],
range: '1.x',
id: 'ajZ5Jt7T99fpH0t8LgyBbDVivYlv/1OGrs/o+D8KmLDl+LKTjObUEt19cAZGaWdqiemuQOnvdZD577nKU+giIQ==',
}, 'default to all versions being considered vulnerable')
t.end()
})
6 changes: 6 additions & 0 deletions test/fixtures/advisories/no-severity-specified.json
@@ -0,0 +1,6 @@
{
"id": 123456789,
"url": "https://npmjs.com/advisories/123456789",
"title": "No severity, so high severity",
"vulnerable_versions": "1.x"
}

0 comments on commit a2dcf13

Please sign in to comment.