From 8dc2e6256111d36a70b1eb05c7335119c31bc96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 3 Apr 2017 03:41:17 -0700 Subject: [PATCH] fix(integrity): use EINTEGRITY error code and update ssri --- README.md | 2 +- lib/content/read.js | 2 +- lib/content/write.js | 2 +- lib/util/move-file.js | 2 +- lib/verify.js | 2 +- package.json | 2 +- test/content.read.js | 8 ++++---- test/content.write.js | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 30297672..d3d9ea7d 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ with an `EBADSIZE` error. If present, the pre-calculated digest for the inserted content. If this option if provided and does not match the post-insertion digest, insertion will fail -with an `EBADCHECKSUM` error. +with an `EINTEGRITY` error. `hashAlgorithm` has no effect if this option is present. diff --git a/lib/content/read.js b/lib/content/read.js index 23bc0134..e7c78d08 100644 --- a/lib/content/read.js +++ b/lib/content/read.js @@ -94,7 +94,7 @@ function sizeError (expected, found) { function checksumError (sri, path) { var err = new Error(`Checksum failed for ${sri} (${path})`) - err.code = 'EBADCHECKSUM' + err.code = 'EINTEGRITY' err.sri = sri err.path = path return err diff --git a/lib/content/write.js b/lib/content/write.js index 0cfbaa50..34c30d3c 100644 --- a/lib/content/write.js +++ b/lib/content/write.js @@ -159,7 +159,7 @@ function sizeError (expected, found) { function checksumError (expected, found) { var err = new Error('checksum failed') - err.code = 'EBADCHECKSUM' + err.code = 'EINTEGRITY' err.expected = expected err.found = found return err diff --git a/lib/util/move-file.js b/lib/util/move-file.js index dcb49f32..422c8294 100644 --- a/lib/util/move-file.js +++ b/lib/util/move-file.js @@ -12,7 +12,7 @@ function moveFile (src, dest) { // trying to move it, we should just not bother. // // In the case of cache corruption, users will receive an - // EBADCHECKSUM error elsewhere, and can remove the offending + // EINTEGRITY error elsewhere, and can remove the offending // content their own way. // // Note that, as the name suggests, this strictly only supports file moves. diff --git a/lib/verify.js b/lib/verify.js index ad2c8927..1c2941c0 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -133,7 +133,7 @@ function verifyContent (filepath, sri) { fs.createReadStream(filepath), sri ).catch(err => { - if (err.code !== 'EBADCHECKSUM') { throw err } + if (err.code !== 'EINTEGRITY') { throw err } return rimraf(filepath).then(() => { contentInfo.valid = false }) diff --git a/package.json b/package.json index efc8cde3..ce4d277d 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "move-concurrently": "^1.0.0", "promise-inflight": "^1.0.1", "rimraf": "^2.6.1", - "ssri": "^3.0.0", + "ssri": "^4.0.0", "unique-filename": "^1.1.0" }, "devDependencies": { diff --git a/test/content.read.js b/test/content.read.js index 514f85c7..54d42d26 100644 --- a/test/content.read.js +++ b/test/content.read.js @@ -100,11 +100,11 @@ test('read: errors if content fails checksum', function (t) { throw new Error('end was called even though stream errored') }) return BB.join( - finished(stream).catch({code: 'EBADCHECKSUM'}, err => err), - read(CACHE, INTEGRITY).catch({code: 'EBADCHECKSUM'}, err => err), + finished(stream).catch({code: 'EINTEGRITY'}, err => err), + read(CACHE, INTEGRITY).catch({code: 'EINTEGRITY'}, err => err), (streamErr, bulkErr) => { - t.equal(streamErr.code, 'EBADCHECKSUM', 'stream got the right error') - t.equal(bulkErr.code, 'EBADCHECKSUM', 'bulk got the right error') + t.equal(streamErr.code, 'EINTEGRITY', 'stream got the right error') + t.equal(bulkErr.code, 'EINTEGRITY', 'bulk got the right error') } ) }) diff --git a/test/content.write.js b/test/content.write.js index 8b25b790..de441031 100644 --- a/test/content.write.js +++ b/test/content.write.js @@ -55,7 +55,7 @@ test('checks input digest doesn\'t match data', t => { }), err => { t.ok(!int1, 'no digest emitted') t.ok(!!err, 'got an error') - t.equal(err.code, 'EBADCHECKSUM', 'returns a useful error code') + t.equal(err.code, 'EINTEGRITY', 'returns a useful error code') }) pipe(fromString(CONTENT), write.stream(CACHE, { integrity: INTEGRITY