-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: IntegrityStream responds to mutating opts object mid-stream
This allows us to start a stream, then get the integrity value mid-way through, and THEN update the options with the expected integrity.
- Loading branch information
Showing
2 changed files
with
74 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const ssri = require('../') | ||
const t = require('tap') | ||
|
||
const data = 'hello world' | ||
const expectIntegrity = ssri.fromData(data, { algorithms: ['sha512'] }) | ||
const expectSize = data.length | ||
|
||
t.test('support adding bad integrity later', t => { | ||
const opts = {} | ||
const stream = ssri.integrityStream(opts) | ||
opts.integrity = ssri.parse('sha512-deepbeets') | ||
return t.rejects(stream.end(data).collect(), { | ||
code: 'EINTEGRITY' | ||
}) | ||
}) | ||
|
||
t.test('support adding bad integrity string later', t => { | ||
const opts = {} | ||
const stream = ssri.integrityStream(opts) | ||
opts.integrity = 'sha512-deepbeets' | ||
return t.rejects(stream.end(data).collect(), { | ||
code: 'EINTEGRITY' | ||
}) | ||
}) | ||
|
||
t.test('support adding bad size later', t => { | ||
const opts = {} | ||
const stream = ssri.integrityStream(opts) | ||
opts.size = 2 | ||
return t.rejects(stream.end(data).collect(), { | ||
code: 'EBADSIZE' | ||
}) | ||
}) | ||
|
||
t.test('support adding good integrity later', t => { | ||
const opts = {} | ||
const stream = ssri.integrityStream(opts) | ||
opts.integrity = expectIntegrity | ||
return stream.end(data).on('verified', match => { | ||
t.same(match, expectIntegrity.sha512[0]) | ||
}).collect() | ||
}) | ||
|
||
t.test('support adding good integrity string later', t => { | ||
const opts = {} | ||
const stream = ssri.integrityStream(opts) | ||
opts.integrity = String(expectIntegrity) | ||
return stream.end(data).on('verified', match => { | ||
t.same(match, expectIntegrity.sha512[0]) | ||
}).collect() | ||
}) | ||
|
||
t.test('support adding good size later', t => { | ||
const opts = {} | ||
const stream = ssri.integrityStream(opts) | ||
opts.size = expectSize | ||
return stream.end(data).on('size', size => { | ||
t.same(size, expectSize) | ||
}).collect() | ||
}) |