If you attempt to store an empty keylist then delete the storage key
This commit is contained in:
parent
068d38d832
commit
37ce176d42
|
@ -97,8 +97,12 @@ LocalStore.prototype.storePrivate = function (keys) {
|
||||||
|
|
||||||
function storeKeys(storage, itemname, keys) {
|
function storeKeys(storage, itemname, keys) {
|
||||||
var armoredKeys = [];
|
var armoredKeys = [];
|
||||||
for (var i = 0; i < keys.length; i++) {
|
if (keys.length) {
|
||||||
armoredKeys.push(keys[i].armor());
|
for (var i = 0; i < keys.length; i++) {
|
||||||
|
armoredKeys.push(keys[i].armor());
|
||||||
|
}
|
||||||
|
storage.setItem(itemname, JSON.stringify(armoredKeys));
|
||||||
|
} else {
|
||||||
|
storage.removeItem(itemname);
|
||||||
}
|
}
|
||||||
storage.setItem(itemname, JSON.stringify(armoredKeys));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,6 +248,21 @@ describe("Keyring", function() {
|
||||||
expect(localstore3.loadPublic()).to.have.length(0);
|
expect(localstore3.loadPublic()).to.have.length(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('emptying keyring and storing removes keys', function() {
|
||||||
|
var key = openpgp.key.readArmored(pubkey).keys[0];
|
||||||
|
|
||||||
|
var localstore = new openpgp.Keyring.localstore('remove-prefix-');
|
||||||
|
|
||||||
|
localstore.storePublic([]);
|
||||||
|
expect(localstore.storage.getItem('remove-prefix-public-keys')).to.be.null;
|
||||||
|
|
||||||
|
localstore.storePublic([key]);
|
||||||
|
expect(localstore.storage.getItem('remove-prefix-public-keys')).to.be.not.null;
|
||||||
|
|
||||||
|
localstore.storePublic([]);
|
||||||
|
expect(localstore.storage.getItem('remove-prefix-public-keys')).to.be.null;
|
||||||
|
})
|
||||||
|
|
||||||
it('removeKeysForId() - unknown id', function() {
|
it('removeKeysForId() - unknown id', function() {
|
||||||
keyring.publicKeys.importKey(pubkey);
|
keyring.publicKeys.importKey(pubkey);
|
||||||
keyring.publicKeys.importKey(pubkey2);
|
keyring.publicKeys.importKey(pubkey2);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user