test(shrinkwrap): installation should fail when incorrect shasum

The installation should fail when the real shasum doesn't match the one in the shrinkwrap.yaml
This commit is contained in:
zkochan
2017-02-12 20:29:23 +02:00
parent 40bd4b630a
commit ded4bd237c

View File

@@ -1,7 +1,8 @@
import tape = require('tape')
import promisifyTape from 'tape-promise'
import writeYamlFile = require('write-yaml-file')
import {prepare, testDefaults} from './utils'
import {installPkgs} from '../src'
import {installPkgs, install} from '../src'
const test = promisifyTape(tape)
@@ -25,3 +26,34 @@ test('shrinkwrap file has correct format', async t => {
t.ok(shr.packages[id].resolution, `has resolution for ${id}`)
t.equal(shr.packages[id].resolution.tarball, 'http://localhost:4873/pkg-with-1-dep/-/pkg-with-1-dep-100.0.0.tgz', `has tarball for ${id}`)
})
test('fail when shasum from shrinkwrap does not match with the actual one', async t => {
const project = prepare(t, {
dependencies: {
'is-negative': '2.1.0',
},
})
await writeYamlFile('shrinkwrap.yaml', {
version: 0,
dependencies: {
'is-negative': 'localhost+4873/is-negative/2.1.0',
},
packages: {
'localhost+4873/is-negative/2.1.0': {
resolution: {
shasum: '00000000000000000000000000000000000000000',
tarball: 'http://localhost:4873/is-negative/-/is-negative-2.1.0.tgz',
type: 'tarball',
},
},
},
})
try {
await install(testDefaults())
t.fail('installation should have failed')
} catch (err) {
t.ok(err.message.indexOf('Incorrect shasum') !== -1, 'failed with expected error')
}
})