From 9d3bc51fcf0b877f3edbda96c1e8a09b2dcd30e7 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Thu, 21 Nov 2013 17:09:47 +0100 Subject: [PATCH] bugfix in cas of channel change --- src/js/dao/email-dao.js | 8 ++++++++ test/new-unit/email-dao-test.js | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index eb85c75..86acbff 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -293,6 +293,14 @@ define(function(require) { return; } + if (!senderPubkey) { + // this should only happen if a mail from another channel is in the inbox + callback({ + errMsg: 'No public key for the sender' + }); + return; + } + // decrypt and verfiy signatures self._crypto.decrypt(email.body, senderPubkey.publicKey, function(err, decrypted) { if (err) { diff --git a/test/new-unit/email-dao-test.js b/test/new-unit/email-dao-test.js index f32265e..7251563 100644 --- a/test/new-unit/email-dao-test.js +++ b/test/new-unit/email-dao-test.js @@ -598,6 +598,24 @@ define(function(require) { }); describe('IMAP: list messages from local storage', function() { + it('should fail for empty public key', function(done) { + dummyMail.body = app.string.cryptPrefix + btoa('asdf') + app.string.cryptSuffix; + devicestorageStub.listItems.yields(null, [dummyMail]); + keychainStub.getReceiverPublicKey.yields(); + + emailDao.listMessages({ + folder: 'INBOX', + offset: 0, + num: 1 + }, function(err, emails) { + expect(err).to.exist; + expect(emails).to.not.exist; + expect(devicestorageStub.listItems.calledOnce).to.be.true; + expect(keychainStub.getReceiverPublicKey.calledOnce).to.be.true; + done(); + }); + }); + it('should work', function(done) { dummyMail.body = app.string.cryptPrefix + btoa('asdf') + app.string.cryptSuffix; devicestorageStub.listItems.yields(null, [dummyMail]);