Skip to content

Commit

Permalink
fix: throw 403 for forbidden major/minor versions
Browse files Browse the repository at this point in the history
Co-authored-by: @claudiahdz
Co-authored-by: @emyl3
Co-authored-by: @rrconey

PR-URL: #2
Credit: @claudiahdz
Close: #2
Reviewed-by: @isaacs
  • Loading branch information
shanisebarona authored and isaacs committed Aug 28, 2019
1 parent ed0fc29 commit 003286e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -96,6 +96,10 @@ function pickManifest (packument, wanted, opts) {
target = stillFresh[0]
}

if (!target && restrictedVersions) {
target = semver.maxSatisfying(restrictedVersions, wanted, true)
}

const manifest = (
target &&
packument.versions[target]
Expand Down
40 changes: 40 additions & 0 deletions test/index.js
Expand Up @@ -147,6 +147,46 @@ test('E403 if version is forbidden', t => {
t.done()
})

test('E403 if version is forbidden, provided a minor version', t => {
const metadata = {
policyRestrictions: {
versions: {
'2.1.0': { version: '2.1.0' },
'2.1.5': { version: '2.1.5' }
}
},
versions: {
'1.0.0': { version: '1.0.0' },
'2.0.0': { version: '2.0.0' },
'2.0.5': { version: '2.0.5' }
}
}
t.throws(() => {
pickManifest(metadata, '2.1')
}, {code: 'E403'}, 'got correct error on match failure')
t.done()
})

test('E403 if version is forbidden, provided a major version', t => {
const metadata = {
policyRestrictions: {
versions: {
'1.0.0': { version: '1.0.0' },
'2.1.0': { version: '2.1.0' },
'2.1.5': { version: '2.1.5' }
}
},
versions: {
'2.0.0': { version: '2.0.0' },
'2.0.5': { version: '2.0.5' }
}
}
t.throws(() => {
pickManifest(metadata, '1')
}, {code: 'E403'}, 'got correct error on match failure')
t.done()
})

test('if `defaultTag` matches a given range, use it', t => {
const metadata = {
'dist-tags': {
Expand Down

0 comments on commit 003286e

Please sign in to comment.