mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-06-25 22:41:41 +00:00
fix: catch error when unmarshaling instead of crashing (#72)
This commit is contained in:
committed by
David Dias
parent
f91f2b6506
commit
156911e162
@ -12,6 +12,8 @@ const parallel = require('async/parallel')
|
||||
|
||||
const PeerId = require('../src')
|
||||
|
||||
const util = require('util')
|
||||
|
||||
const testId = require('./fixtures/sample-id')
|
||||
const testIdHex = testId.id
|
||||
const testIdBytes = mh.fromHexString(testId.id)
|
||||
@ -245,6 +247,24 @@ describe('PeerId', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('returns error via cb instead of crashing', () => {
|
||||
const garbage = [Buffer.from('00010203040506070809', 'hex'), {}, null, false, undefined, true, 1, 0, Buffer.from(''), 'aGVsbG93b3JsZA==', 'helloworld', '']
|
||||
|
||||
const fncs = ['createFromPubKey', 'createFromPrivKey', 'createFromJSON']
|
||||
|
||||
garbage.forEach(garbage => {
|
||||
fncs.forEach(fnc => {
|
||||
it(fnc + '(' + util.inspect(garbage) + ')', cb => {
|
||||
PeerId[fnc](garbage, (err, res) => {
|
||||
expect(err).to.exist()
|
||||
expect(res).to.not.exist()
|
||||
cb()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('throws on inconsistent data', () => {
|
||||
let k1
|
||||
let k2
|
||||
|
Reference in New Issue
Block a user