Skip to content

Commit

Permalink
fix: verify public key exists in validator (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun authored and vasco-santos committed Apr 3, 2019
1 parent 5750dd0 commit 602e27f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ const extractPublicKey = (peerId, entry, callback) => {
}
return callback(null, pubKey)
}
callback(null, peerId.pubKey)

if (peerId.pubKey) {
callback(null, peerId.pubKey)
} else {
callback(Object.assign(new Error('no public key is available'), { code: ERRORS.ERR_UNDEFINED_PARAMETER }))
}
}

// rawStdEncoding with RFC4648
Expand Down
19 changes: 19 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,25 @@ describe('ipns', function () {
})
})

it('validator with no valid public key should error', (done) => {
const sequence = 0
const validity = 1000000

ipns.create(rsa, cid, sequence, validity, (err, entry) => {
expect(err).to.not.exist()

const marshalledData = ipns.marshal(entry)
const key = Buffer.from(`/ipns/${ipfsId.id}`)

ipns.validator.validate(marshalledData, key, (err, valid) => {
expect(err).to.exist()
expect(err.code).to.eql(ERRORS.ERR_UNDEFINED_PARAMETER)
expect(valid).to.not.exist()
done()
})
})
})

it('should use validator.validate to validate a record', (done) => {
const sequence = 0
const validity = 1000000
Expand Down

0 comments on commit 602e27f

Please sign in to comment.