mirror of
https://github.com/moparisthebest/mail
synced 2024-11-26 02:42:17 -05:00
integration tests all work again
This commit is contained in:
parent
d7f6c89062
commit
a58753d82b
@ -48,7 +48,9 @@ module.exports = function(grunt) {
|
||||
qunit: {
|
||||
all: {
|
||||
options: {
|
||||
urls: ['http://localhost:<%= connect.test.options.port %>/test/unit/index.html']
|
||||
urls: [
|
||||
'http://localhost:<%= connect.test.options.port %>/test/unit/index.html',
|
||||
'http://localhost:<%= connect.test.options.port %>/test/integration/index.html']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,104 +131,6 @@ app.dao.EmailDAO = function(_, crypto, devicestorage, cloudstorage, util, keycha
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks the user virtual inbox containing end-2-end encrypted mail items
|
||||
*/
|
||||
this.checkVInbox = function(callback) {
|
||||
var self = this;
|
||||
|
||||
cloudstorage.listEncryptedItems('email', this.account.get('emailAddress'), 'vinbox', function(err, data) {
|
||||
// if virtual inbox is emtpy just callback
|
||||
if (err || !data || data.status || data.length === 0) {
|
||||
callback(); // error
|
||||
return;
|
||||
}
|
||||
|
||||
// asynchronously iterate over the encrypted items
|
||||
var after = _.after(data.length, function() {
|
||||
callback();
|
||||
});
|
||||
|
||||
_.each(data, function(asymCt) {
|
||||
// asymmetric decrypt
|
||||
asymDecryptMail(asymCt, function(err, pt) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// symmetric encrypt and push to cloud
|
||||
symEncryptAndUpload(pt, function(err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// delete asymmetricall encrypted item from virtual inbox
|
||||
deleteVinboxItem(asymCt, function(err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
after(); // asynchronously iterate through objects
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function asymDecryptMail(m, callback) {
|
||||
var pubKeyId = m.senderPk.split(';')[1];
|
||||
// pull the sender's public key
|
||||
cloudstorage.getPublicKey(pubKeyId, function(err, senderPk) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// do authenticated decryption
|
||||
naclCrypto.asymDecrypt(m.ciphertext, m.itemIV, senderPk.publicKey, keypair.boxSk, function(plaintext) {
|
||||
callback(null, JSON.parse(plaintext));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function symEncryptAndUpload(email, callback) {
|
||||
var itemKey = util.random(self.account.get('symKeySize')),
|
||||
itemIV = util.random(self.account.get('symIvSize')),
|
||||
keyIV = util.random(self.account.get('symIvSize')),
|
||||
json = JSON.stringify(email),
|
||||
envelope, encryptedKey;
|
||||
|
||||
// symmetrically encrypt item
|
||||
crypto.aesEncrypt(json, itemKey, itemIV, function(ct) {
|
||||
|
||||
// encrypt item key for user
|
||||
encryptedKey = crypto.aesEncryptForUserSync(itemKey, keyIV);
|
||||
envelope = {
|
||||
id: email.id,
|
||||
crypto: 'aes-128-ccm',
|
||||
ciphertext: ct,
|
||||
encryptedKey: encryptedKey,
|
||||
keyIV: keyIV,
|
||||
itemIV: itemIV
|
||||
};
|
||||
|
||||
// push encrypted item to cloud
|
||||
cloudstorage.putEncryptedItem(envelope, 'email', self.account.get('emailAddress'), 'inbox', function(err) {
|
||||
callback(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function deleteVinboxItem(email, callback) {
|
||||
cloudstorage.deleteEncryptedItem(email.id, 'email', self.account.get('emailAddress'), 'vinbox', function(err) {
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Synchronize a folder's items from the cloud to the device-storage
|
||||
* @param folderName [String] The name of the folder e.g. 'inbox'
|
||||
|
@ -135,61 +135,51 @@ asyncTest("Get Public Keys", 2, function() {
|
||||
|
||||
module("Email DAO");
|
||||
|
||||
// asyncTest("Init", 1, function() {
|
||||
asyncTest("Init", 1, function() {
|
||||
var account = new app.model.Account({
|
||||
emailAddress: cloudstoragedao_test.user,
|
||||
symKeySize: cloudstoragedao_test.keySize,
|
||||
symIvSize: cloudstoragedao_test.ivSize,
|
||||
asymKeySize: cloudstoragedao_test.rsaKeySize
|
||||
});
|
||||
|
||||
// var account = new app.model.Account({
|
||||
// emailAddress: cloudstoragedao_test.user,
|
||||
// symKeySize: cloudstoragedao_test.keySize,
|
||||
// symIvSize: cloudstoragedao_test.ivSize,
|
||||
// asymKeySize: cloudstoragedao_test.rsaKeySize
|
||||
// });
|
||||
cloudstoragedao_test.emailDao.init(account, cloudstoragedao_test.password, function(err) {
|
||||
ok(!err, 'Init complete');
|
||||
|
||||
// cloudstoragedao_test.emailDao.init(account, cloudstoragedao_test.password, function(err) {
|
||||
// ok(!err, 'Init complete');
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
// start();
|
||||
// });
|
||||
// });
|
||||
asyncTest("Send Plaintext Email item", 1, function() {
|
||||
var email = new app.model.Email({
|
||||
id: cloudstoragedao_test.util.UUID(),
|
||||
from: cloudstoragedao_test.user, // sender address
|
||||
to: [cloudstoragedao_test.user], // list of receivers
|
||||
subject: 'Client Email DAO Test', // Subject line
|
||||
body: 'Hello world' // plaintext body
|
||||
});
|
||||
|
||||
// asyncTest("Send Plaintext Email item", 1, function() {
|
||||
cloudstoragedao_test.emailDao.sendEmail(email, function(err) {
|
||||
ok(!err, 'Email sent');
|
||||
|
||||
// var email = new app.model.Email({
|
||||
// id: cloudstoragedao_test.util.UUID(),
|
||||
// from: cloudstoragedao_test.user, // sender address
|
||||
// to: [cloudstoragedao_test.user], // list of receivers
|
||||
// subject: 'Client Email DAO Test', // Subject line
|
||||
// body: 'Hello world' // plaintext body
|
||||
// });
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
// cloudstoragedao_test.emailDao.sendEmail(email, function(err) {
|
||||
// ok(!err, 'Email sent');
|
||||
asyncTest("Sync emails from cloud", 1, function() {
|
||||
cloudstoragedao_test.emailDao.syncFromCloud('inbox', function(err) {
|
||||
ok(!err, 'Synced items');
|
||||
|
||||
// start();
|
||||
// });
|
||||
// });
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
// asyncTest("Check virtual inbox, re-encrypt and push to cloud", 1, function() {
|
||||
// cloudstoragedao_test.emailDao.checkVInbox(function(err) {
|
||||
// ok(!err, 'Synced items');
|
||||
asyncTest("List emails from cloud", 2, function() {
|
||||
|
||||
// start();
|
||||
// });
|
||||
// });
|
||||
cloudstoragedao_test.emailDao.listItems('inbox', 0, null, function(err, collection) {
|
||||
ok(!err);
|
||||
ok(collection.length > 0, 'Read synced items');
|
||||
|
||||
// asyncTest("Sync emails from cloud", 1, function() {
|
||||
// cloudstoragedao_test.emailDao.syncFromCloud('inbox', function(err) {
|
||||
// ok(!err, 'Synced items');
|
||||
|
||||
// start();
|
||||
// });
|
||||
// });
|
||||
|
||||
// asyncTest("List emails from cloud", 3, function() {
|
||||
|
||||
// cloudstoragedao_test.emailDao.listItems('inbox', 0, null, function(err, collection) {
|
||||
// ok(!err);
|
||||
// ok(collection.length > 0, 'Read synced items');
|
||||
|
||||
// start();
|
||||
// });
|
||||
// });
|
||||
start();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user