Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: verify public key exists in validator #21

Merged
merged 2 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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