Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Commit

Permalink
fix(integrity): update cacache and ssri and change EBADCHECKSUM -> EI…
Browse files Browse the repository at this point in the history
…NTEGRITY
  • Loading branch information
zkat committed Apr 3, 2017
1 parent fff0335 commit b6cf6f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ fetch('http://reliable.site.com', {

#### <a name="opts-integrity"></a> `> opts.integrity`

Matches the response body against the given [Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) metadata. If verification fails, the request will fail with an `EBADCHECKSUM` error.
Matches the response body against the given [Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) metadata. If verification fails, the request will fail with an `EINTEGRITY` error.

`integrity` may either be a string or an [`ssri`](https://npm.im/ssri) `Integrity`-like.

Expand All @@ -294,7 +294,7 @@ fetch('https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-1.0.0.tg

fetch('https://malicious-registry.org/make-fetch-happen/-/make-fetch-happen-1.0.0.tgz'. {
integrity: 'sha1-o47j7zAYnedYFn1dF/fR9OV3z8Q='
}) // Error: EBADCHECKSUM
}) // Error: EINTEGRITY
```

### <a name="wow"></a> Message From Our Sponsors
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
"license": "CC0-1.0",
"dependencies": {
"bluebird": "^3.5.0",
"cacache": "^7.0.1",
"cacache": "^7.0.2",
"checksum-stream": "^1.0.2",
"lru-cache": "^4.0.2",
"mississippi": "^1.2.0",
"node-fetch": "^2.0.0-alpha.3",
"promise-retry": "^1.1.1",
"proxy-agent": "^2.0.0",
"safe-buffer": "^5.0.1",
"ssri": "^3.0.2"
"ssri": "^4.0.0"
},
"devDependencies": {
"mkdirp": "^0.5.1",
Expand Down
12 changes: 6 additions & 6 deletions test/integrity.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('basic integrity verification', t => {
}).then(buf => {
throw new Error(`bad data: ${buf.toString('utf8')}`)
}).catch(err => {
t.equal(err.code, 'EBADCHECKSUM', 'content failed checksum!')
t.equal(err.code, 'EINTEGRITY', 'content failed checksum!')
})
})
})
Expand All @@ -51,7 +51,7 @@ test('picks the "best" algorithm', t => {
}).then(buf => {
throw new Error(`bad data: ${buf.toString('utf8')}`)
}).catch(err => {
t.equal(err.code, 'EBADCHECKSUM', 'content validated with either sha256 or sha384 (likely the latter)')
t.equal(err.code, 'EINTEGRITY', 'content validated with either sha256 or sha384 (likely the latter)')
})
}).then(() => {
// invalidate sha384. sha256 is still valid, in theory
Expand All @@ -61,7 +61,7 @@ test('picks the "best" algorithm', t => {
}).then(buf => {
throw new Error(`bad data: ${buf.toString('utf8')}`)
}).catch(err => {
t.equal(err.code, 'EBADCHECKSUM', 'strongest algorithm (sha384) treated as authoritative -- sha256 not used')
t.equal(err.code, 'EINTEGRITY', 'strongest algorithm (sha384) treated as authoritative -- sha256 not used')
})
}).then(() => {
// remove bad sha384 altogether. sha256 remains valid
Expand Down Expand Up @@ -92,7 +92,7 @@ test('supports multiple hashes per algorithm', t => {
return safetch(`${HOST}/bad`).then(res => res.buffer()).then(buf => {
throw new Error(`bad data: ${buf.toString('utf8')}`)
}).catch(err => {
t.equal(err.code, 'EBADCHECKSUM', 'only the two valid contents pass')
t.equal(err.code, 'EINTEGRITY', 'only the two valid contents pass')
})
})
})
Expand All @@ -111,7 +111,7 @@ test('checks integrity on cache fetch too', t => {
return safetch(`${HOST}/test`).then(res => res.buffer()).then(buf => {
throw new Error(`bad data: ${buf.toString('utf8')}`)
}).catch(err => {
t.equal(err.code, 'EBADCHECKSUM', 'cached content failed checksum!')
t.equal(err.code, 'EINTEGRITY', 'cached content failed checksum!')
})
}).then(() => {
srv.get('/test').reply(200, 'nope')
Expand All @@ -122,7 +122,7 @@ test('checks integrity on cache fetch too', t => {
}).then(res => res.buffer()).then(buf => {
throw new Error(`bad data: ${buf.toString('utf8')}`)
}).catch(err => {
t.equal(err.code, 'EBADCHECKSUM', 'cached content failed checksum!')
t.equal(err.code, 'EINTEGRITY', 'cached content failed checksum!')
})
})
})

0 comments on commit b6cf6f6

Please sign in to comment.