Skip to content

Commit

Permalink
fix: return info on removed key #10
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Dec 8, 2017
1 parent 506e1d7 commit f49e753
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/keychain.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,12 @@ class Keychain {
return _error(callback, `Invalid key name '${name}'`)
}
const dsname = DsName(name)
self.store.has(dsname, (err, exists) => {
self._getKeyInfo(name, (err, keyinfo) => {
if (err) return _error(callback, err)
if (!exists) return _error(callback, `Key '${name}' does not exist'`)

self.store.delete(dsname, callback)
self.store.delete(dsname, (err) => {
if (err) return _error(callback, err)
callback(null, keyinfo)
})
})
}

Expand Down
5 changes: 4 additions & 1 deletion test/keychain.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,11 @@ module.exports = (datastore1, datastore2) => {
})

it('can remove a known key', (done) => {
ks.removeKey(renamedRsaKeyName, (err) => {
ks.removeKey(renamedRsaKeyName, (err, key) => {
expect(err).to.not.exist()
expect(key).to.exist()
expect(key).to.have.property('name', renamedRsaKeyName)
expect(key).to.have.property('id', rsaKeyInfo.id)
done()
})
})
Expand Down

0 comments on commit f49e753

Please sign in to comment.