From 2f351985c44b08dd0704cfa2493685dc4b22fdb9 Mon Sep 17 00:00:00 2001 From: Sanjana Rajan Date: Mon, 19 Mar 2018 18:55:30 -0700 Subject: [PATCH] tests --- test/general/key.js | 17 +++++++++++++++++ test/general/openpgp.js | 14 ++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/test/general/key.js b/test/general/key.js index 1349b65e..425962a6 100644 --- a/test/general/key.js +++ b/test/general/key.js @@ -1076,6 +1076,23 @@ describe('Key', function() { }); }); + it('Generate key - setting date to the past', function() { + const past = new Date(0); + const opt = { + userIds: { name: 'Test User', email: 'text@example.com' }, + passphrase: 'secret', + unlocked: true, + date: past + }; + + return openpgp.generateKey(opt).then(function(newKey) { + expect(newKey.key).to.exist; + expect(+newKey.key.primaryKey.created).to.equal(+past); + expect(+newKey.key.subKeys[0].subKey.created).to.equal(+past); + expect(+newKey.key.subKeys[0].bindingSignatures[0].created).to.equal(+past); + }); + }) + it('Generate key - multi userid', function() { const userId1 = 'test '; const userId2 = 'test '; diff --git a/test/general/openpgp.js b/test/general/openpgp.js index 72f62492..2ff92576 100644 --- a/test/general/openpgp.js +++ b/test/general/openpgp.js @@ -483,10 +483,12 @@ describe('OpenPGP.js public api tests', function() { }); it('should have default params set', function() { + const now = new Date(); const opt = { userIds: { name: 'Test User', email: 'text@example.com' }, passphrase: 'secret', - unlocked: true + unlocked: true, + date: now }; return openpgp.generateKey(opt).then(function(newKey) { expect(keyGenStub.withArgs({ @@ -495,7 +497,8 @@ describe('OpenPGP.js public api tests', function() { numBits: 2048, unlocked: true, keyExpirationTime: 0, - curve: "" + curve: "", + date: now }).calledOnce).to.be.true; expect(newKey.key).to.exist; expect(newKey.privateKeyArmored).to.exist; @@ -504,14 +507,17 @@ describe('OpenPGP.js public api tests', function() { }); it('should work for no params', function() { - return openpgp.generateKey().then(function(newKey) { + const now = new Date(); + + return openpgp.generateKey({date: now}).then(function(newKey) { expect(keyGenStub.withArgs({ userIds: [], passphrase: undefined, numBits: 2048, unlocked: false, keyExpirationTime: 0, - curve: "" + curve: "", + date: now }).calledOnce).to.be.true; expect(newKey.key).to.exist; });