From 1e2c85621bce63b6eaa8106d793673faa1686bde Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Wed, 23 Aug 2017 18:08:18 +0800 Subject: [PATCH] Remove primaryEmail parameter from public-key service. --- src/service/public-key.js | 14 ++------- test/integration/public-key-test.js | 49 +++++++++++++---------------- 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/src/service/public-key.js b/src/service/public-key.js index 87abfc5..6e3326f 100644 --- a/src/service/public-key.js +++ b/src/service/public-key.js @@ -62,11 +62,10 @@ class PublicKey { /** * Persist a new public key * @param {String} publicKeyArmored The ascii armored pgp key block - * @param {String} primaryEmail (optional) The key's primary email address * @param {Object} origin Required for links to the keyserver e.g. { protocol:'https', host:'openpgpkeys@example.com' } * @yield {undefined} */ - async put({publicKeyArmored, primaryEmail, origin}) { + async put({publicKeyArmored, origin}) { // lazily purge old/unverified keys on every key upload await this._purgeOldUnverified(); // parse key block @@ -79,7 +78,7 @@ class PublicKey { // store key in database await this._persisKey(key); // send mails to verify user ids (send only one if primary email is provided) - await this._sendVerifyEmail(key, primaryEmail, origin); + await this._sendVerifyEmail(key, origin); } /** @@ -121,17 +120,10 @@ class PublicKey { * Send verification emails to the public keys user ids for verification. * If a primary email address is provided only one email will be sent. * @param {Array} userIds user id documents containg the verification nonces - * @param {string} primaryEmail the public key's primary email address * @param {Object} origin the server's origin (required for email links) * @yield {undefined} */ - async _sendVerifyEmail({userIds, keyId, publicKeyArmored}, primaryEmail, origin) { - // check for primary email (send only one email) - const primaryUserId = userIds.find(uid => uid.email === primaryEmail); - if (primaryUserId) { - userIds = [primaryUserId]; - } - // send emails + async _sendVerifyEmail({userIds, keyId, publicKeyArmored}, origin) { for (const userId of userIds) { userId.publicKeyArmored = publicKeyArmored; // set key for encryption await this._email.send({template: tpl.verifyKey, userId, keyId, origin}); diff --git a/test/integration/public-key-test.js b/test/integration/public-key-test.js index 3fd42d3..0d76031 100644 --- a/test/integration/public-key-test.js +++ b/test/integration/public-key-test.js @@ -73,30 +73,23 @@ describe('Public Key Integration Tests', function() { }); describe('put', () => { - it('should persist key and send verification email with primaryEmail', async () => { - await publicKey.put({publicKeyArmored, primaryEmail, origin}); - expect(mailsSent.length).to.equal(1); - expect(mailsSent[0].to).to.equal(primaryEmail); - expect(mailsSent[0].params.keyId).to.exist; - expect(mailsSent[0].params.nonce).to.exist; - }); - it('should persist key and send verification email without primaryEmail', async () => { + it('should persist key and send verification email', async () => { await publicKey.put({publicKeyArmored, origin}); expect(mailsSent.length).to.equal(4); }); it('should work twice if not yet verified', async () => { - await publicKey.put({publicKeyArmored, primaryEmail, origin}); - expect(mailsSent.length).to.equal(1); - await publicKey.put({publicKeyArmored, primaryEmail, origin}); - expect(mailsSent.length).to.equal(2); + await publicKey.put({publicKeyArmored, origin}); + expect(mailsSent.length).to.equal(4); + await publicKey.put({publicKeyArmored, origin}); + expect(mailsSent.length).to.equal(8); }); it('should throw 304 if key already exists', async () => { - await publicKey.put({publicKeyArmored, primaryEmail, origin}); + await publicKey.put({publicKeyArmored, origin}); await publicKey.verify(mailsSent[0].params); try { - await publicKey.put({publicKeyArmored, primaryEmail, origin}); + await publicKey.put({publicKeyArmored, origin}); expect(false).to.be.true; } catch (e) { expect(e.status).to.equal(304); @@ -147,7 +140,7 @@ describe('Public Key Integration Tests', function() { describe('verify', () => { it('should update the document', async () => { - await publicKey.put({publicKeyArmored, primaryEmail, origin}); + await publicKey.put({publicKeyArmored, origin}); const emailParams = mailsSent[0].params; await publicKey.verify(emailParams); const gotten = await mongo.get({keyId: emailParams.keyId}, DB_TYPE); @@ -158,7 +151,7 @@ describe('Public Key Integration Tests', function() { }); it('should not find the document', async () => { - await publicKey.put({publicKeyArmored, primaryEmail, origin}); + await publicKey.put({publicKeyArmored, origin}); const emailParams = mailsSent[0].params; try { await publicKey.verify({keyId: emailParams.keyId, nonce: 'fake_nonce'}); @@ -174,10 +167,10 @@ describe('Public Key Integration Tests', function() { }); it('should not verify a second key for already verified user id of another key', async () => { - await publicKey.put({publicKeyArmored, primaryEmail: primaryEmail2, origin}); - expect(mailsSent.length).to.equal(1); - await publicKey.put({publicKeyArmored: publicKeyArmored2, primaryEmail: primaryEmail2, origin}); - expect(mailsSent.length).to.equal(2); + await publicKey.put({publicKeyArmored, origin}); + expect(mailsSent.length).to.equal(4); + await publicKey.put({publicKeyArmored: publicKeyArmored2, origin}); + expect(mailsSent.length).to.equal(5); await publicKey.verify(mailsSent[1].params); try { @@ -213,7 +206,7 @@ describe('Public Key Integration Tests', function() { describe('should find a verified key', () => { beforeEach(async () => { key = pgp.parseKey(publicKeyArmored); - await publicKey.put({publicKeyArmored, primaryEmail, origin}); + await publicKey.put({publicKeyArmored, origin}); await publicKey.verify(mailsSent[0].params); }); @@ -281,7 +274,7 @@ describe('Public Key Integration Tests', function() { let emailParams; beforeEach(async () => { - await publicKey.put({publicKeyArmored, primaryEmail, origin}); + await publicKey.put({publicKeyArmored, origin}); emailParams = mailsSent[0].params; }); @@ -337,24 +330,24 @@ describe('Public Key Integration Tests', function() { let keyId; beforeEach(async () => { - await publicKey.put({publicKeyArmored, primaryEmail, origin}); + await publicKey.put({publicKeyArmored, origin}); keyId = mailsSent[0].params.keyId; }); it('should work for verified key', async () => { await publicKey.verify(mailsSent[0].params); await publicKey.requestRemove({keyId, origin}); - expect(mailsSent.length).to.equal(5); + expect(mailsSent.length).to.equal(8); }); it('should work for unverified key', async () => { await publicKey.requestRemove({keyId, origin}); - expect(mailsSent.length).to.equal(5); + expect(mailsSent.length).to.equal(8); }); it('should work by email address', async () => { await publicKey.requestRemove({email: primaryEmail, origin}); - expect(mailsSent.length).to.equal(2); + expect(mailsSent.length).to.equal(5); }); it('should throw 404 for no key', async () => { @@ -372,13 +365,13 @@ describe('Public Key Integration Tests', function() { let keyId; beforeEach(async () => { - await publicKey.put({publicKeyArmored, primaryEmail, origin}); + await publicKey.put({publicKeyArmored, origin}); keyId = mailsSent[0].params.keyId; await publicKey.requestRemove({keyId, origin}); }); it('should remove key', async () => { - await publicKey.verifyRemove(mailsSent[1].params); + await publicKey.verifyRemove(mailsSent[4].params); const key = await mongo.get({keyId}, DB_TYPE); expect(key).to.not.exist; });