2013-08-19 15:13:32 -04:00
|
|
|
define(function(require) {
|
|
|
|
'use strict';
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
var EmailDAO = require('js/dao/email-dao'),
|
|
|
|
KeychainDAO = require('js/dao/keychain-dao'),
|
2013-09-19 12:35:12 -04:00
|
|
|
ImapClient = require('imap-client'),
|
2014-02-06 05:55:24 -05:00
|
|
|
PgpMailer = require('pgpmailer'),
|
2014-02-25 11:29:12 -05:00
|
|
|
PgpBuilder = require('pgpbuilder'),
|
2013-10-11 21:19:01 -04:00
|
|
|
PGP = require('js/crypto/pgp'),
|
2013-12-03 13:21:50 -05:00
|
|
|
DeviceStorageDAO = require('js/dao/devicestorage-dao'),
|
2014-02-25 13:18:37 -05:00
|
|
|
mailreader = require('mailreader'),
|
2014-02-06 05:55:24 -05:00
|
|
|
str = require('js/app-config').string,
|
2013-08-19 15:13:32 -04:00
|
|
|
expect = chai.expect;
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
chai.Assertion.includeStack = true;
|
2013-08-19 15:13:32 -04:00
|
|
|
|
2013-12-04 06:06:27 -05:00
|
|
|
describe('Email DAO unit tests', function() {
|
2014-02-25 11:29:12 -05:00
|
|
|
var dao, keychainStub, imapClientStub, pgpMailerStub, pgpBuilderStub, pgpStub, devicestorageStub;
|
2013-08-28 08:12:39 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
var emailAddress, passphrase, asymKeySize, mockkeyId, dummyEncryptedMail,
|
2014-02-24 04:14:07 -05:00
|
|
|
dummyDecryptedMail, mockKeyPair, account, verificationMail, verificationUuid,
|
2014-01-08 10:04:18 -05:00
|
|
|
corruptedVerificationMail, corruptedVerificationUuid,
|
2013-12-03 14:24:12 -05:00
|
|
|
nonWhitelistedMail;
|
2013-08-19 15:13:32 -04:00
|
|
|
|
2013-12-09 13:21:52 -05:00
|
|
|
beforeEach(function(done) {
|
2013-12-03 13:21:50 -05:00
|
|
|
emailAddress = 'asdf@asdf.com';
|
|
|
|
passphrase = 'asdf';
|
|
|
|
asymKeySize = 2048;
|
|
|
|
mockkeyId = 1234;
|
|
|
|
dummyEncryptedMail = {
|
|
|
|
uid: 1234,
|
2013-08-28 08:12:39 -04:00
|
|
|
from: [{
|
2013-12-03 13:21:50 -05:00
|
|
|
address: 'asd@asd.de'
|
|
|
|
}],
|
2013-08-28 08:12:39 -04:00
|
|
|
to: [{
|
2013-12-03 13:21:50 -05:00
|
|
|
address: 'qwe@qwe.de'
|
|
|
|
}],
|
2014-02-27 09:06:35 -05:00
|
|
|
subject: 'qweasd',
|
2013-12-05 12:28:18 -05:00
|
|
|
body: '-----BEGIN PGP MESSAGE-----\nasd\n-----END PGP MESSAGE-----',
|
|
|
|
unread: false,
|
|
|
|
answered: false
|
2013-12-03 13:21:50 -05:00
|
|
|
};
|
2014-01-08 10:04:18 -05:00
|
|
|
verificationUuid = '9A858952-17EE-4273-9E74-D309EAFDFAFB';
|
2013-12-03 13:21:50 -05:00
|
|
|
verificationMail = {
|
2013-11-08 03:29:04 -05:00
|
|
|
from: [{
|
|
|
|
name: 'Whiteout Test',
|
|
|
|
address: 'whiteout.test@t-online.de'
|
|
|
|
}], // sender address
|
|
|
|
to: [{
|
|
|
|
address: 'safewithme.testuser@gmail.com'
|
|
|
|
}], // list of receivers
|
|
|
|
subject: "[whiteout] New public key uploaded", // Subject line
|
2013-12-03 13:21:50 -05:00
|
|
|
body: 'yadda yadda bla blabla foo bar https://keys.whiteout.io/verify/' + verificationUuid, // plaintext body
|
2014-02-27 09:06:35 -05:00
|
|
|
unread: false,
|
2013-12-05 12:28:18 -05:00
|
|
|
answered: false
|
2013-12-03 13:21:50 -05:00
|
|
|
};
|
2014-01-08 10:04:18 -05:00
|
|
|
corruptedVerificationUuid = 'OMFG_FUCKING_BASTARD_UUID_FROM_HELL!';
|
|
|
|
corruptedVerificationMail = {
|
|
|
|
from: [{
|
|
|
|
name: 'Whiteout Test',
|
|
|
|
address: 'whiteout.test@t-online.de'
|
|
|
|
}], // sender address
|
|
|
|
to: [{
|
|
|
|
address: 'safewithme.testuser@gmail.com'
|
|
|
|
}], // list of receivers
|
|
|
|
subject: "[whiteout] New public key uploaded", // Subject line
|
|
|
|
body: 'yadda yadda bla blabla foo bar https://keys.whiteout.io/verify/' + corruptedVerificationUuid, // plaintext body
|
2014-02-27 09:06:35 -05:00
|
|
|
unread: false,
|
2014-01-08 10:04:18 -05:00
|
|
|
answered: false
|
|
|
|
};
|
2013-12-03 13:21:50 -05:00
|
|
|
dummyDecryptedMail = {
|
2014-01-18 05:42:28 -05:00
|
|
|
uid: 1234,
|
|
|
|
from: [{
|
|
|
|
address: 'asd@asd.de'
|
|
|
|
}],
|
|
|
|
to: [{
|
|
|
|
address: 'qwe@qwe.de'
|
|
|
|
}],
|
|
|
|
subject: 'qweasd',
|
|
|
|
body: 'Content-Type: multipart/signed;\r\n boundary="Apple-Mail=_1D8756C0-F347-4D7A-A8DB-7869CBF14FD2";\r\n protocol="application/pgp-signature";\r\n micalg=pgp-sha512\r\n\r\n\r\n--Apple-Mail=_1D8756C0-F347-4D7A-A8DB-7869CBF14FD2\r\nContent-Type: multipart/mixed;\r\n boundary="Apple-Mail=_8ED7DC84-6AD9-4A08-8327-80B62D6BCBFA"\r\n\r\n\r\n--Apple-Mail=_8ED7DC84-6AD9-4A08-8327-80B62D6BCBFA\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/plain;\r\n charset=us-ascii\r\n\r\nasdasd \r\n--Apple-Mail=_8ED7DC84-6AD9-4A08-8327-80B62D6BCBFA\r\nContent-Disposition: attachment;\r\n filename=dummy.txt\r\nContent-Type: text/plain;\r\n name="dummy.txt"\r\nContent-Transfer-Encoding: 7bit\r\n\r\noaudbcoaurbvosuabvlasdjbfalwubjvawvb\r\n--Apple-Mail=_8ED7DC84-6AD9-4A08-8327-80B62D6BCBFA--\r\n\r\n--Apple-Mail=_1D8756C0-F347-4D7A-A8DB-7869CBF14FD2\r\nContent-Transfer-Encoding: 7bit\r\nContent-Disposition: attachment;\r\n filename=signature.asc\r\nContent-Type: application/pgp-signature;\r\n name=signature.asc\r\nContent-Description: Message signed with OpenPGP using GPGMail\r\n\r\n-----BEGIN PGP SIGNATURE-----\r\nComment: GPGTools - https://gpgtools.org\r\n\r\niQEcBAEBCgAGBQJS2kO1AAoJEDzmUwH7XO/cP+YH/2PSBxX1ZZd83Uf9qBGDY807\r\niHOdgPFXm64YjSnohO7XsPcnmihqP1ipS2aaCXFC3/Vgb9nc4isQFS+i1VdPwfuR\r\n1Pd2l3dC4/nD4xO9h/W6JW7Yd24NS5TJD5cA7LYwQ8LF+rOzByMatiTMmecAUCe8\r\nEEalEjuogojk4IacA8dg/bfLqQu9E+0GYUJBcI97dx/0jZ0qMOxbWOQLsJ3DnUnV\r\nOad7pAIbHEO6T0EBsH7TyTj4RRHkP6SKE0mm6ZYUC7KCk2Z3MtkASTxUrnqW5qZ5\r\noaXUO9GEc8KZcmbCdhZY2Y5h+dmucaO0jpbeSKkvtYyD4KZrSvt7NTb/0dSLh4Y=\r\n=G8km\r\n-----END PGP SIGNATURE-----\r\n\r\n--Apple-Mail=_1D8756C0-F347-4D7A-A8DB-7869CBF14FD2--\r\n',
|
|
|
|
unread: false,
|
|
|
|
answered: false,
|
2013-12-03 13:21:50 -05:00
|
|
|
};
|
2013-12-03 14:24:12 -05:00
|
|
|
nonWhitelistedMail = {
|
|
|
|
uid: 1234,
|
|
|
|
from: [{
|
|
|
|
address: 'asd@asd.de'
|
|
|
|
}],
|
|
|
|
to: [{
|
|
|
|
address: 'qwe@qwe.de'
|
|
|
|
}],
|
|
|
|
subject: 'qweasd',
|
|
|
|
body: 'asd'
|
|
|
|
};
|
2013-12-03 13:21:50 -05:00
|
|
|
mockKeyPair = {
|
|
|
|
publicKey: {
|
|
|
|
_id: mockkeyId,
|
|
|
|
userId: emailAddress,
|
|
|
|
publicKey: 'publicpublicpublicpublic'
|
|
|
|
},
|
|
|
|
privateKey: {
|
|
|
|
_id: mockkeyId,
|
|
|
|
userId: emailAddress,
|
|
|
|
encryptedKey: 'privateprivateprivateprivate'
|
|
|
|
}
|
2013-08-28 08:12:39 -04:00
|
|
|
};
|
2013-08-20 07:30:35 -04:00
|
|
|
account = {
|
2013-12-03 13:21:50 -05:00
|
|
|
emailAddress: emailAddress,
|
|
|
|
asymKeySize: asymKeySize,
|
|
|
|
busy: false
|
2013-08-20 07:30:35 -04:00
|
|
|
};
|
2013-08-19 15:13:32 -04:00
|
|
|
|
|
|
|
keychainStub = sinon.createStubInstance(KeychainDAO);
|
|
|
|
imapClientStub = sinon.createStubInstance(ImapClient);
|
2014-02-06 05:55:24 -05:00
|
|
|
pgpMailerStub = sinon.createStubInstance(PgpMailer);
|
2014-02-25 11:29:12 -05:00
|
|
|
pgpBuilderStub = sinon.createStubInstance(PgpBuilder);
|
2013-10-11 21:19:01 -04:00
|
|
|
pgpStub = sinon.createStubInstance(PGP);
|
2013-09-26 07:26:57 -04:00
|
|
|
devicestorageStub = sinon.createStubInstance(DeviceStorageDAO);
|
2013-08-19 15:13:32 -04:00
|
|
|
|
2014-02-25 13:18:37 -05:00
|
|
|
dao = new EmailDAO(keychainStub, pgpStub, devicestorageStub, pgpBuilderStub, mailreader);
|
2013-12-03 13:21:50 -05:00
|
|
|
dao._account = account;
|
|
|
|
|
|
|
|
expect(dao._keychain).to.equal(keychainStub);
|
|
|
|
expect(dao._crypto).to.equal(pgpStub);
|
|
|
|
expect(dao._devicestorage).to.equal(devicestorageStub);
|
2013-12-09 13:21:52 -05:00
|
|
|
|
|
|
|
// connect
|
|
|
|
expect(dao._imapClient).to.not.exist;
|
|
|
|
expect(dao._smtpClient).to.not.exist;
|
|
|
|
expect(dao._account.online).to.be.undefined;
|
|
|
|
dao._account.folders = [];
|
|
|
|
imapClientStub.login.yields();
|
|
|
|
|
|
|
|
dao.onConnect({
|
|
|
|
imapClient: imapClientStub,
|
2014-02-06 05:55:24 -05:00
|
|
|
pgpMailer: pgpMailerStub
|
2013-12-09 13:21:52 -05:00
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(dao._account.online).to.be.true;
|
|
|
|
expect(dao._imapClient).to.equal(dao._imapClient);
|
|
|
|
expect(dao._smtpClient).to.equal(dao._smtpClient);
|
|
|
|
done();
|
|
|
|
});
|
2013-08-19 15:13:32 -04:00
|
|
|
});
|
|
|
|
|
2013-12-09 13:21:52 -05:00
|
|
|
afterEach(function(done) {
|
|
|
|
dao.onDisconnect(null, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(dao._account.online).to.be.false;
|
|
|
|
expect(dao._imapClient).to.not.exist;
|
|
|
|
expect(dao._smtpClient).to.not.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-08-19 15:13:32 -04:00
|
|
|
|
2013-12-04 06:06:27 -05:00
|
|
|
describe('push', function() {
|
|
|
|
it('should work', function(done) {
|
|
|
|
var o = {};
|
|
|
|
|
|
|
|
dao.onIncomingMessage = function(obj) {
|
|
|
|
expect(obj).to.equal(o);
|
|
|
|
done();
|
|
|
|
};
|
2013-12-05 12:28:18 -05:00
|
|
|
|
2013-12-04 06:06:27 -05:00
|
|
|
dao._imapClient.onIncomingMessage(o);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-08-19 15:13:32 -04:00
|
|
|
describe('init', function() {
|
2013-10-21 07:10:42 -04:00
|
|
|
beforeEach(function() {
|
2013-12-03 13:21:50 -05:00
|
|
|
delete dao._account;
|
2013-10-21 07:10:42 -04:00
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should init', function(done) {
|
2013-12-09 13:21:52 -05:00
|
|
|
var listFolderStub, folders;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2013-12-06 11:47:38 -05:00
|
|
|
folders = [{}, {}];
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
// initKeychain
|
|
|
|
devicestorageStub.init.withArgs(emailAddress).yields();
|
|
|
|
keychainStub.getUserKeyPair.yields(null, mockKeyPair);
|
|
|
|
|
|
|
|
// initFolders
|
|
|
|
listFolderStub = sinon.stub(dao, '_imapListFolders');
|
|
|
|
listFolderStub.yields(null, folders);
|
|
|
|
|
|
|
|
dao.init({
|
|
|
|
account: account
|
|
|
|
}, function(err, keyPair) {
|
|
|
|
expect(err).to.not.exist;
|
2013-12-09 13:21:52 -05:00
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.online).to.be.false;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(keyPair).to.equal(mockKeyPair);
|
|
|
|
|
|
|
|
expect(dao._account).to.equal(account);
|
|
|
|
expect(dao._account.folders).to.equal(folders);
|
|
|
|
expect(devicestorageStub.init.calledOnce).to.be.true;
|
|
|
|
expect(keychainStub.getUserKeyPair.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
expect(listFolderStub.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-10 17:05:17 -05:00
|
|
|
it('should not fail when offline', function(done) {
|
|
|
|
var listFolderStub;
|
|
|
|
|
|
|
|
// initKeychain
|
|
|
|
devicestorageStub.init.withArgs(emailAddress).yields();
|
|
|
|
keychainStub.getUserKeyPair.yields(null, mockKeyPair);
|
|
|
|
|
|
|
|
// initFolders
|
|
|
|
listFolderStub = sinon.stub(dao, '_imapListFolders');
|
2014-01-08 10:04:18 -05:00
|
|
|
listFolderStub.yields({
|
|
|
|
code: 42
|
|
|
|
});
|
2013-12-10 17:05:17 -05:00
|
|
|
|
|
|
|
dao.init({
|
|
|
|
account: account
|
|
|
|
}, function(err, keyPair) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.online).to.be.false;
|
|
|
|
expect(keyPair).to.equal(mockKeyPair);
|
|
|
|
|
|
|
|
expect(dao._account).to.equal(account);
|
|
|
|
expect(dao._account.folders).to.equal(undefined);
|
|
|
|
expect(devicestorageStub.init.calledOnce).to.be.true;
|
|
|
|
expect(keychainStub.getUserKeyPair.calledOnce).to.be.true;
|
|
|
|
expect(listFolderStub.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should fail due to error while listing folders', function(done) {
|
2013-12-09 13:21:52 -05:00
|
|
|
var listFolderStub;
|
2013-08-19 15:13:32 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
// initKeychain
|
|
|
|
devicestorageStub.init.withArgs(emailAddress).yields();
|
|
|
|
keychainStub.getUserKeyPair.yields(null, mockKeyPair);
|
|
|
|
|
|
|
|
// initFolders
|
|
|
|
listFolderStub = sinon.stub(dao, '_imapListFolders');
|
|
|
|
listFolderStub.yields({});
|
|
|
|
|
|
|
|
dao.init({
|
|
|
|
account: account
|
|
|
|
}, function(err, keyPair) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(keyPair).to.not.exist;
|
|
|
|
|
|
|
|
expect(dao._account).to.equal(account);
|
2013-09-26 07:26:57 -04:00
|
|
|
expect(devicestorageStub.init.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(keychainStub.getUserKeyPair.calledOnce).to.be.true;
|
|
|
|
expect(listFolderStub.calledOnce).to.be.true;
|
|
|
|
|
2013-08-19 15:13:32 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-09 13:21:52 -05:00
|
|
|
it('should fail due to error in getUserKeyPair', function(done) {
|
|
|
|
devicestorageStub.init.yields();
|
|
|
|
keychainStub.getUserKeyPair.yields({});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.init({
|
|
|
|
account: account
|
|
|
|
}, function(err, keyPair) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(keyPair).to.not.exist;
|
2013-10-21 07:10:42 -04:00
|
|
|
|
|
|
|
expect(devicestorageStub.init.calledOnce).to.be.true;
|
|
|
|
|
2013-12-09 13:21:52 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onConnect', function() {
|
2014-02-27 11:42:10 -05:00
|
|
|
var imapLoginStub, imapListFoldersStub;
|
2013-12-09 13:21:52 -05:00
|
|
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
// imap login
|
|
|
|
imapLoginStub = sinon.stub(dao, '_imapLogin');
|
|
|
|
imapListFoldersStub = sinon.stub(dao, '_imapListFolders');
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2013-12-09 13:21:52 -05:00
|
|
|
dao.onDisconnect(null, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(dao._imapClient).to.not.exist;
|
|
|
|
expect(dao._smtpClient).to.not.exist;
|
|
|
|
expect(dao._account.online).to.be.false;
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-09 13:21:52 -05:00
|
|
|
afterEach(function() {
|
|
|
|
imapLoginStub.restore();
|
|
|
|
imapListFoldersStub.restore();
|
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2013-12-09 13:21:52 -05:00
|
|
|
it('should fail due to error in imap login', function(done) {
|
|
|
|
imapLoginStub.yields({});
|
|
|
|
|
|
|
|
dao.onConnect({
|
|
|
|
imapClient: imapClientStub,
|
2014-02-06 05:55:24 -05:00
|
|
|
pgpMailer: pgpMailerStub
|
2013-12-09 13:21:52 -05:00
|
|
|
}, function(err) {
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(err).to.exist;
|
2013-12-09 13:21:52 -05:00
|
|
|
expect(imapLoginStub.calledOnce).to.be.true;
|
|
|
|
expect(dao._account.online).to.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2013-12-09 13:21:52 -05:00
|
|
|
it('should work when folder already initiated', function(done) {
|
|
|
|
dao._account.folders = [];
|
|
|
|
imapLoginStub.yields();
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2013-12-09 13:21:52 -05:00
|
|
|
dao.onConnect({
|
|
|
|
imapClient: imapClientStub,
|
2014-02-06 05:55:24 -05:00
|
|
|
pgpMailer: pgpMailerStub
|
2013-12-09 13:21:52 -05:00
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(dao._account.online).to.be.true;
|
|
|
|
expect(dao._imapClient).to.equal(dao._imapClient);
|
|
|
|
expect(dao._smtpClient).to.equal(dao._smtpClient);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work when folder not yet initiated', function(done) {
|
|
|
|
var folders = [];
|
|
|
|
imapLoginStub.yields();
|
|
|
|
imapListFoldersStub.yields(null, folders);
|
|
|
|
|
|
|
|
dao.onConnect({
|
|
|
|
imapClient: imapClientStub,
|
2014-02-06 05:55:24 -05:00
|
|
|
pgpMailer: pgpMailerStub
|
2013-12-09 13:21:52 -05:00
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(dao._account.online).to.be.true;
|
|
|
|
expect(dao._imapClient).to.equal(dao._imapClient);
|
|
|
|
expect(dao._smtpClient).to.equal(dao._smtpClient);
|
|
|
|
expect(dao._account.folders).to.deep.equal(folders);
|
2013-10-21 07:10:42 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('unlock', function() {
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should unlock', function(done) {
|
2014-02-24 04:14:07 -05:00
|
|
|
dao._pgpMailer = {
|
|
|
|
_pgpbuilder: {}
|
|
|
|
};
|
2013-08-19 15:13:32 -04:00
|
|
|
|
2014-02-24 04:14:07 -05:00
|
|
|
pgpStub.importKeys.withArgs({
|
|
|
|
passphrase: passphrase,
|
|
|
|
privateKeyArmored: mockKeyPair.privateKey.encryptedKey,
|
|
|
|
publicKeyArmored: mockKeyPair.publicKey.publicKey
|
|
|
|
}).yields();
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.unlock({
|
|
|
|
passphrase: passphrase,
|
|
|
|
keypair: mockKeyPair
|
|
|
|
}, function(err) {
|
2013-10-21 07:10:42 -04:00
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
2013-10-13 13:04:49 -04:00
|
|
|
expect(pgpStub.importKeys.calledOnce).to.be.true;
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2013-08-19 15:13:32 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-10-11 21:19:01 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should generate a keypair and unlock', function(done) {
|
2014-02-24 04:14:07 -05:00
|
|
|
var keypair;
|
|
|
|
|
|
|
|
dao._pgpMailer = {
|
|
|
|
_pgpbuilder: {}
|
|
|
|
};
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
keypair = {
|
|
|
|
keyId: 123,
|
|
|
|
publicKeyArmored: mockKeyPair.publicKey.publicKey,
|
|
|
|
privateKeyArmored: mockKeyPair.privateKey.encryptedKey
|
|
|
|
};
|
|
|
|
|
2014-02-24 04:14:07 -05:00
|
|
|
pgpStub.generateKeys.withArgs({
|
|
|
|
emailAddress: emailAddress,
|
|
|
|
keySize: asymKeySize,
|
|
|
|
passphrase: passphrase
|
|
|
|
}).yields(null, keypair);
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2014-02-24 04:14:07 -05:00
|
|
|
pgpStub.importKeys.withArgs({
|
|
|
|
passphrase: passphrase,
|
|
|
|
privateKeyArmored: mockKeyPair.privateKey.encryptedKey,
|
|
|
|
publicKeyArmored: mockKeyPair.publicKey.publicKey
|
|
|
|
}).yields();
|
2013-12-03 13:21:50 -05:00
|
|
|
keychainStub.putUserKeyPair.withArgs().yields();
|
|
|
|
|
|
|
|
dao.unlock({
|
|
|
|
passphrase: passphrase
|
|
|
|
}, function(err) {
|
2013-10-21 07:10:42 -04:00
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(pgpStub.generateKeys.calledOnce).to.be.true;
|
2013-10-21 07:10:42 -04:00
|
|
|
expect(pgpStub.importKeys.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(keychainStub.putUserKeyPair.calledOnce).to.be.true;
|
2013-10-21 07:10:42 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should fail when persisting fails', function(done) {
|
|
|
|
var keypair = {
|
|
|
|
keyId: 123,
|
|
|
|
publicKeyArmored: 'qwerty',
|
|
|
|
privateKeyArmored: 'asdfgh'
|
|
|
|
};
|
|
|
|
pgpStub.generateKeys.yields(null, keypair);
|
|
|
|
pgpStub.importKeys.withArgs().yields();
|
|
|
|
keychainStub.putUserKeyPair.yields({});
|
|
|
|
|
|
|
|
dao.unlock({
|
|
|
|
passphrase: passphrase
|
|
|
|
}, function(err) {
|
2013-10-21 07:10:42 -04:00
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(pgpStub.generateKeys.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(pgpStub.importKeys.calledOnce).to.be.true;
|
|
|
|
expect(keychainStub.putUserKeyPair.calledOnce).to.be.true;
|
2013-10-21 07:10:42 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should fail when import fails', function(done) {
|
|
|
|
var keypair = {
|
|
|
|
keyId: 123,
|
|
|
|
publicKeyArmored: 'qwerty',
|
|
|
|
privateKeyArmored: 'asdfgh'
|
|
|
|
};
|
|
|
|
|
|
|
|
pgpStub.generateKeys.withArgs().yields(null, keypair);
|
|
|
|
pgpStub.importKeys.withArgs().yields({});
|
2013-10-21 07:10:42 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
dao.unlock({
|
|
|
|
passphrase: passphrase
|
|
|
|
}, function(err) {
|
2013-10-21 07:10:42 -04:00
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(pgpStub.generateKeys.calledOnce).to.be.true;
|
|
|
|
expect(pgpStub.importKeys.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
done();
|
2013-10-11 21:19:01 -04:00
|
|
|
});
|
2013-10-21 07:10:42 -04:00
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should fail when generation fails', function(done) {
|
|
|
|
pgpStub.generateKeys.yields({});
|
2013-10-11 21:19:01 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
dao.unlock({
|
|
|
|
passphrase: passphrase
|
|
|
|
}, function(err) {
|
2013-10-21 07:10:42 -04:00
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(pgpStub.generateKeys.calledOnce).to.be.true;
|
|
|
|
|
2013-10-11 21:19:01 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-08-19 15:13:32 -04:00
|
|
|
});
|
|
|
|
|
2014-01-18 05:42:28 -05:00
|
|
|
describe('_imapParseMessageBlock', function() {
|
|
|
|
it('should parse a message', function(done) {
|
2014-02-25 13:18:37 -05:00
|
|
|
var parseRfc = sinon.stub(mailreader, 'parseRfc').withArgs({}).yields();
|
2014-01-18 05:42:28 -05:00
|
|
|
|
2014-02-25 13:18:37 -05:00
|
|
|
dao._imapParseMessageBlock({}, function() {
|
|
|
|
expect(parseRfc.calledOnce).to.be.true;
|
2014-01-18 05:42:28 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
describe('_imapLogin', function() {
|
2013-12-09 13:21:52 -05:00
|
|
|
it('should fail when disconnected', function(done) {
|
|
|
|
dao.onDisconnect(null, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
dao._imapLogin(function(err) {
|
|
|
|
expect(err.code).to.equal(42);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should work', function(done) {
|
|
|
|
imapClientStub.login.yields();
|
|
|
|
|
|
|
|
dao._imapLogin(function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-09-26 11:37:56 -04:00
|
|
|
it('should fail due to error in imap login', function(done) {
|
2013-12-03 13:21:50 -05:00
|
|
|
imapClientStub.login.yields({});
|
2013-09-26 11:37:56 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
dao._imapLogin(function(err) {
|
|
|
|
expect(err).to.exist;
|
2013-09-26 11:37:56 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
});
|
2013-09-26 11:37:56 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
describe('_imapLogout', function() {
|
2013-12-09 13:21:52 -05:00
|
|
|
it('should fail when disconnected', function(done) {
|
|
|
|
dao.onDisconnect(null, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
dao._imapLogout(function(err) {
|
|
|
|
expect(err.code).to.equal(42);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-09-26 11:37:56 -04:00
|
|
|
it('should work', function(done) {
|
2013-12-03 13:21:50 -05:00
|
|
|
imapClientStub.logout.yields();
|
2013-09-26 11:37:56 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
dao._imapLogout(function(err) {
|
2013-09-26 11:37:56 -04:00
|
|
|
expect(err).to.not.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should fail due to error in imap login', function(done) {
|
|
|
|
imapClientStub.logout.yields({});
|
|
|
|
|
|
|
|
dao._imapLogout(function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
done();
|
2013-08-20 07:30:35 -04:00
|
|
|
});
|
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
});
|
2013-08-20 07:30:35 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
describe('_imapListFolders', function() {
|
|
|
|
var dummyFolders = [{
|
|
|
|
type: 'Inbox',
|
|
|
|
path: 'INBOX'
|
|
|
|
}, {
|
|
|
|
type: 'Outbox',
|
|
|
|
path: 'OUTBOX'
|
|
|
|
}];
|
|
|
|
|
|
|
|
it('should list from storage', function(done) {
|
|
|
|
devicestorageStub.listItems.withArgs('folders').yields(null, [dummyFolders]);
|
|
|
|
|
|
|
|
dao._imapListFolders(function(err, folders) {
|
2013-08-20 07:30:35 -04:00
|
|
|
expect(err).to.not.exist;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(devicestorageStub.listItems.calledOnce).to.be.true;
|
|
|
|
expect(folders[0].type).to.equal('Inbox');
|
2013-08-20 07:30:35 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should not list from storage due to error', function(done) {
|
|
|
|
devicestorageStub.listItems.yields({});
|
2013-10-10 13:15:16 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
dao._imapListFolders(function(err, folders) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(folders).to.not.exist;
|
|
|
|
expect(devicestorageStub.listItems.calledOnce).to.be.true;
|
|
|
|
expect(imapClientStub.listWellKnownFolders.called).to.be.false;
|
|
|
|
done();
|
2013-10-10 13:15:16 -04:00
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
});
|
2013-10-10 13:15:16 -04:00
|
|
|
|
2013-12-09 13:21:52 -05:00
|
|
|
it('should fail when disconnected', function(done) {
|
|
|
|
devicestorageStub.listItems.yields(null, []);
|
|
|
|
|
|
|
|
dao.onDisconnect(null, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
dao._imapListFolders(function(err) {
|
|
|
|
expect(err.code).to.equal(42);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should list from imap', function(done) {
|
|
|
|
devicestorageStub.listItems.yields(null, []);
|
|
|
|
imapClientStub.listWellKnownFolders.yields(null, {
|
|
|
|
inbox: dummyFolders[0]
|
|
|
|
});
|
|
|
|
devicestorageStub.storeList.yields();
|
2013-10-10 13:15:16 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
dao._imapListFolders(function(err, folders) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(devicestorageStub.listItems.calledOnce).to.be.true;
|
|
|
|
expect(imapClientStub.listWellKnownFolders.calledOnce).to.be.true;
|
|
|
|
expect(devicestorageStub.storeList.calledOnce).to.be.true;
|
|
|
|
expect(folders[0].type).to.equal('Inbox');
|
|
|
|
done();
|
2013-09-20 12:44:14 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should not list from imap due to store error', function(done) {
|
|
|
|
devicestorageStub.listItems.yields(null, []);
|
|
|
|
imapClientStub.listWellKnownFolders.yields(null, {
|
|
|
|
inbox: dummyFolders[0]
|
2013-08-20 07:30:35 -04:00
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
devicestorageStub.storeList.yields({});
|
2013-08-20 13:48:49 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
dao._imapListFolders(function(err, folders) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(folders).to.not.exist;
|
|
|
|
expect(devicestorageStub.listItems.calledOnce).to.be.true;
|
|
|
|
expect(imapClientStub.listWellKnownFolders.calledOnce).to.be.true;
|
|
|
|
expect(devicestorageStub.storeList.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-08-20 13:48:49 -04:00
|
|
|
});
|
|
|
|
});
|
2013-08-21 07:43:19 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should not list from imap due to imap error', function(done) {
|
|
|
|
devicestorageStub.listItems.yields(null, []);
|
|
|
|
imapClientStub.listWellKnownFolders.yields({});
|
2013-08-21 10:07:59 -04:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
dao._imapListFolders(function(err, folders) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(folders).to.not.exist;
|
|
|
|
expect(devicestorageStub.listItems.calledOnce).to.be.true;
|
|
|
|
expect(imapClientStub.listWellKnownFolders.calledOnce).to.be.true;
|
|
|
|
expect(devicestorageStub.storeList.called).to.be.false;
|
|
|
|
done();
|
2013-11-08 03:29:04 -05:00
|
|
|
});
|
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
});
|
2013-11-08 03:29:04 -05:00
|
|
|
|
2013-12-12 07:14:49 -05:00
|
|
|
describe('_imapSearch', function() {
|
2013-12-09 13:21:52 -05:00
|
|
|
it('should fail when disconnected', function(done) {
|
|
|
|
dao.onDisconnect(null, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
2013-12-12 08:27:20 -05:00
|
|
|
dao._imapSearch({}, function(err) {
|
2013-12-09 13:21:52 -05:00
|
|
|
expect(err.code).to.equal(42);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should work', function(done) {
|
|
|
|
var path = 'FOLDAAAA';
|
2013-11-08 03:29:04 -05:00
|
|
|
|
2013-12-12 07:14:49 -05:00
|
|
|
imapClientStub.search.withArgs({
|
2014-02-27 09:06:35 -05:00
|
|
|
path: path
|
2013-12-03 13:21:50 -05:00
|
|
|
}).yields();
|
|
|
|
|
2013-12-12 07:14:49 -05:00
|
|
|
dao._imapSearch({
|
2013-12-03 13:21:50 -05:00
|
|
|
folder: path
|
|
|
|
}, done);
|
2013-09-26 07:26:57 -04:00
|
|
|
});
|
2013-12-12 07:14:49 -05:00
|
|
|
it('should work', function(done) {
|
|
|
|
var path = 'FOLDAAAA';
|
|
|
|
|
|
|
|
imapClientStub.search.withArgs({
|
|
|
|
path: path,
|
|
|
|
answered: true
|
|
|
|
}).yields();
|
|
|
|
|
|
|
|
dao._imapSearch({
|
|
|
|
folder: path,
|
|
|
|
answered: true
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
it('should work', function(done) {
|
|
|
|
var path = 'FOLDAAAA';
|
|
|
|
|
|
|
|
imapClientStub.search.withArgs({
|
|
|
|
path: path,
|
|
|
|
unread: true
|
|
|
|
}).yields();
|
|
|
|
|
|
|
|
dao._imapSearch({
|
|
|
|
folder: path,
|
|
|
|
unread: true
|
|
|
|
}, done);
|
|
|
|
});
|
2013-10-04 11:02:27 -04:00
|
|
|
});
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
describe('_imapDeleteMessage', function() {
|
2013-12-09 13:21:52 -05:00
|
|
|
it('should fail when disconnected', function(done) {
|
|
|
|
dao.onDisconnect(null, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
dao._imapDeleteMessage({}, function(err) {
|
|
|
|
expect(err.code).to.equal(42);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-10-04 11:02:27 -04:00
|
|
|
it('should work', function(done) {
|
2013-12-03 13:21:50 -05:00
|
|
|
var path = 'FOLDAAAA',
|
|
|
|
uid = 1337;
|
|
|
|
|
|
|
|
imapClientStub.deleteMessage.withArgs({
|
|
|
|
path: path,
|
|
|
|
uid: uid
|
|
|
|
}).yields();
|
|
|
|
|
|
|
|
dao._imapDeleteMessage({
|
|
|
|
folder: path,
|
|
|
|
uid: uid
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
2013-09-26 07:26:57 -04:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
describe('_imapListMessages', function() {
|
|
|
|
it('should work', function(done) {
|
|
|
|
var path = 'FOLDAAAA',
|
|
|
|
firstUid = 1337,
|
|
|
|
lastUid = 1339;
|
|
|
|
|
|
|
|
imapClientStub.listMessagesByUid.withArgs({
|
|
|
|
path: path,
|
|
|
|
firstUid: firstUid,
|
|
|
|
lastUid: lastUid
|
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
dao._imapListMessages({
|
|
|
|
folder: path,
|
|
|
|
firstUid: firstUid,
|
|
|
|
lastUid: lastUid
|
|
|
|
}, function(err, msgs) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(msgs).to.exist;
|
|
|
|
|
|
|
|
expect(imapClientStub.listMessagesByUid.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not work when listMessagesByUid fails', function(done) {
|
|
|
|
var path = 'FOLDAAAA',
|
|
|
|
firstUid = 1337,
|
|
|
|
lastUid = 1339;
|
|
|
|
|
|
|
|
imapClientStub.listMessagesByUid.yields({});
|
|
|
|
|
|
|
|
dao._imapListMessages({
|
|
|
|
folder: path,
|
|
|
|
firstUid: firstUid,
|
|
|
|
lastUid: lastUid
|
|
|
|
}, function(err, msgs) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(msgs).to.not.exist;
|
|
|
|
|
|
|
|
expect(imapClientStub.listMessagesByUid.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-09 13:21:52 -05:00
|
|
|
it('should fail when disconnected', function(done) {
|
|
|
|
dao.onDisconnect(null, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
dao._imapListMessages({}, function(err) {
|
2013-12-09 13:21:52 -05:00
|
|
|
expect(err.code).to.equal(42);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-02-14 11:29:16 -05:00
|
|
|
});
|
2013-12-09 13:21:52 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
describe('_imapStreamText', function() {
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should work', function(done) {
|
2014-02-14 11:29:16 -05:00
|
|
|
var path = 'FOLDAAAA';
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
imapClientStub.getBody.withArgs({
|
2013-12-03 13:21:50 -05:00
|
|
|
path: path,
|
2014-02-14 11:29:16 -05:00
|
|
|
message: {}
|
2014-01-14 10:32:36 -05:00
|
|
|
}).yields(null, {});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
dao._imapStreamText({
|
2013-12-03 13:21:50 -05:00
|
|
|
folder: path,
|
2014-02-14 11:29:16 -05:00
|
|
|
message: {}
|
2013-12-12 07:14:49 -05:00
|
|
|
}, function(err, msg) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(msg).to.exist;
|
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
expect(imapClientStub.getBody.calledOnce).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
it('should not work when getBody fails', function(done) {
|
2014-02-14 11:29:16 -05:00
|
|
|
var path = 'FOLDAAAA';
|
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
imapClientStub.getBody.yields({});
|
2013-12-12 07:14:49 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
dao._imapStreamText({
|
2013-12-12 07:14:49 -05:00
|
|
|
folder: path,
|
2014-02-14 11:29:16 -05:00
|
|
|
message: {}
|
2013-12-12 07:14:49 -05:00
|
|
|
}, function(err, msg) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(msg).to.not.exist;
|
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
expect(imapClientStub.getBody.calledOnce).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
});
|
2014-02-14 11:29:16 -05:00
|
|
|
|
|
|
|
it('should fail when disconnected', function(done) {
|
|
|
|
dao.onDisconnect(null, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
dao._imapStreamText({}, function(err) {
|
|
|
|
expect(err.code).to.equal(42);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('_localListMessages', function() {
|
2013-12-06 09:03:42 -05:00
|
|
|
it('should work without uid', function(done) {
|
2013-12-03 13:21:50 -05:00
|
|
|
var folder = 'FOLDAAAA';
|
|
|
|
devicestorageStub.listItems.withArgs('email_' + folder, 0, null).yields();
|
|
|
|
|
|
|
|
dao._localListMessages({
|
|
|
|
folder: folder
|
|
|
|
}, done);
|
|
|
|
});
|
2013-12-06 09:03:42 -05:00
|
|
|
|
|
|
|
it('should work with uid', function(done) {
|
|
|
|
var folder = 'FOLDAAAA',
|
|
|
|
uid = 123;
|
|
|
|
devicestorageStub.listItems.withArgs('email_' + folder + '_' + uid, 0, null).yields();
|
|
|
|
|
|
|
|
dao._localListMessages({
|
|
|
|
folder: folder,
|
|
|
|
uid: uid
|
|
|
|
}, done);
|
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('_localStoreMessages', function() {
|
|
|
|
it('should work', function(done) {
|
|
|
|
var folder = 'FOLDAAAA',
|
|
|
|
emails = [{}];
|
|
|
|
devicestorageStub.storeList.withArgs(emails, 'email_' + folder).yields();
|
|
|
|
|
|
|
|
dao._localStoreMessages({
|
|
|
|
folder: folder,
|
|
|
|
emails: emails
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('_localDeleteMessage', function() {
|
|
|
|
it('should work', function(done) {
|
|
|
|
var folder = 'FOLDAAAA',
|
|
|
|
uid = 1337;
|
|
|
|
devicestorageStub.removeList.withArgs('email_' + folder + '_' + uid).yields();
|
|
|
|
|
|
|
|
dao._localDeleteMessage({
|
|
|
|
folder: folder,
|
|
|
|
uid: uid
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail when uid is missing', function(done) {
|
|
|
|
var folder = 'FOLDAAAA';
|
|
|
|
|
|
|
|
dao._localDeleteMessage({
|
|
|
|
folder: folder
|
2013-10-04 11:02:27 -04:00
|
|
|
}, function(err) {
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(err).to.exist;
|
2013-10-04 11:02:27 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-08-20 07:30:35 -04:00
|
|
|
});
|
2013-10-04 11:02:27 -04:00
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
describe('getBody', function() {
|
2014-02-17 08:31:14 -05:00
|
|
|
it('should not do anything if the message already has content', function() {
|
2014-02-14 11:29:16 -05:00
|
|
|
var message = {
|
|
|
|
body: 'bender is great!'
|
|
|
|
};
|
2013-11-13 11:05:21 -05:00
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
dao.getBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message
|
|
|
|
});
|
2014-02-17 08:31:14 -05:00
|
|
|
|
|
|
|
// should do nothing
|
2014-02-14 11:29:16 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should read an unencrypted body from the device', function(done) {
|
|
|
|
var message, uid, folder, body, localListStub;
|
|
|
|
|
|
|
|
folder = 'asdasdasdasdasd';
|
|
|
|
body = 'bender is great! bender is great!';
|
|
|
|
uid = 1234;
|
|
|
|
message = {
|
|
|
|
uid: uid
|
|
|
|
};
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').withArgs({
|
2013-12-12 07:14:49 -05:00
|
|
|
folder: folder,
|
2014-02-14 11:29:16 -05:00
|
|
|
uid: uid
|
2014-02-17 08:31:14 -05:00
|
|
|
}).yieldsAsync(null, [{
|
2014-02-14 11:29:16 -05:00
|
|
|
body: body
|
|
|
|
}]);
|
2014-01-18 05:42:28 -05:00
|
|
|
|
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
dao.getBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message,
|
2013-12-03 13:21:50 -05:00
|
|
|
folder: folder
|
2014-02-14 11:29:16 -05:00
|
|
|
}, function(err, msg) {
|
2013-11-13 11:05:21 -05:00
|
|
|
expect(err).to.not.exist;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(msg).to.equal(message);
|
|
|
|
expect(msg.body).to.not.be.empty;
|
|
|
|
expect(msg.encrypted).to.be.false;
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(msg.loadingBody).to.be.false;
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
|
2013-11-13 11:05:21 -05:00
|
|
|
done();
|
|
|
|
});
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(message.loadingBody).to.be.true;
|
2013-11-13 11:05:21 -05:00
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should read an encrypted body from the device', function(done) {
|
|
|
|
var message, uid, folder, body, localListStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
folder = 'asdasdasdasdasd';
|
|
|
|
body = '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----';
|
|
|
|
uid = 1234;
|
|
|
|
message = {
|
|
|
|
uid: uid
|
|
|
|
};
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').withArgs({
|
|
|
|
folder: folder,
|
|
|
|
uid: uid
|
2014-02-17 08:31:14 -05:00
|
|
|
}).yieldsAsync(null, [{
|
2014-02-14 11:29:16 -05:00
|
|
|
body: body
|
|
|
|
}]);
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
dao.getBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message,
|
|
|
|
folder: folder
|
|
|
|
}, function(err, msg) {
|
|
|
|
expect(err).to.not.exist;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(msg).to.equal(message);
|
|
|
|
expect(msg.body).to.not.be.empty;
|
|
|
|
expect(msg.encrypted).to.be.true;
|
|
|
|
expect(msg.decrypted).to.be.false;
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(message.loadingBody).to.be.false;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
done();
|
2013-11-21 11:37:07 -05:00
|
|
|
});
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(message.loadingBody).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
});
|
2013-11-21 11:37:07 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should stream an unencrypted body from imap', function(done) {
|
|
|
|
var message, uid, folder, body, localListStub, localStoreStub, imapStreamStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
folder = 'asdasdasdasdasd';
|
|
|
|
body = 'bender is great! bender is great!';
|
|
|
|
uid = 1234;
|
|
|
|
message = {
|
|
|
|
uid: uid
|
|
|
|
};
|
2013-12-06 11:47:38 -05:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').withArgs({
|
|
|
|
folder: folder,
|
2014-02-14 11:29:16 -05:00
|
|
|
uid: uid
|
2014-02-24 11:37:23 -05:00
|
|
|
}).yieldsAsync(null, [message]);
|
2013-12-12 07:14:49 -05:00
|
|
|
|
2014-02-24 12:19:12 -05:00
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages').withArgs({
|
|
|
|
folder: folder,
|
|
|
|
emails: [message]
|
|
|
|
}).yieldsAsync();
|
2013-12-12 07:14:49 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
imapStreamStub = sinon.stub(dao, '_imapStreamText', function(opts, cb) {
|
|
|
|
expect(opts).to.deep.equal({
|
|
|
|
folder: folder,
|
|
|
|
message: message
|
|
|
|
});
|
2014-01-18 05:42:28 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
message.body = body;
|
|
|
|
cb();
|
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
dao.getBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message,
|
2013-12-03 13:21:50 -05:00
|
|
|
folder: folder
|
2014-02-14 11:29:16 -05:00
|
|
|
}, function(err, msg) {
|
2013-11-21 11:37:07 -05:00
|
|
|
expect(err).to.not.exist;
|
2014-02-17 08:31:14 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(msg).to.equal(message);
|
|
|
|
expect(msg.body).to.not.be.empty;
|
|
|
|
expect(msg.encrypted).to.be.false;
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(msg.loadingBody).to.be.false;
|
|
|
|
|
2014-02-24 11:37:23 -05:00
|
|
|
expect(localListStub.calledTwice).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(imapStreamStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
done();
|
|
|
|
});
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(message.loadingBody).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should stream an encrypted body from imap', function(done) {
|
|
|
|
var message, uid, folder, body, localListStub, localStoreStub, imapStreamStub;
|
|
|
|
|
|
|
|
folder = 'asdasdasdasdasd';
|
|
|
|
body = '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----';
|
|
|
|
uid = 1234;
|
|
|
|
message = {
|
|
|
|
uid: uid
|
|
|
|
};
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').withArgs({
|
|
|
|
folder: folder,
|
|
|
|
uid: uid
|
2014-02-24 11:37:23 -05:00
|
|
|
}).yieldsAsync(null, [message]);
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2014-02-24 12:19:12 -05:00
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages').withArgs({
|
|
|
|
folder: folder,
|
|
|
|
emails: [message]
|
|
|
|
}).yieldsAsync();
|
2014-02-14 11:29:16 -05:00
|
|
|
|
|
|
|
imapStreamStub = sinon.stub(dao, '_imapStreamText', function(opts, cb) {
|
|
|
|
expect(opts).to.deep.equal({
|
|
|
|
folder: folder,
|
|
|
|
message: message
|
|
|
|
});
|
|
|
|
|
|
|
|
message.body = body;
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
dao.getBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message,
|
|
|
|
folder: folder
|
|
|
|
}, function(err, msg) {
|
|
|
|
expect(err).to.not.exist;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(msg).to.equal(message);
|
|
|
|
expect(msg.body).to.not.be.empty;
|
|
|
|
expect(msg.encrypted).to.be.true;
|
|
|
|
expect(msg.decrypted).to.be.false;
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(msg.loadingBody).to.be.false;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2014-02-24 11:37:23 -05:00
|
|
|
expect(localListStub.calledTwice).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(imapStreamStub.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2013-11-21 11:37:07 -05:00
|
|
|
done();
|
|
|
|
});
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(message.loadingBody).to.be.true;
|
2013-11-21 11:37:07 -05:00
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('fail to stream from imap due to error when persisting', function(done) {
|
|
|
|
var message, uid, folder, body, localListStub, localStoreStub, imapStreamStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
folder = 'asdasdasdasdasd';
|
2014-02-24 11:37:23 -05:00
|
|
|
body = 'THIS IS THE BODY';
|
2014-02-14 11:29:16 -05:00
|
|
|
uid = 1234;
|
|
|
|
message = {
|
|
|
|
uid: uid
|
|
|
|
};
|
|
|
|
|
2014-02-24 11:37:23 -05:00
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yieldsAsync(null, [message]);
|
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages').yieldsAsync({});
|
2014-02-14 11:29:16 -05:00
|
|
|
|
|
|
|
imapStreamStub = sinon.stub(dao, '_imapStreamText', function(opts, cb) {
|
|
|
|
message.body = body;
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
dao.getBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message,
|
|
|
|
folder: folder
|
|
|
|
}, function(err, msg) {
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(err).to.exist;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(msg).to.not.exist;
|
2014-02-24 11:37:23 -05:00
|
|
|
expect(localListStub.calledTwice).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(imapStreamStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
|
|
|
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(message.loadingBody).to.be.false;
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('fail to stream from imap due to stream error', function(done) {
|
|
|
|
var message, uid, folder, body, localListStub, localStoreStub, imapStreamStub;
|
|
|
|
|
|
|
|
folder = 'asdasdasdasdasd';
|
|
|
|
uid = 1234;
|
|
|
|
message = {
|
|
|
|
uid: uid
|
|
|
|
};
|
|
|
|
|
2014-02-24 11:37:23 -05:00
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [{}]);
|
2014-02-14 11:29:16 -05:00
|
|
|
|
|
|
|
imapStreamStub = sinon.stub(dao, '_imapStreamText', function(opts, cb) {
|
|
|
|
message.body = body;
|
|
|
|
cb({});
|
|
|
|
});
|
|
|
|
|
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages');
|
|
|
|
|
2014-02-20 09:42:51 -05:00
|
|
|
dao.getBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message,
|
|
|
|
folder: folder
|
|
|
|
}, function(err, msg) {
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(err).to.exist;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(msg).to.not.exist;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(imapStreamStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.called).to.be.false;
|
|
|
|
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(message.loadingBody).to.be.false;
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-02-14 11:29:16 -05:00
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-24 04:14:07 -05:00
|
|
|
describe('decryptBody', function() {
|
2014-02-17 08:31:14 -05:00
|
|
|
it('should not do anything when the message is not encrypted', function() {
|
2014-02-14 11:29:16 -05:00
|
|
|
var message = {
|
|
|
|
encrypted: false
|
|
|
|
};
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-24 04:14:07 -05:00
|
|
|
dao.decryptBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message
|
|
|
|
});
|
2014-02-17 08:31:14 -05:00
|
|
|
|
|
|
|
// should do nothing
|
2014-02-14 11:29:16 -05:00
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-17 08:31:14 -05:00
|
|
|
it('should not do anything when the message is already decrypted', function() {
|
2014-02-14 11:29:16 -05:00
|
|
|
var message = {
|
|
|
|
encrypted: true,
|
|
|
|
decrypted: true
|
|
|
|
};
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-24 04:14:07 -05:00
|
|
|
dao.decryptBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message
|
2013-11-21 11:37:07 -05:00
|
|
|
});
|
2014-02-17 08:31:14 -05:00
|
|
|
|
|
|
|
// should do nothing
|
2013-12-03 13:21:50 -05:00
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('decrypt a pgp/mime message', function(done) {
|
|
|
|
var message, parsedBody, mimeBody, parseStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
message = {
|
2014-02-20 09:42:51 -05:00
|
|
|
from: [{
|
|
|
|
address: 'asdasdasd'
|
|
|
|
}],
|
2014-02-14 11:29:16 -05:00
|
|
|
encrypted: true,
|
|
|
|
decrypted: false,
|
|
|
|
body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----'
|
|
|
|
};
|
2013-11-21 11:37:07 -05:00
|
|
|
|
2014-02-25 13:18:37 -05:00
|
|
|
mimeBody = 'Content-Type: asdasdasd';
|
2014-02-14 11:29:16 -05:00
|
|
|
parsedBody = 'body? yes.';
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-17 08:31:14 -05:00
|
|
|
keychainStub.getReceiverPublicKey.withArgs(message.from[0].address).yieldsAsync(null, mockKeyPair.publicKey);
|
|
|
|
pgpStub.decrypt.withArgs(message.body, mockKeyPair.publicKey.publicKey).yieldsAsync(null, mimeBody);
|
2014-02-20 09:42:51 -05:00
|
|
|
parseStub = sinon.stub(dao, '_imapParseMessageBlock', function(o, cb) {
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(o.message).to.equal(message);
|
2014-02-25 13:18:37 -05:00
|
|
|
expect(o.raw).to.equal(mimeBody);
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
o.message.body = parsedBody;
|
|
|
|
cb(null, o.message);
|
|
|
|
});
|
2013-11-21 11:37:07 -05:00
|
|
|
|
2014-02-24 04:14:07 -05:00
|
|
|
dao.decryptBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message
|
|
|
|
}, function(error, msg) {
|
|
|
|
expect(error).to.not.exist;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(msg).to.equal(message);
|
|
|
|
expect(msg.decrypted).to.be.true;
|
|
|
|
expect(msg.body).to.equal(parsedBody);
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(msg.decryptingBody).to.be.false;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(keychainStub.getReceiverPublicKey.calledOnce).to.be.true;
|
|
|
|
expect(pgpStub.decrypt.calledOnce).to.be.true;
|
|
|
|
expect(parseStub.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2014-02-17 08:31:14 -05:00
|
|
|
|
|
|
|
expect(message.decryptingBody).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('decrypt a pgp/inline message', function(done) {
|
|
|
|
var message, plaintextBody, parseStub;
|
|
|
|
|
|
|
|
message = {
|
2014-02-20 09:42:51 -05:00
|
|
|
from: [{
|
|
|
|
address: 'asdasdasd'
|
|
|
|
}],
|
2014-02-14 11:29:16 -05:00
|
|
|
encrypted: true,
|
|
|
|
decrypted: false,
|
|
|
|
body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----'
|
|
|
|
};
|
|
|
|
|
|
|
|
plaintextBody = 'body? yes.';
|
|
|
|
|
2014-02-17 08:31:14 -05:00
|
|
|
keychainStub.getReceiverPublicKey.withArgs(message.from[0].address).yieldsAsync(null, mockKeyPair.publicKey);
|
|
|
|
pgpStub.decrypt.withArgs(message.body, mockKeyPair.publicKey.publicKey).yieldsAsync(null, plaintextBody);
|
2014-02-14 11:29:16 -05:00
|
|
|
parseStub = sinon.stub(dao, '_imapParseMessageBlock');
|
|
|
|
|
2014-02-24 04:14:07 -05:00
|
|
|
dao.decryptBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message
|
|
|
|
}, function(error, msg) {
|
|
|
|
expect(error).to.not.exist;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(msg).to.equal(message);
|
|
|
|
expect(msg.decrypted).to.be.true;
|
|
|
|
expect(msg.body).to.equal(plaintextBody);
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(msg.decryptingBody).to.be.false;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(keychainStub.getReceiverPublicKey.calledOnce).to.be.true;
|
|
|
|
expect(pgpStub.decrypt.calledOnce).to.be.true;
|
|
|
|
expect(parseStub.called).to.be.false;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2013-11-21 11:37:07 -05:00
|
|
|
done();
|
|
|
|
});
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(message.decryptingBody).to.be.true;
|
2013-11-21 11:37:07 -05:00
|
|
|
});
|
2013-08-19 15:13:32 -04:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should fail during decryption message', function(done) {
|
|
|
|
var message, plaintextBody, parseStub, errMsg;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
message = {
|
2014-02-20 09:42:51 -05:00
|
|
|
from: [{
|
|
|
|
address: 'asdasdasd'
|
|
|
|
}],
|
2014-02-14 11:29:16 -05:00
|
|
|
encrypted: true,
|
|
|
|
decrypted: false,
|
|
|
|
body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----'
|
|
|
|
};
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
plaintextBody = 'body? yes.';
|
|
|
|
errMsg = 'yaddayadda';
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
keychainStub.getReceiverPublicKey.withArgs(message.from[0].address).yields(null, mockKeyPair.publicKey);
|
|
|
|
pgpStub.decrypt.yields({
|
|
|
|
errMsg: errMsg
|
|
|
|
});
|
|
|
|
parseStub = sinon.stub(dao, '_imapParseMessageBlock');
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-24 04:14:07 -05:00
|
|
|
dao.decryptBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message
|
|
|
|
}, function(error, msg) {
|
|
|
|
expect(error).to.not.exist;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(msg).to.equal(message);
|
|
|
|
expect(msg.decrypted).to.be.true;
|
|
|
|
expect(msg.body).to.equal(errMsg);
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(msg.decryptingBody).to.be.false;
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(keychainStub.getReceiverPublicKey.calledOnce).to.be.true;
|
|
|
|
expect(pgpStub.decrypt.calledOnce).to.be.true;
|
|
|
|
expect(parseStub.called).to.be.false;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should fail during key export', function(done) {
|
|
|
|
var message, parseStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
message = {
|
2014-02-20 09:42:51 -05:00
|
|
|
from: [{
|
|
|
|
address: 'asdasdasd'
|
|
|
|
}],
|
2014-02-14 11:29:16 -05:00
|
|
|
encrypted: true,
|
|
|
|
decrypted: false,
|
|
|
|
body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----'
|
|
|
|
};
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
keychainStub.getReceiverPublicKey.yields({});
|
|
|
|
parseStub = sinon.stub(dao, '_imapParseMessageBlock');
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-24 04:14:07 -05:00
|
|
|
dao.decryptBody({
|
2014-02-14 11:29:16 -05:00
|
|
|
message: message
|
|
|
|
}, function(error, msg) {
|
|
|
|
expect(error).to.exist;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(msg).to.not.exist;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(message.decrypted).to.be.false;
|
2014-02-17 08:31:14 -05:00
|
|
|
expect(message.decryptingBody).to.be.false;
|
2014-02-20 09:42:51 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(keychainStub.getReceiverPublicKey.calledOnce).to.be.true;
|
|
|
|
expect(pgpStub.decrypt.called).to.be.false;
|
|
|
|
expect(parseStub.called).to.be.false;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-02-14 11:29:16 -05:00
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
|
|
|
|
describe('sync', function() {
|
|
|
|
it('should initially fill from local', function(done) {
|
|
|
|
var folder, localListStub, invocations, imapSearchStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
2014-02-14 11:29:16 -05:00
|
|
|
path: folder
|
2013-12-03 13:21:50 -05:00
|
|
|
}];
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
2014-02-14 11:29:16 -05:00
|
|
|
}).yields(null, [dummyEncryptedMail.uid]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(dao._account.folders[0].messages.length).to.equal(1);
|
|
|
|
expect(dao._account.folders[0].messages[0].uid).to.equal(dummyEncryptedMail.uid);
|
|
|
|
expect(dao._account.folders[0].messages[0].body).to.not.exist;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should not work when busy', function(done) {
|
|
|
|
dao._account.busy = true;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sync({
|
2014-02-14 11:29:16 -05:00
|
|
|
folder: 'OOGA'
|
2013-12-03 13:21:50 -05:00
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
2014-02-14 11:29:16 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should not work without providing a folder', function(done) {
|
|
|
|
dao.sync({}, function(err) {
|
|
|
|
expect(err).to.exist;
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should not work when initial setup errors', function(done) {
|
|
|
|
var folder, localListStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
2014-02-14 11:29:16 -05:00
|
|
|
path: folder
|
2013-12-03 13:21:50 -05:00
|
|
|
}];
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields({});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should be up to date', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
2013-12-03 13:21:50 -05:00
|
|
|
folder: folder
|
2014-02-20 05:34:55 -05:00
|
|
|
}).yields(null, [dummyEncryptedMail.uid - 10, dummyEncryptedMail.uid]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(dao._account.folders[0]).to.not.be.empty;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should error while searching on imap', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [dummyEncryptedMail]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
2013-12-03 13:21:50 -05:00
|
|
|
folder: folder
|
2014-02-14 11:29:16 -05:00
|
|
|
}).yields({});
|
2014-01-18 05:42:28 -05:00
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(err).to.not.exist;
|
2014-01-18 05:42:28 -05:00
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(err).to.exist;
|
2014-01-18 05:42:28 -05:00
|
|
|
expect(dao._account.busy).to.be.false;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(dao._account.folders[0]).to.not.be.empty;
|
2014-01-18 05:42:28 -05:00
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(imapSearchStub.calledOnce).to.be.true;
|
2014-01-18 05:42:28 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should error while listing local messages', function(done) {
|
|
|
|
var folder, localListStub;
|
2014-01-18 05:42:28 -05:00
|
|
|
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
2014-02-14 11:29:16 -05:00
|
|
|
messages: [dummyDecryptedMail]
|
2014-02-07 03:23:38 -05:00
|
|
|
}];
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields({});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(err).to.exist;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should remove messages from the remote', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, localDeleteStub, imapDeleteStub;
|
2013-12-03 14:24:12 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [dummyEncryptedMail]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
2014-02-14 11:29:16 -05:00
|
|
|
}).yields(null, []);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
2014-02-14 11:29:16 -05:00
|
|
|
|
|
|
|
imapDeleteStub = sinon.stub(dao, '_imapDeleteMessage').yields();
|
|
|
|
localDeleteStub = sinon.stub(dao, '_localDeleteMessage').yields();
|
2013-12-03 14:24:12 -05:00
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(localDeleteStub.calledOnce).to.be.true;
|
|
|
|
expect(imapDeleteStub.calledOnce).to.be.true;
|
2013-12-03 14:24:12 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should error while removing messages from local', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, localDeleteStub, imapDeleteStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [dummyEncryptedMail]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
2014-02-14 11:29:16 -05:00
|
|
|
imapDeleteStub = sinon.stub(dao, '_imapDeleteMessage').yields();
|
|
|
|
localDeleteStub = sinon.stub(dao, '_localDeleteMessage').yields({});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(err).to.exist;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(localDeleteStub.calledOnce).to.be.true;
|
|
|
|
expect(imapDeleteStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.called).to.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while removing messages from the remote', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, localDeleteStub, imapDeleteStub;
|
|
|
|
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [dummyEncryptedMail]);
|
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapDeleteStub = sinon.stub(dao, '_imapDeleteMessage').yields({});
|
|
|
|
localDeleteStub = sinon.stub(dao, '_localDeleteMessage');
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(err).to.exist;
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(imapDeleteStub.calledOnce).to.be.true;
|
|
|
|
expect(localDeleteStub.called).to.be.false;
|
|
|
|
expect(imapSearchStub.called).to.be.false;
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should delete messages locally if not present on remote', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, localDeleteStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
2014-02-14 11:29:16 -05:00
|
|
|
messages: [dummyDecryptedMail]
|
2013-12-03 13:21:50 -05:00
|
|
|
}];
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
2014-02-14 11:29:16 -05:00
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
localDeleteStub = sinon.stub(dao, '_localDeleteMessage').withArgs({
|
|
|
|
folder: folder,
|
|
|
|
uid: dummyEncryptedMail.uid
|
|
|
|
}).yields();
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(err).to.not.exist;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(localDeleteStub.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should error while deleting locally if not present on remote', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, localDeleteStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
2014-02-14 11:29:16 -05:00
|
|
|
messages: [dummyDecryptedMail]
|
2013-12-03 13:21:50 -05:00
|
|
|
}];
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [dummyEncryptedMail]);
|
|
|
|
localDeleteStub = sinon.stub(dao, '_localDeleteMessage').yields({});
|
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch').withArgs({
|
2013-12-12 07:14:49 -05:00
|
|
|
folder: folder
|
2014-02-14 11:29:16 -05:00
|
|
|
}).yields(null, []);
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(dao._account.busy).to.be.false;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(dao._account.folders[0].messages).to.not.be.empty;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(imapSearchStub.calledOnce).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(localDeleteStub.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should fetch messages downstream from the remote', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, localStoreStub, imapListMessagesStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
delete dummyEncryptedMail.body;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, []);
|
|
|
|
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
2014-02-14 11:29:16 -05:00
|
|
|
}).yields(null, [dummyEncryptedMail.uid]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
imapListMessagesStub = sinon.stub(dao, '_imapListMessages');
|
|
|
|
imapListMessagesStub.withArgs({
|
2013-12-03 13:21:50 -05:00
|
|
|
folder: folder,
|
2014-02-14 11:29:16 -05:00
|
|
|
firstUid: dummyEncryptedMail.uid,
|
|
|
|
lastUid: dummyEncryptedMail.uid
|
|
|
|
}).yields(null, [dummyEncryptedMail]);
|
|
|
|
|
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages');
|
|
|
|
localStoreStub.withArgs({
|
2013-12-03 13:21:50 -05:00
|
|
|
folder: folder,
|
2014-02-14 11:29:16 -05:00
|
|
|
emails: [dummyEncryptedMail]
|
2013-12-03 13:21:50 -05:00
|
|
|
}).yields();
|
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(dao._account.folders[0].messages.length).to.equal(1);
|
|
|
|
expect(dao._account.folders[0].messages[0].uid).to.equal(dummyEncryptedMail.uid);
|
|
|
|
expect(dao._account.folders[0].messages[0].body).to.not.exist;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should error while storing messages from the remote locally', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, localStoreStub, imapListMessagesStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
delete dummyEncryptedMail.body;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').withArgs({
|
2013-12-12 07:14:49 -05:00
|
|
|
folder: folder
|
2014-02-14 11:29:16 -05:00
|
|
|
}).yields(null, []);
|
|
|
|
|
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.yields(null, [dummyEncryptedMail.uid]);
|
|
|
|
|
|
|
|
imapListMessagesStub = sinon.stub(dao, '_imapListMessages');
|
|
|
|
imapListMessagesStub.yields(null, [dummyEncryptedMail]);
|
2013-12-12 07:14:49 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages');
|
|
|
|
localStoreStub.yields({});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(dao._account.busy).to.be.false;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(dao._account.folders[0].messages.length).to.equal(0);
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(imapSearchStub.calledOnce).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-12 07:14:49 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should verify an authentication mail', function(done) {
|
2014-02-27 09:06:35 -05:00
|
|
|
var invocations, folder, localListStub, imapSearchStub, imapGetStub, imapListMessagesStub, imapDeleteStub, localStoreStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, []);
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
2014-02-27 09:06:35 -05:00
|
|
|
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [verificationMail.uid]);
|
2014-02-27 09:06:35 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
2014-02-27 09:06:35 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
2014-02-27 09:06:35 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
imapListMessagesStub = sinon.stub(dao, '_imapListMessages').yields(null, [verificationMail]);
|
2014-02-27 09:06:35 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
imapGetStub = sinon.stub(dao, '_imapStreamText').yields(null);
|
2014-02-27 09:06:35 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
keychainStub.verifyPublicKey.withArgs(verificationUuid).yields();
|
2014-02-27 09:06:35 -05:00
|
|
|
|
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages');
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
imapDeleteStub = sinon.stub(dao, '_imapDeleteMessage').withArgs({
|
|
|
|
folder: folder,
|
|
|
|
uid: verificationMail.uid
|
|
|
|
}).yields();
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
if (invocations === 0) {
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(imapGetStub.calledOnce).to.be.true;
|
|
|
|
expect(keychainStub.verifyPublicKey.calledOnce).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(imapDeleteStub.calledOnce).to.be.true;
|
2014-02-27 09:06:35 -05:00
|
|
|
expect(localStoreStub.calledOnce).to.be.false;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-12 07:14:49 -05:00
|
|
|
|
2014-02-27 09:06:35 -05:00
|
|
|
it('should not care abouta failed deletion of an authentication mail', function(done) {
|
|
|
|
var invocations, folder, localListStub, localStoreStub, imapSearchStub, imapGetStub, imapListMessagesStub, imapDeleteStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, []);
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [verificationMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
2014-02-14 11:29:16 -05:00
|
|
|
imapListMessagesStub = sinon.stub(dao, '_imapListMessages').yields(null, [verificationMail]);
|
|
|
|
imapGetStub = sinon.stub(dao, '_imapStreamText').yields(null);
|
|
|
|
keychainStub.verifyPublicKey.withArgs(verificationUuid).yields();
|
|
|
|
imapDeleteStub = sinon.stub(dao, '_imapDeleteMessage').yields({});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-27 09:06:35 -05:00
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages');
|
|
|
|
localStoreStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
emails: [verificationMail]
|
|
|
|
}).yields();
|
|
|
|
|
2014-01-08 10:04:18 -05:00
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2014-01-08 10:04:18 -05:00
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-27 09:06:35 -05:00
|
|
|
expect(err).to.not.exist;
|
2014-01-08 10:04:18 -05:00
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2014-02-27 09:06:35 -05:00
|
|
|
expect(localStoreStub.called).to.be.false;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
2014-01-08 10:04:18 -05:00
|
|
|
expect(imapGetStub.calledOnce).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(keychainStub.verifyPublicKey.calledOnce).to.be.true;
|
|
|
|
expect(imapDeleteStub.calledOnce).to.be.true;
|
2014-01-08 10:04:18 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should fail during verifying authentication', function(done) {
|
2014-02-27 09:06:35 -05:00
|
|
|
var invocations, folder, localListStub, imapSearchStub, localStoreStub, imapGetStub, imapListMessagesStub, imapDeleteStub;
|
2014-01-08 10:04:18 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, []);
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2014-01-08 10:04:18 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
2014-02-14 11:29:16 -05:00
|
|
|
}).yields(null, [verificationMail.uid]);
|
2014-01-08 10:04:18 -05:00
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
2014-02-14 11:29:16 -05:00
|
|
|
imapListMessagesStub = sinon.stub(dao, '_imapListMessages').yields(null, [verificationMail]);
|
|
|
|
imapGetStub = sinon.stub(dao, '_imapStreamText').yields(null);
|
|
|
|
keychainStub.verifyPublicKey.withArgs(verificationUuid).yields({
|
|
|
|
errMsg: 'fubar'
|
|
|
|
});
|
|
|
|
imapDeleteStub = sinon.stub(dao, '_imapDeleteMessage').yields({});
|
2014-01-08 10:04:18 -05:00
|
|
|
|
2014-02-27 09:06:35 -05:00
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages');
|
|
|
|
localStoreStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
emails: [verificationMail]
|
|
|
|
}).yields();
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(err).to.not.exist;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-27 09:06:35 -05:00
|
|
|
if (invocations === 1) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.not.exist;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(dao._account.busy).to.be.false;
|
2014-02-27 09:06:35 -05:00
|
|
|
expect(dao._account.folders[0].messages).to.not.be.empty;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2014-02-27 09:06:35 -05:00
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(imapGetStub.calledOnce).to.be.true;
|
2014-02-14 11:29:16 -05:00
|
|
|
expect(keychainStub.verifyPublicKey.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(imapDeleteStub.called).to.be.false;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-12 07:14:49 -05:00
|
|
|
|
2014-02-14 11:29:16 -05:00
|
|
|
it('should not bother about corrupted authentication mails', function(done) {
|
|
|
|
var invocations, folder, localListStub, imapSearchStub, imapGetStub, imapListMessagesStub, imapDeleteStub;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: []
|
|
|
|
}];
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, []);
|
2014-02-14 11:29:16 -05:00
|
|
|
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
2014-02-14 11:29:16 -05:00
|
|
|
}).yields(null, [corruptedVerificationMail.uid]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
2014-02-14 11:29:16 -05:00
|
|
|
imapListMessagesStub = sinon.stub(dao, '_imapListMessages').yields(null, [corruptedVerificationMail]);
|
|
|
|
imapGetStub = sinon.stub(dao, '_imapStreamText').yields(null);
|
|
|
|
keychainStub.verifyPublicKey.withArgs(corruptedVerificationUuid).yields({
|
|
|
|
errMsg: 'fubar'
|
|
|
|
});
|
|
|
|
imapDeleteStub = sinon.stub(dao, '_imapDeleteMessage').yields({});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0].messages).to.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(imapGetStub.calledOnce).to.be.true;
|
|
|
|
expect(keychainStub.verifyPublicKey.called).to.be.false;
|
|
|
|
expect(imapDeleteStub.called).to.be.false;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-05 12:28:18 -05:00
|
|
|
it('should sync tags from memory to imap and storage', function(done) {
|
2013-12-12 07:14:49 -05:00
|
|
|
var folder, localListStub, imapSearchStub, invocations,
|
2013-12-05 12:28:18 -05:00
|
|
|
markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
var inImap = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inImap.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [inStorage]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [inImap.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, [inImap.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
2013-12-05 13:10:30 -05:00
|
|
|
markStub = sinon.stub(dao, '_imapMark').withArgs({
|
2013-12-05 12:28:18 -05:00
|
|
|
folder: folder,
|
|
|
|
uid: dummyDecryptedMail.uid,
|
|
|
|
unread: dummyDecryptedMail.unread,
|
|
|
|
answered: dummyDecryptedMail.answered
|
|
|
|
}).yields();
|
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages').withArgs({
|
|
|
|
folder: folder,
|
2013-12-06 09:03:42 -05:00
|
|
|
emails: [inStorage]
|
2013-12-03 13:21:50 -05:00
|
|
|
}).yields();
|
|
|
|
|
2013-12-05 12:28:18 -05:00
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
2013-12-03 13:21:50 -05:00
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
2013-12-05 12:28:18 -05:00
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
2013-12-05 12:28:18 -05:00
|
|
|
expect(markStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
|
|
|
|
2013-12-06 09:03:42 -05:00
|
|
|
expect(inStorage.unread).to.equal(dummyDecryptedMail.unread);
|
|
|
|
expect(inStorage.answered).to.equal(dummyDecryptedMail.answered);
|
|
|
|
|
2013-12-05 12:28:18 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-12 07:14:49 -05:00
|
|
|
it('should error while syncing unread tags from memory to storage', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations, markStub, localStoreStub;
|
2013-12-05 12:28:18 -05:00
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
var inImap = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inImap.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [inStorage]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
2013-12-05 13:10:30 -05:00
|
|
|
markStub = sinon.stub(dao, '_imapMark').yields();
|
2013-12-05 12:28:18 -05:00
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages').yields({});
|
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(markStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(imapSearchStub.called).to.be.false;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while syncing answered tags from memory to storage', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations, markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
var inImap = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inImap.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [inStorage]);
|
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
markStub = sinon.stub(dao, '_imapMark').yields();
|
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages').yields({});
|
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(markStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
|
|
|
expect(imapSearchStub.called).to.be.false;
|
2013-12-05 12:28:18 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while syncing tags from memory to imap', function(done) {
|
2013-12-12 07:14:49 -05:00
|
|
|
var folder, localListStub, imapSearchStub, invocations,
|
2013-12-05 12:28:18 -05:00
|
|
|
markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
var inImap = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inImap.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [inStorage]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
2013-12-05 13:10:30 -05:00
|
|
|
markStub = sinon.stub(dao, '_imapMark').yields({});
|
2013-12-05 12:28:18 -05:00
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages');
|
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(markStub.calledOnce).to.be.true;
|
|
|
|
expect(localStoreStub.called).to.be.false;
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(imapSearchStub.called).to.be.false;
|
2013-12-05 12:28:18 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should sync tags from imap to memory and storage', function(done) {
|
2013-12-12 07:14:49 -05:00
|
|
|
var folder, localListStub, imapSearchStub, invocations,
|
2013-12-05 12:28:18 -05:00
|
|
|
markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inStorage.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [inStorage]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
2013-12-05 13:10:30 -05:00
|
|
|
markStub = sinon.stub(dao, '_imapMark');
|
2013-12-06 09:03:42 -05:00
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages').yields();
|
2013-12-05 12:28:18 -05:00
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0]).to.not.be.empty;
|
2013-12-06 09:03:42 -05:00
|
|
|
expect(localListStub.calledTwice).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
2013-12-05 12:28:18 -05:00
|
|
|
expect(markStub.called).to.be.false;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
|
|
|
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(dummyDecryptedMail.unread).to.equal(false);
|
|
|
|
expect(inStorage.unread).to.equal(false);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while searching for unread tags on imap', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations, markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inStorage.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [inStorage]);
|
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields({});
|
|
|
|
markStub = sinon.stub(dao, '_imapMark');
|
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages');
|
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(markStub.called).to.be.false;
|
|
|
|
expect(imapSearchStub.calledTwice).to.be.true;
|
|
|
|
expect(localStoreStub.called).to.be.false;
|
|
|
|
|
|
|
|
expect(inStorage.unread).to.equal(true);
|
|
|
|
expect(dummyDecryptedMail.unread).to.equal(true); // the live object has not been touched!
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while searching for answered tags on imap', function(done) {
|
|
|
|
var folder, localListStub, imapSearchStub, invocations, markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inStorage.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [inStorage]);
|
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields({});
|
|
|
|
markStub = sinon.stub(dao, '_imapMark');
|
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages');
|
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0]).to.not.be.empty;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(markStub.called).to.be.false;
|
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
|
|
|
expect(localStoreStub.called).to.be.false;
|
|
|
|
|
|
|
|
expect(inStorage.unread).to.equal(true);
|
|
|
|
expect(dummyDecryptedMail.unread).to.equal(true); // the live object has not been touched!
|
2013-12-05 12:28:18 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error while syncing tags from imap to storage', function(done) {
|
2013-12-12 07:14:49 -05:00
|
|
|
var folder, localListStub, imapSearchStub, invocations,
|
2013-12-05 12:28:18 -05:00
|
|
|
markStub, localStoreStub;
|
|
|
|
|
|
|
|
invocations = 0;
|
|
|
|
folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder,
|
|
|
|
messages: [dummyDecryptedMail]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var inStorage = JSON.parse(JSON.stringify(dummyEncryptedMail));
|
|
|
|
dummyDecryptedMail.unread = inStorage.unread = true;
|
|
|
|
|
|
|
|
localListStub = sinon.stub(dao, '_localListMessages').yields(null, [inStorage]);
|
2013-12-12 07:14:49 -05:00
|
|
|
imapSearchStub = sinon.stub(dao, '_imapSearch');
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail.uid]);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
unread: true
|
|
|
|
}).yields(null, []);
|
|
|
|
imapSearchStub.withArgs({
|
|
|
|
folder: folder,
|
|
|
|
answered: true
|
|
|
|
}).yields(null, []);
|
2013-12-05 13:10:30 -05:00
|
|
|
markStub = sinon.stub(dao, '_imapMark');
|
2013-12-05 12:28:18 -05:00
|
|
|
localStoreStub = sinon.stub(dao, '_localStoreMessages').yields({});
|
|
|
|
|
|
|
|
dao.sync({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
if (invocations === 0) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(dao._account.busy).to.be.true;
|
|
|
|
invocations++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(dao._account.busy).to.be.false;
|
|
|
|
expect(dao._account.folders[0]).to.not.be.empty;
|
2013-12-06 09:03:42 -05:00
|
|
|
expect(localListStub.calledTwice).to.be.true;
|
2013-12-12 07:14:49 -05:00
|
|
|
expect(imapSearchStub.calledThrice).to.be.true;
|
2013-12-05 12:28:18 -05:00
|
|
|
expect(markStub.called).to.be.false;
|
|
|
|
expect(localStoreStub.calledOnce).to.be.true;
|
|
|
|
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-05 12:28:18 -05:00
|
|
|
describe('mark', function() {
|
2013-12-03 13:21:50 -05:00
|
|
|
it('should work', function(done) {
|
|
|
|
imapClientStub.updateFlags.withArgs({
|
|
|
|
path: 'asdf',
|
|
|
|
uid: 1,
|
2013-12-05 12:28:18 -05:00
|
|
|
unread: false,
|
|
|
|
answered: false
|
2013-12-03 13:21:50 -05:00
|
|
|
}).yields();
|
|
|
|
|
2013-12-05 13:10:30 -05:00
|
|
|
dao._imapMark({
|
2013-12-03 13:21:50 -05:00
|
|
|
folder: 'asdf',
|
2013-12-05 12:28:18 -05:00
|
|
|
uid: 1,
|
|
|
|
unread: false,
|
|
|
|
answered: false
|
2013-12-03 13:21:50 -05:00
|
|
|
}, function(err) {
|
|
|
|
expect(imapClientStub.updateFlags.calledOnce).to.be.true;
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('sendPlaintext', function() {
|
|
|
|
it('should work', function(done) {
|
2014-02-06 05:55:24 -05:00
|
|
|
pgpMailerStub.send.withArgs({
|
|
|
|
mail: dummyEncryptedMail
|
|
|
|
}).yields();
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sendPlaintext({
|
|
|
|
email: dummyEncryptedMail
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
2014-02-06 05:55:24 -05:00
|
|
|
expect(pgpMailerStub.send.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not work when pgpmailer fails', function(done) {
|
|
|
|
pgpMailerStub.send.yields({});
|
|
|
|
|
|
|
|
dao.sendPlaintext({
|
|
|
|
email: dummyEncryptedMail
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(pgpMailerStub.send.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('sendEncrypted', function() {
|
|
|
|
it('should work', function(done) {
|
2014-02-24 04:14:07 -05:00
|
|
|
var publicKeys = ["PUBLIC KEY"];
|
|
|
|
dummyDecryptedMail.publicKeysArmored = publicKeys;
|
2014-02-25 09:10:29 -05:00
|
|
|
|
2014-02-06 05:55:24 -05:00
|
|
|
pgpMailerStub.send.withArgs({
|
|
|
|
encrypt: true,
|
2014-02-28 08:45:10 -05:00
|
|
|
cleartextMessage: str.message + str.signature,
|
2014-02-06 05:55:24 -05:00
|
|
|
mail: dummyDecryptedMail,
|
2014-02-24 04:14:07 -05:00
|
|
|
publicKeysArmored: publicKeys
|
2014-02-06 05:55:24 -05:00
|
|
|
}).yields();
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sendEncrypted({
|
|
|
|
email: dummyDecryptedMail
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
2014-02-06 05:55:24 -05:00
|
|
|
expect(pgpMailerStub.send.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-02-06 05:55:24 -05:00
|
|
|
it('should not work when pgpmailer fails', function(done) {
|
2014-02-24 04:14:07 -05:00
|
|
|
var publicKeys = ["PUBLIC KEY"];
|
|
|
|
dummyDecryptedMail.publicKeysArmored = publicKeys;
|
2014-02-06 05:55:24 -05:00
|
|
|
pgpMailerStub.send.yields({});
|
2013-12-03 13:21:50 -05:00
|
|
|
|
|
|
|
dao.sendEncrypted({
|
|
|
|
email: dummyDecryptedMail
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
|
2014-02-06 05:55:24 -05:00
|
|
|
expect(pgpMailerStub.send.calledOnce).to.be.true;
|
2013-12-03 13:21:50 -05:00
|
|
|
|
2014-02-25 09:10:29 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-02-25 11:29:12 -05:00
|
|
|
|
|
|
|
describe('encrypt', function() {
|
|
|
|
it('should encrypt', function(done) {
|
|
|
|
pgpBuilderStub.encrypt.yields();
|
|
|
|
|
|
|
|
dao.encrypt({}, function() {
|
|
|
|
expect(pgpBuilderStub.encrypt.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-25 09:10:29 -05:00
|
|
|
describe('syncOutbox', function() {
|
|
|
|
it('should sync the outbox', function(done) {
|
|
|
|
var folder = 'FOLDAAAA';
|
|
|
|
dao._account.folders = [{
|
|
|
|
type: 'Folder',
|
|
|
|
path: folder
|
|
|
|
}];
|
|
|
|
|
|
|
|
var localListStub = sinon.stub(dao, '_localListMessages').withArgs({
|
|
|
|
folder: folder
|
|
|
|
}).yields(null, [dummyEncryptedMail]);
|
|
|
|
|
|
|
|
dao.syncOutbox({
|
|
|
|
folder: folder
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(localListStub.calledOnce).to.be.true;
|
|
|
|
expect(dao._account.folders[0].messages.length).to.equal(1);
|
|
|
|
|
2014-02-06 05:55:24 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-12-03 13:21:50 -05:00
|
|
|
});
|
2013-08-19 15:13:32 -04:00
|
|
|
});
|