Skip to content

Commit

Permalink
chore(tests): update to tap15
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Jun 10, 2021
1 parent d403b68 commit ef0e765
Show file tree
Hide file tree
Showing 9 changed files with 2,510 additions and 1,735 deletions.
4,107 changes: 2,441 additions & 1,666 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"devDependencies": {
"standard": "^16.0.3",
"standard-version": "^9.1.0",
"tap": "^14.10.6"
"tap": "^15.0.9"
},
"engines": {
"node": ">= 8"
Expand Down
34 changes: 17 additions & 17 deletions test/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,33 @@ test('checkData', t => {
digest: hash(TEST_DATA, 'sha512')
})
const meta = sri.sha512[0]
t.deepEqual(
t.same(
ssri.checkData(TEST_DATA, sri),
meta,
'Buffer data successfully verified'
)
t.doesNotThrow(() => {
ssri.checkData(TEST_DATA, sri, { error: true })
}, 'error not thrown when error: true and data verifies')
t.deepEqual(
t.same(
ssri.checkData(TEST_DATA, `sha512-${hash(TEST_DATA, 'sha512')}`),
meta,
'Accepts string SRI'
)
t.deepEqual(
t.same(
ssri.checkData(TEST_DATA, {
algorithm: 'sha512',
digest: hash(TEST_DATA, 'sha512')
}),
meta,
'Accepts Hash-like SRI'
)
t.deepEqual(
t.same(
ssri.checkData(TEST_DATA.toString('utf8'), sri),
meta,
'String data successfully verified'
)
t.deepEqual(
t.same(
ssri.checkData(
TEST_DATA,
`sha512-nope sha512-${hash(TEST_DATA, 'sha512')}`
Expand Down Expand Up @@ -87,7 +87,7 @@ test('checkData', t => {
ssri.checkData('nope', '', { error: true })
}, /No valid integrity hashes/, 'errors on empty sri input if error: true')

t.deepEqual(
t.same(
ssri.checkData(TEST_DATA, [
'sha512-nope',
`sha1-${hash(TEST_DATA, 'sha1')}`,
Expand All @@ -103,7 +103,7 @@ test('checkData', t => {
'opts.pickAlgorithm can be used to customize which one is used.'
)

t.deepEqual(
t.same(
ssri.checkData(TEST_DATA, [
`sha256-${hash(TEST_DATA, 'sha256')}`,
`sha1-${hash(TEST_DATA, 'sha1')}`,
Expand All @@ -119,7 +119,7 @@ test('checkData', t => {
'opts.pickAlgorithm can return false to keep the first option'
)

t.deepEqual(
t.same(
ssri.checkData(TEST_DATA, [
`sha1-${hash(TEST_DATA, 'sha1')}`,
`sha384-${hash(TEST_DATA, 'sha384')}`,
Expand All @@ -130,7 +130,7 @@ test('checkData', t => {
}).sha384[0],
'picks the "strongest" available algorithm, by default'
)
t.done()
t.end()
})

test('checkStream', t => {
Expand All @@ -142,26 +142,26 @@ test('checkStream', t => {
let streamEnded
const stream = fileStream().on('end', () => { streamEnded = true })
return ssri.checkStream(stream, sri).then(res => {
t.deepEqual(res, meta, 'Stream data successfully verified')
t.same(res, meta, 'Stream data successfully verified')
t.ok(streamEnded, 'source stream ended')
return ssri.checkStream(
fileStream(),
`sha512-${hash(TEST_DATA, 'sha512')}`
)
}).then(res => {
t.deepEqual(res, meta, 'Accepts string SRI')
t.same(res, meta, 'Accepts string SRI')
return ssri.checkStream(fileStream(), {
algorithm: 'sha512',
digest: hash(TEST_DATA, 'sha512')
})
}).then(res => {
t.deepEqual(res, meta, 'Accepts Hash-like SRI')
t.same(res, meta, 'Accepts Hash-like SRI')
return ssri.checkStream(
fileStream(),
`sha512-nope sha512-${hash(TEST_DATA, 'sha512')}`
)
}).then(res => {
t.deepEqual(
t.same(
res,
meta,
'succeeds if any of the hashes under the chosen algorithm match'
Expand Down Expand Up @@ -203,7 +203,7 @@ test('checkStream', t => {
}
})
}).then(res => {
t.deepEqual(
t.same(
res,
ssri.parse({
algorithm: 'sha1', digest: hash(TEST_DATA, 'sha1')
Expand All @@ -216,7 +216,7 @@ test('checkStream', t => {
`sha256-${hash(TEST_DATA, 'sha256')}`
].join(' '))
}).then(res => {
t.deepEqual(
t.same(
res,
ssri.parse({
algorithm: 'sha384', digest: hash(TEST_DATA, 'sha384')
Expand All @@ -231,7 +231,7 @@ test('checkStream', t => {
algorithms: ['sha256']
})
}).then(res => {
t.deepEqual(
t.same(
res,
ssri.parse({
algorithm: 'sha384', digest: hash(TEST_DATA, 'sha384')
Expand All @@ -246,7 +246,7 @@ test('checkStream', t => {
algorithms: ['sha512']
})
}).then(res => {
t.deepEqual(
t.same(
res,
ssri.parse({
algorithm: 'sha384', digest: hash(TEST_DATA, 'sha384')
Expand Down
4 changes: 2 additions & 2 deletions test/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test('works just like from', function (t) {
const integrityCreate = ssri.create().update('hi').digest()

t.ok(integrityCreate instanceof integrity.constructor, 'should be same Integrity that fromData returns')
t.equals(integrity + '', integrityCreate + '', 'should be the sam as fromData')
t.equal(integrity + '', integrityCreate + '', 'should be the sam as fromData')
t.end()
})

Expand Down Expand Up @@ -57,7 +57,7 @@ test('pass in an algo multiple times', t => {
test('can pass options', function (t) {
const integrity = ssri.create({ algorithms: ['sha256', 'sha384'] }).update('hi').digest()

t.equals(
t.equal(
integrity + '',
'sha256-j0NDRmSPa5bfid2pAcUXaxCm2Dlh3TwayItZstwyeqQ= ' +
'sha384-B5EAbfgShHckT1PQ/c4hDbgfVXV1EOJqzuNcGKa86qKNzbv9bcBBubTcextU439S',
Expand Down
4 changes: 2 additions & 2 deletions test/from.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test('fromHex', t => {
'sha512-3q2+7w==?a?b?c',
'options added to entry'
)
t.done()
t.end()
})

test('fromData', t => {
Expand Down Expand Up @@ -56,7 +56,7 @@ test('fromData', t => {
].join(' '),
'can add opts.options to each entry'
)
t.done()
t.end()
})

test('fromStream', t => {
Expand Down
14 changes: 7 additions & 7 deletions test/integrity-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ test('generates integrity', t => {
stream.on('integrity', i => { integrity = i })
stream.on('end', () => {
t.equal(collected, 'foo', 'stream output is complete')
t.deepEqual(integrity, TARGET, 'matching integrity emitted')
t.done()
t.same(integrity, TARGET, 'matching integrity emitted')
t.end()
})
stream.end()
})
Expand All @@ -28,8 +28,8 @@ test('optional algorithms option', t => {
let integrity
stream.on('integrity', i => { integrity = i })
stream.on('end', () => {
t.deepEqual(integrity, TARGET, 'matching integrity emitted')
t.done()
t.same(integrity, TARGET, 'matching integrity emitted')
t.end()
})
stream.end()
})
Expand All @@ -46,8 +46,8 @@ test('verification for correct data succeeds', t => {
stream.on('integrity', i => { integrity = i })
stream.on('end', () => {
t.equal(collected, 'foo', 'stream output is complete')
t.deepEqual(integrity, TARGET, 'matching integrity emitted')
t.done()
t.same(integrity, TARGET, 'matching integrity emitted')
t.end()
})
stream.end()
})
Expand All @@ -60,7 +60,7 @@ test('verification for wrong data fails', t => {
stream.on('data', () => {})
stream.on('error', err => {
t.equal(err.code, 'EINTEGRITY', 'errors with EINTEGRITY on mismatch')
t.done()
t.end()
})
stream.end()
})
26 changes: 13 additions & 13 deletions test/integrity.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('toString()', t => {
'sha1-eUN/Xt2hP5wGabl43XqQZt0gWfE=\nsha256-Qhx213Vjr6GRSEawEL0WTzlb00whAuXpngy5zxc8HYc=',
'accepts separator option'
)
t.done()
t.end()
})

test('toJSON()', t => {
Expand All @@ -38,7 +38,7 @@ test('toJSON()', t => {
'sha512-foo',
'hash objects should toJSON also'
)
t.done()
t.end()
})

test('concat()', t => {
Expand Down Expand Up @@ -80,34 +80,34 @@ test('concat()', t => {
'sha512-WrLorGiX4iEWOOOaJSiCrmDIamA47exH+Bz7tVwIPb4sCU8w4iNqGCqYuspMMeU5pgz/sU7koP5u8W3RCUojGw==',
'accepts strict mode option'
)
t.done()
t.end()
})

test('match()', t => {
const sri = ssri.parse('sha1-foo sha512-bar')
t.similar(sri.match('sha1-foo'), {
t.match(sri.match('sha1-foo'), {
algorithm: 'sha1',
digest: 'foo'
}, 'returns the matching hash')
t.similar(sri.match(ssri.parse('sha1-foo')), {
t.match(sri.match(ssri.parse('sha1-foo')), {
algorithm: 'sha1',
digest: 'foo'
}, 'accepts other Integrity objects')
t.similar(sri.match(ssri.parse('sha1-foo')), {
t.match(sri.match(ssri.parse('sha1-foo')), {
algorithm: 'sha1',
digest: 'foo'
}, 'accepts other Hash objects')
t.similar(sri.match({ digest: 'foo', algorithm: 'sha1' }), {
t.match(sri.match({ digest: 'foo', algorithm: 'sha1' }), {
algorithm: 'sha1',
digest: 'foo'
}, 'accepts Hash-like objects')
t.similar(sri.match('sha1-bar sha512-bar'), {
t.match(sri.match('sha1-bar sha512-bar'), {
algorithm: 'sha512',
digest: 'bar'
}, 'returns the strongest match')
t.notOk(sri.match('sha512-foo'), 'falsy when match fails')
t.notOk(sri.match('sha384-foo'), 'falsy when match fails')
t.done()
t.end()
})

test('pickAlgorithm()', t => {
Expand All @@ -125,7 +125,7 @@ test('pickAlgorithm()', t => {
'sha384',
'custom pickAlgorithm function accepted'
)
t.done()
t.end()
})

test('hexDigest()', t => {
Expand All @@ -137,7 +137,7 @@ test('hexDigest()', t => {
ssri.parse('sha512-bar', { single: true }).hexDigest(),
Buffer.from('bar', 'base64').toString('hex'),
'returned hex version of base64 digest')
t.done()
t.end()
})

test('isIntegrity and isHash', t => {
Expand All @@ -147,10 +147,10 @@ test('isIntegrity and isHash', t => {
sri.sha512[0].isHash,
'sri hash has !!.isHash'
)
t.done()
t.end()
})

test('semi-private', t => {
t.equal(ssri.Integrity, undefined, 'Integrity class is module-private.')
t.done()
t.end()
})

0 comments on commit ef0e765

Please sign in to comment.