Skip to content

Commit 0d90a01

Browse files
authored
fix(audit): add a condition to allow third-party registries returning E400 (#5480)
* Add a condition to fix third-party registries returning E400 * changed to a separate test. Co-authored-by: Juan Heyns <jheyns@mit.edu>
1 parent 8743366 commit 0d90a01

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/commands/audit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class VerifySignatures {
156156
...key,
157157
pemkey: `-----BEGIN PUBLIC KEY-----\n${key.key}\n-----END PUBLIC KEY-----`,
158158
}))).catch(err => {
159-
if (err.code === 'E404') {
159+
if (err.code === 'E404' || err.code === 'E400') {
160160
return null
161161
} else {
162162
throw err

test/lib/commands/audit.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ t.test('audit signatures', async t => {
11711171
t.matchSnapshot(joinedOutput())
11721172
})
11731173

1174-
t.test('third-party registry without keys does not verify', async t => {
1174+
t.test('third-party registry without keys (E404) does not verify', async t => {
11751175
const registryUrl = 'https://verdaccio-clone2.org'
11761176
const { npm } = await loadMockNpm(t, {
11771177
prefixDir: installWithThirdPartyRegistry,
@@ -1200,6 +1200,35 @@ t.test('audit signatures', async t => {
12001200
)
12011201
})
12021202

1203+
t.test('third-party registry without keys (E400) does not verify', async t => {
1204+
const registryUrl = 'https://verdaccio-clone2.org'
1205+
const { npm } = await loadMockNpm(t, {
1206+
prefixDir: installWithThirdPartyRegistry,
1207+
config: {
1208+
'@npmcli:registry': registryUrl,
1209+
},
1210+
})
1211+
const registry = new MockRegistry({ tap: t, registry: registryUrl })
1212+
const manifest = registry.manifest({
1213+
name: '@npmcli/arborist',
1214+
packuments: [{
1215+
version: '1.0.14',
1216+
dist: {
1217+
tarball: 'https://registry.npmjs.org/@npmcli/arborist/-/@npmcli/arborist-1.0.14.tgz',
1218+
integrity: 'sha512-caa8hv5rW9VpQKk6tyNRvSaVDySVjo9GkI7Wj/wcsFyxPm3tYrE' +
1219+
'sFyTjSnJH8HCIfEGVQNjqqKXaXLFVp7UBag==',
1220+
},
1221+
}],
1222+
})
1223+
await registry.package({ manifest })
1224+
registry.nock.get('/-/npm/v1/keys').reply(400)
1225+
1226+
await t.rejects(
1227+
npm.exec('audit', ['signatures']),
1228+
/found no dependencies to audit that where installed from a supported registry/
1229+
)
1230+
})
1231+
12031232
t.test('third-party registry with keys and signatures', async t => {
12041233
const registryUrl = 'https://verdaccio-clone.org'
12051234
const { npm, joinedOutput } = await loadMockNpm(t, {

0 commit comments

Comments
 (0)