1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-12 04:05:13 -05:00
mail/test/integration/email-dao-test.js

430 lines
40 KiB
JavaScript
Raw Normal View History

define(function(require) {
'use strict';
2014-06-11 03:42:34 -04:00
var expect = chai.expect,
ImapClient = require('imap-client'),
BrowserCrow = require('browsercrow'),
BrowserSMTP = require('browsersmtp'),
SmtpClient = require('smtpclient'),
appController = require('js/app-controller'),
mailreader = require('mailreader'),
openpgp = require('openpgp'),
PgpMailer = require('pgpmailer');
describe('Email DAO integration tests', function() {
2014-06-11 03:42:34 -04:00
this.timeout(100000);
chai.Assertion.includeStack = true;
2014-06-11 03:42:34 -04:00
var emailDao, imapClient, imapMessages, imapFolders, imapServer, smtpServer, smtpClient, userStorage,
mockKeyPair;
2014-06-11 03:42:34 -04:00
var testAccount = {
user: 'safewithme.testuser@gmail.com',
pass: 'passphrase',
xoauth2: 'testtoken'
};
2014-06-11 03:42:34 -04:00
beforeEach(function(done) {
2014-06-11 03:42:34 -04:00
imapMessages = [{
raw: 'Message-id: <a>\r\nSubject: hello 1\r\n\r\nWorld 1!',
internaldate: '14-Sep-2013 21:22:28 -0300',
uid: 500
}, {
raw: 'Message-id: <b>\r\nSubject: hello 2\r\n\r\nWorld 2!',
flags: ['\\Seen'],
uid: 600
}, {
raw: 'Message-id: <c>\r\nSubject: hello 3\r\n\r\nWorld 3!'
}, {
raw: 'From: sender name <sender@example.com>\r\n' +
'To: Receiver name <receiver@example.com>\r\n' +
'Subject: hello 4\r\n' +
'Message-Id: <d>\r\n' +
'Date: Fri, 13 Sep 2013 15:01:00 +0300\r\n' +
'\r\n' +
'World 4!'
}, {
raw: 'Message-id: <e>\r\nSubject: hello 5\r\n\r\nWorld 5!'
}, {
raw: 'Message-id: <f>Subject: hello 6\r\n\r\nWorld 6!'
}, {
raw: 'Message-id: <g>\nFrom: safewithme.testuser@gmail.com\nTo: safewithme.testuser@gmail.com\nSubject: enigmail encrypted pgp/mime with attachment\nContent-Type: multipart/encrypted;\n protocol=\"application/pgp-encrypted\";\n boundary=\"abc\"\n\nThis is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)\n--abc\nContent-Type: application/pgp-encrypted\nContent-Description: PGP/MIME version identification\n\nVersion: 1\n\n--abc\nContent-Type: application/octet-stream; name=\"encrypted.asc\"\nContent-Description: OpenPGP encrypted message\nContent-Disposition: inline; filename=\"encrypted.asc\"\n\n-----BEGIN PGP MESSAGE-----\nVersion: GnuPG/MacGPG2 v2.0.22 (Darwin)\nComment: GPGTools - http://gpgtools.org\nComment: Using GnuPG with Thunderbird - http://www.enigmail.net/\n\nhQEMA9f7k/zfv8I8AQf/XY1dJfGWb2iU0GYhZLNXkXoi7k4pnWSbRKQoVcEFoYpz\niltbJo70U6rdRziUO2VnGzsdnyi+NtpaZSXdxAKrE2KxQsPwNUziBWyTCL9WyAa/\nz9L5PldfK7H1o8C9CqC3LU6Ppwafaw2WImbPgnvwvuSD+BeAJlPQ9QyzhKmG8faq\nG67yMLm76kP1zKiEacIZng4ilGQ+K5cy43ryod/7HNQWUkHXt/E4YJXzjyNOXzYh\n5r2fbz0OIYcyFIuAIDqzDG5wtGmRc/6qVkUVdOs+H3RPCFPJjPUsRdH5kW6uiHQ2\nMMr5blSzWt0Q7cIqlZJgoMRte3VGEy0ED/oJZaIo3Mnst2ue5uIc5j6Q31nJCvJt\nY37ldHgrN+RpU6pcSjLgfkntjw5nQaV+KnNoB4BpKhODYMVZIuA8TivgVjpDFDgu\n8X/X0gMXD8l6hqMGP48g7etD+poYDWUp5DnsjuyNo2uFXDRyO5GZLM31jh2pIiQw\neoOmijPWy2/CSuMV6swNMbUryhp1idrujC5ggKeLBYARefDKD1T40PUFV88THCyL\n2NPZY1XKp2NIMH+WrJKYTqaJgSGzRKkqZOZByISAd+Ld7nm/t636sT1HoVHn9AR7\nfbiOqjvHW/AYV0TAK912QzVj/qg4PKSaMSV0CjIW3IoY1uPmYLxfSDxUmHwrnyEn\n74CkF/a3VNBTN6MX2Z6kFuswZx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ql0JmBSVK3S\nfPJCimDNoynasdCM68Av0GB/AHr4rT5PQd0UQyRmPvh4+lD6CHGWMZoYqjDvMM5n\nqv1h/Cwt/nKk68Ehi1tzbOHup3TT0jZC811FyYKvHwLT0rVJxJgn93MnSgkwJbVs\nhEfdYZee1dTFlaLFOCB5llGYyTae60Gp8qppz9Xr3jdk+ertl7GjG/IUvU8K56Si\nHKDPWLd/8uSeajKYHthwAKAlYbXQrNpUgozaQjt7G9NbqdWfT1NOsmCSCFOCDjOs\nTTJ21dz5f4pk6j1GNNAe20iJXBayPplCaG/GxneY1V+0t2UTwF1DaqhLLb1PZ0k9\n9ejZuwqRXFReFx+DLSUMTNsxYOekHVdAEBkti5vzfqLUc6f3LZ4cZV5+COi
internaldate: '14-Sep-2013 20:22:28 -0300',
uid: 800
}, {
raw: "Message-id: <h>\nFrom: safewithme.testuser@gmail.com\nTo: safewithme.testuser@gmail.com\nSubject: enigmail encrypted signed pgp/mime with attachment\nContent-Type: multipart/encrypted;\n protocol=\"application/pgp-encrypted\";\n boundary=\"abc\"\n\nThis is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)\n--abc\nContent-Type: application/pgp-encrypted\nContent-Description: PGP/MIME version identification\n\nVersion: 1\n\n--abc\nContent-Type: application/octet-stream; name=\"encrypted.asc\"\nContent-Description: OpenPGP encrypted message\nContent-Disposition: inline; filename=\"encrypted.asc\"\n\n-----BEGIN PGP MESSAGE-----\nVersion: GnuPG/MacGPG2 v2.0.22 (Darwin)\nComment: GPGTools - http://gpgtools.org\nComment: Using GnuPG with Thunderbird - http://www.enigmail.net/\n\nhQELA9f7k/zfv8I8AQf3WUkThZZkrDcKyCmrnWoUC75EKDD6L9R40OpMNMMdYb5o\nQedZVlokwHeCFdliIVi/WtHfMsyZsT65w7C9rDtLf4l/vtE8Pg2OuTu/BYf4+O4h\nMhRKk6snqE3SQENeatsslRQFpz3/C1SgXbb9ooug8ZOD1I+/4I6xGpBbFnlJ78rX\nW33h/V/8WAXF/LRoH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8XsCspczj2jraGExXjmlomJ8fMLV61onkzDajcTR7pmvKPXjEJ/Gg9\ne5SpXT2Ae/IobnnCQDWia8tRe218+tAWnRegSMvnCBwihIAPhN2H9DecEvs1H4qX\n/vJ4MkIUqToDH3Mu7MGZzrScc/8oDOUUWYAz0qpbchG33oEUllPpo8wNHB5tGNR6\nK7M1bRAAlMBDv4EaEOoIEkXrC+8P5HDmPTy9IWmPTx7y0g+0B6rY5W36yK0NwqBD\nftchOYinFot6yV3t2mnh+i4ZwQUYRLdiW4Z17mRNsv2T+1IPOdyp0T0IPBDwneCD\nb97dd7JAd7TOg6pZqzETjz8xrSp4d32ZJnnxpBrPd9bzAWwvXPjuGTNmoPWAdfLI\n/Vro+afHguRbycQ9/1jZw4z6J/9Ng6PRPN5jdLhKHXqmCvy9e33/e8HPi2rsvDUT\nkt2BypXj2WHAtJhZbncJHn4pMcE6whVxGZpwcJ9k4lfWRUyRyziI1lvGlwBSDa9U\nJwkAR42p3QKfjZ5ckSJ7aZ8xL8jQ+RCmWTe9oolPISW0tr2PP9OP0in9RIKzfZei\nl8wFV2xDNZ/7WiG4wM4AohWTvb34WxmAtUFBrUAoFtGEg7j3SoriBAbpWi3Fognw\nI5eLQ+YinfgSaYZV2wNrt8FPa6/2N70dNasp2IIp5kFkWD5ek7E4cL1/7QGA56r1\nqYRis73pJ/pRjTakLDdZVJtW5iQPaebFzMPBX24ZnUrRuL1PCmu1AfYFFlJDznEH\nL02d8J5+8sijBHDi7k+AdysqDV/BFW2iqKf6gO2SAgRHwzej1s4X3WIW6IM2lnFo\n90XKw60gPLl2XXnMEkUNm/HCE+Ov6JaXUVp0vx/1U3i4AR1ZuUJ+
internaldate: '14-Sep-2013 22:22:28 -0300',
uid: 801
}];
2014-06-11 03:42:34 -04:00
imapFolders = {
separator: '/',
folders: {
'[Gmail]': {
flags: ['\\Noselect'],
folders: {
'All Mail': {
'special-use': '\\All'
},
Drafts: {
'special-use': '\\Drafts'
},
Important: {
'special-use': '\\Important'
},
'Sent Mail': {
'special-use': '\\Sent'
},
Spam: {
'special-use': '\\Junk'
},
Starred: {
'special-use': '\\Flagged'
},
Trash: {
'special-use': '\\Trash'
}
}
}
}
};
2014-06-11 03:42:34 -04:00
var serverUsers = {};
serverUsers[testAccount.user] = {
password: testAccount.pass,
xoauth2: {
accessToken: testAccount.xoauth2,
sessionTimeout: 3600 * 1000
}
};
2014-06-11 03:42:34 -04:00
imapServer = new BrowserCrow({
debug: false,
plugins: ['sasl-ir', 'xoauth2', 'special-use', 'id', 'idle', 'unselect', 'enable', 'condstore'],
id: {
name: 'browsercrow',
version: '0.1.0'
},
storage: {
'INBOX': {
messages: imapMessages
},
'': imapFolders
},
users: serverUsers
});
2014-06-11 03:42:34 -04:00
smtpServer = new BrowserSMTP({
debug: false,
users: serverUsers
});
2014-06-11 03:42:34 -04:00
mockKeyPair = {
privateKey: {
_id: 'D7FB93FCDFBFC23C',
2014-06-11 03:42:34 -04:00
userId: testAccount.user,
userIds: [{
name: 'John Doe',
emailAddress: testAccount.user
}],
2014-06-11 03:42:34 -04:00
encryptedKey: '-----BEGIN PGP PRIVATE KEY BLOCK-----\r\nVersion: OpenPGP.js v.1.20131116\r\nComment: Whiteout Mail - http://whiteout.io\r\n\r\nxcL+BFKODs4BB/9iOF4THsjQMY+WEpT7ShgKxj4bHzRRaQkqczS4nZvP0U3g\r\nqeqCnbpagyeKXA+bhWFQW4GmXtgAoeD5PXs6AZYrw3tWNxLKu2Oe6Tp9K/XI\r\nxTMQ2wl4qZKDXHvuPsJ7cmgaWqpPyXtxA4zHHS3WrkI/6VzHAcI/y6x4szSB\r\nKgSuhI3hjh3s7TybUC1U6AfoQGx/S7e3WwlCOrK8GTClirN/2mCPRC5wuIft\r\nnkoMfA6jK8d2OPrJ63shy5cgwHOjQg/xuk46dNS7tkvGmbaa+X0PgqSKB+Hf\r\nYPPNS/ylg911DH9qa8BqYU2QpNh9jUKXSF+HbaOM+plWkCSAL7czV+R3ABEB\r\nAAH+AwMI8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ZwH/2AVGYB+8RDarP5a5uZPYSxJKeM8zHMbi7LKQWhr5NpkJajZdra1CCGZ\r\nTXTeQSRBvU4SNGOmDAlhf0qCGeXwMHIzrzovkBedHIc/vypEkItdJeXQAaJx\r\nuhQOnmyi9priuzBBx4e9x1aBn+aAdNGiJB4l13L2T4fow8WLIVpVwXB6BWya\r\nlz50JwLzJP6qHxkhvIZElTrQ+Yoo3stS6w/7wNtK/f3MIYkIGVVUrIDgzN0X\r\nm4z6ypN1dsrM6tPkMZ0JlqjHiz7DXpKrWsfNkoVZ9A98osMH2nIDS58JVEDc\r\nAXoFSLsbdmqFmIc2Ew828TjlX+FLU9tlx89WhSMTapzUjHU=\r\n=wxuK\r\n-----END PGP PRIVATE KEY BLOCK-----'
},
publicKey: {
_id: 'D7FB93FCDFBFC23C',
2014-06-11 03:42:34 -04:00
userId: testAccount.user,
userIds: [{
name: 'John Doe',
emailAddress: testAccount.user
}],
2014-06-11 03:42:34 -04:00
publicKey: '-----BEGIN PGP PUBLIC KEY BLOCK-----\r\nVersion: OpenPGP.js v.1.20131116\r\nComment: Whiteout Mail - http://whiteout.io\r\n\r\nxsBNBFKODs4BB/9iOF4THsjQMY+WEpT7ShgKxj4bHzRRaQkqczS4nZvP0U3g\r\nqeqCnbpagyeKXA+bhWFQW4GmXtgAoeD5PXs6AZYrw3tWNxLKu2Oe6Tp9K/XI\r\nxTMQ2wl4qZKDXHvuPsJ7cmgaWqpPyXtxA4zHHS3WrkI/6VzHAcI/y6x4szSB\r\nKgSuhI3hjh3s7TybUC1U6AfoQGx/S7e3WwlCOrK8GTClirN/2mCPRC5wuIft\r\nnkoMfA6jK8d2OPrJ63shy5cgwHOjQg/xuk46dNS7tkvGmbaa+X0PgqSKB+Hf\r\nYPPNS/ylg911DH9qa8BqYU2QpNh9jUKXSF+HbaOM+plWkCSAL7czV+R3ABEB\r\nAAHNLVdoaXRlb3V0IFVzZXIgPHNhZmV3aXRobWUudGVzdHVzZXJAZ21haWwu\r\nY29tPsLAXAQQAQgAEAUCUo4O2gkQ1/uT/N+/wjwAAN2cB/9gFRmAfvEQ2qz+\r\nWubmT2EsSSnjPMxzG4uyykFoa+TaZCWo2Xa2tQghmU103kEkQb1OEjRjpgwJ\r\nYX9Kghnl8DByM686L5AXnRyHP78qRJCLXSXl0AGicboUDp5sovaa4rswQceH\r\nvcdWgZ/mgHTRoiQeJddy9k+H6MPFiyFaVcFwegVsmpc+dCcC8yT+qh8ZIbyG\r\nRJU60PmKKN7LUusP+8DbSv39zCGJCBlVVKyA4MzdF5uM+sqTdXbKzOrT5DGd\r\nCZaox4s+w16Sq1rHzZKFWfQPfKLDB9pyA0ufCVRA3AF6BUi7G3ZqhZiHNhMP\r\nNvE45V/hS1PbZcfPVoUjE2qc1Ix1\r\n=7Wpe\r\n-----END PGP PUBLIC KEY BLOCK-----'
}
};
// don't multithread, Function.prototype.bind() is broken in phantomjs in web workers
window.Worker = undefined;
navigator.online = true;
imapClient = new ImapClient({
auth: {
user: testAccount.user,
xoauth2: testAccount.xoauth2
},
secure: true,
ca: ['random string']
});
imapClient._client.client._TCPSocket = imapServer.createTCPSocket();
imapClient._listeningClient.client._TCPSocket = imapServer.createTCPSocket();
imapClient.onError = function(err) {
console.log('IMAP error.', err);
console.log('IMAP reconnecting...');
// re-init client modules on error
appController.onConnect(function(err) {
if (err) {
console.error('IMAP reconnect failed!', err);
return;
}
console.log('IMAP reconnect attempt complete.');
});
2014-06-11 03:42:34 -04:00
};
smtpClient = new SmtpClient('localhost', 25, {
auth: {
user: testAccount.user,
xoauth2: testAccount.xoauth2
},
secure: true,
ca: ['random string'],
onError: console.error
});
2014-06-11 03:42:34 -04:00
smtpClient._TCPSocket = smtpServer.createTCPSocket();
sinon.stub(mailreader, 'startWorker', function() {});
sinon.stub(openpgp, 'initWorker', function() {});
sinon.stub(appController, 'onConnect', function(cb) {
appController._emailDao.onConnect({
imapClient: imapClient,
pgpMailer: new PgpMailer({
tls: {
ca: 'random string'
}
}, appController._pgpbuilder)
}, cb);
});
appController.start({
onError: function() {}
}, function(err) {
expect(err).to.not.exist;
userStorage = appController._userStorage;
appController.init({
emailAddress: testAccount.user
}, function(err) {
expect(err).to.not.exist;
2014-06-11 03:42:34 -04:00
emailDao = appController._emailDao;
emailDao.onIncomingMessage = function() {};
emailDao.unlock({
passphrase: testAccount.pass,
keypair: mockKeyPair
}, function(err) {
expect(err).to.not.exist;
2014-06-11 03:42:34 -04:00
appController.onConnect(function(err) {
expect(err).to.not.exist;
done();
});
});
});
});
});
2014-06-11 03:42:34 -04:00
afterEach(function(done) {
openpgp.initWorker.restore();
mailreader.startWorker.restore();
appController.onConnect.restore();
imapClient._client.close();
imapClient._listeningClient.close();
userStorage.clear(done);
});
describe('IMAP Tests', function() {
var currentFolder;
beforeEach(function(done) {
emailDao.openFolder({
folder: {
path: 'INBOX'
}
}, function(err) {
expect(err).to.not.exist;
2014-06-11 03:42:34 -04:00
currentFolder = emailDao._account.folders.filter(function(folder) {
return folder.path === 'INBOX';
}).pop();
expect(currentFolder).to.exist;
done();
});
});
2014-06-11 03:42:34 -04:00
afterEach(function() {
emailDao.onIncomingMessage = function() {};
});
it('should receive new messages on startup', function(done) {
emailDao.onIncomingMessage = function(messages) {
expect(messages.length).to.equal(imapMessages.length);
done();
2014-06-11 03:42:34 -04:00
};
});
it('should receive new messages', function(done) {
emailDao.onIncomingMessage = function(messages) {
expect(messages.length).to.equal(imapMessages.length);
emailDao.onIncomingMessage = function(messages) {
expect(messages.length).to.equal(1);
expect(messages[0].answered).to.be.false;
emailDao.onIncomingMessage = function(messages) {
expect(messages.length).to.equal(1);
expect(messages[0].answered).to.be.true;
done();
};
};
setTimeout(function() {
imapServer.appendMessage('INBOX', ['$My$Flag'], false, 'Message-id: <n1>\r\nSubject: new message\r\n\r\nhello world!');
setTimeout(function() {
imapServer.appendMessage('INBOX', ['$My$Flag', '\\Answered'], false, 'Message-id: <n2>\r\nSubject: new message\r\n\r\nhello world!');
}, 1000);
}, 1000);
};
});
it('should delete a message', function(done) {
emailDao.onIncomingMessage = function() {
emailDao.deleteMessage({
folder: currentFolder,
message: {
uid: 600
}
}, function(err) {
expect(err).to.not.exist;
emailDao.openFolder({
folder: {
path: '[Gmail]/Trash'
}
}, function(err, folder) {
expect(err).to.not.exist;
expect(folder.exists).to.equal(1);
emailDao.onIncomingMessage = function(messages) {
expect(messages.length).to.equal(1);
expect(messages[0].id).to.equal('b');
done();
};
});
});
};
});
it('should get body', function(done) {
emailDao.onIncomingMessage = function(messages) {
emailDao.getBody({
folder: currentFolder,
message: messages[4]
}, function(err, message) {
expect(err).to.not.exist;
expect(message.body).to.equal('World 5!');
done();
});
};
});
[{
nr: 6,
hasAttachments: true
}, {
nr: 7,
hasAttachments: true
}].forEach(function(email) {
it('should get and decrypt body #' + email.nr, function(done) {
emailDao.onIncomingMessage = function(messages) {
emailDao.getBody({
folder: currentFolder,
message: messages[email.nr]
}, function(err, message) {
expect(err).to.not.exist;
emailDao.decryptBody({
message: message,
folder: currentFolder
}, function(err) {
expect(err).to.not.exist;
expect(message.body).to.equal('asdf');
if (email.hasAttachments) {
expect(message.attachments.length).to.equal(1);
}
done();
});
});
};
});
});
2014-06-11 03:42:34 -04:00
it('should set flags', function(done) {
emailDao.onIncomingMessage = function(messages) {
var message = messages[0];
message.unread = false;
message.answered = true;
emailDao.setFlags({
folder: currentFolder,
message: message
}, function(err) {
expect(err).to.not.exist;
done();
});
};
});
});
2014-06-11 03:42:34 -04:00
describe('SMTP Tests', function() {
// phantomjs is just sooo slow
it('should send a plaintext message', function(done) {
sinon.stub(smtpServer, 'onmail', function(mail) {
expect(mail.from).to.equal(testAccount.user);
expect(mail.to).to.deep.equal([testAccount.user]);
expect(/^Content-Type: multipart\/signed/.test(mail.body)).to.be.true;
});
emailDao.sendPlaintext({
smtpclient: smtpClient,
email: {
from: [testAccount.user],
to: [testAccount.user],
subject: 'plaintext test',
body: 'hello world!'
}
}, function(err) {
expect(err).to.not.exist;
2014-06-11 03:42:34 -04:00
expect(smtpServer.onmail.callCount).to.equal(1);
smtpServer.onmail.restore();
done();
});
});
2014-06-11 03:42:34 -04:00
it('should send an encrypted message', function(done) {
sinon.stub(smtpServer, 'onmail', function(mail) {
expect(mail.from).to.equal(testAccount.user);
expect(mail.to).to.deep.equal([testAccount.user]);
expect(/^Content-Type: multipart\/mixed/.test(mail.body)).to.be.true;
expect(mail.body).to.contain('this is a private conversation');
});
emailDao.sendEncrypted({
smtpclient: smtpClient,
email: {
from: [testAccount.user],
to: [testAccount.user],
subject: 'plaintext test',
body: 'hello world!',
publicKeysArmored: [mockKeyPair.publicKey.publicKey]
}
}, function(err) {
expect(err).to.not.exist;
2014-06-11 03:42:34 -04:00
expect(smtpServer.onmail.callCount).to.equal(1);
smtpServer.onmail.restore();
done();
});
});
});
});
});