From 1c361cd4e15ee5156e8e959fd44c65801f8fcd31 Mon Sep 17 00:00:00 2001 From: Sanjana Rajan Date: Tue, 31 Jan 2017 14:16:34 -0800 Subject: [PATCH] add some reformatting key tests --- test/general/key.js | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/test/general/key.js b/test/general/key.js index 11e9a594..4ecaeec9 100644 --- a/test/general/key.js +++ b/test/general/key.js @@ -890,6 +890,47 @@ var pgp_desktop_priv = done(); }).catch(done); }); - + it('Reformat key without passphrase', function(done) { + var userId1 = 'test1 '; + var userId2 = 'test2 '; + var opt = {numBits: 512, userIds: userId1}; + if (openpgp.util.getWebCryptoAll()) { opt.numBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys + openpgp.generateKey(opt).then(function(key) { + key = key.key + expect(key.users.length).to.equal(1); + expect(key.users[0].userId.userid).to.equal(userId1); + expect(key.primaryKey.isDecrypted).to.be.true; + opt.privateKey = key; + opt.userIds = userId2; + openpgp.reformatKey(opt).then(function(newKey) { + newKey = newKey.key + expect(newKey.users.length).to.equal(1); + expect(newKey.users[0].userId.userid).to.equal(userId2); + expect(newKey.primaryKey.isDecrypted).to.be.true; + done(); + }).catch(done); + }).catch(done); + }); + it('Reformat and encrypt key', function(done) { + var userId1 = 'test1 '; + var userId2 = 'test2 '; + var opt = {numBits: 512, userIds: userId1}; + if (openpgp.util.getWebCryptoAll()) { opt.numBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys + openpgp.generateKey(opt).then(function(key) { + key = key.key + opt.privateKey = key; + opt.userIds = userId2; + opt.passphrase = '123'; + openpgp.reformatKey(opt).then(function(newKey) { + newKey = newKey.key + expect(newKey.users.length).to.equal(1); + expect(newKey.users[0].userId.userid).to.equal(userId2); + expect(newKey.primaryKey.isDecrypted).to.be.false; + newKey.decrypt('123'); + expect(newKey.primaryKey.isDecrypted).to.be.true; + done(); + }).catch(done); + }).catch(done); + }); });