2013-03-13 11:58:46 -04:00
|
|
|
module("Email DAO");
|
|
|
|
|
|
|
|
var emaildao_test = {
|
|
|
|
user: 'test@atlasdev.onmicrosoft.com',
|
|
|
|
password: 'Xoza76645',
|
|
|
|
keySize: 128,
|
2013-05-18 19:33:59 -04:00
|
|
|
ivSize: 128,
|
|
|
|
rsaKeySize: 1024
|
2013-03-13 11:58:46 -04:00
|
|
|
};
|
|
|
|
|
2013-05-18 16:33:10 -04:00
|
|
|
asyncTest("Init", 3, function() {
|
2013-03-13 11:58:46 -04:00
|
|
|
// init dependencies
|
2013-05-22 11:03:54 -04:00
|
|
|
var util = new cryptoLib.Util(window, uuid);
|
2013-05-31 07:09:49 -04:00
|
|
|
var jsonDao = new app.dao.LawnchairDAO(Lawnchair);
|
2013-06-02 22:26:17 -04:00
|
|
|
jsonDao.init(emaildao_test.user);
|
2013-03-13 11:58:46 -04:00
|
|
|
emaildao_test.crypto = new app.crypto.Crypto(window, util);
|
2013-03-22 07:46:56 -04:00
|
|
|
emaildao_test.storage = new app.dao.DeviceStorage(util, emaildao_test.crypto, jsonDao, null);
|
2013-03-13 11:58:46 -04:00
|
|
|
// cloud storage stub
|
|
|
|
var cloudstorageStub = {
|
2013-05-31 17:27:19 -04:00
|
|
|
putPublicKey: function(pk, callback) {
|
2013-04-01 17:23:25 -04:00
|
|
|
callback();
|
2013-04-19 10:38:32 -04:00
|
|
|
},
|
2013-05-31 17:27:19 -04:00
|
|
|
putPrivateKey: function(prk, callback) {
|
2013-04-19 10:38:32 -04:00
|
|
|
callback();
|
2013-06-03 13:57:15 -04:00
|
|
|
},
|
|
|
|
getPublicKeyByUserId: function(userId, callback) {
|
|
|
|
callback();
|
2013-04-01 17:23:25 -04:00
|
|
|
}
|
2013-03-13 11:58:46 -04:00
|
|
|
};
|
2013-05-31 09:51:34 -04:00
|
|
|
emaildao_test.keychain = new app.dao.KeychainDAO(jsonDao, cloudstorageStub);
|
2013-06-03 13:57:15 -04:00
|
|
|
emaildao_test.emailDao = new app.dao.EmailDAO(jsonDao, emaildao_test.crypto, emaildao_test.storage, cloudstorageStub, util, emaildao_test.keychain);
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
// generate test data
|
2013-03-21 15:18:03 -04:00
|
|
|
emaildao_test.list = new TestData().getEmailCollection(100);
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
var account = new app.model.Account({
|
|
|
|
emailAddress: emaildao_test.user,
|
|
|
|
symKeySize: emaildao_test.keySize,
|
2013-05-18 19:33:59 -04:00
|
|
|
symIvSize: emaildao_test.ivSize,
|
|
|
|
asymKeySize: emaildao_test.rsaKeySize
|
2013-03-13 11:58:46 -04:00
|
|
|
});
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-05-31 09:51:34 -04:00
|
|
|
// clear db before tests
|
|
|
|
jsonDao.clear(function(err) {
|
|
|
|
ok(!err, 'DB cleared. Error status: ' + err);
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-05-31 09:51:34 -04:00
|
|
|
emaildao_test.emailDao.init(account, emaildao_test.password, function(err) {
|
|
|
|
ok(!err);
|
|
|
|
equal(emaildao_test.emailDao.account.get('emailAddress'), emaildao_test.user, 'Email DAO Account');
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-05-31 09:51:34 -04:00
|
|
|
asyncTest("Persist test emails", 4, function() {
|
|
|
|
emaildao_test.keychain.getUserKeyPair(emaildao_test.user, function(err, keypair) {
|
|
|
|
ok(!err && keypair, 'Fetch keypair from keychain');
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-05-31 09:51:34 -04:00
|
|
|
var receiverPubkeys = [keypair.publicKey];
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-05-31 09:51:34 -04:00
|
|
|
emaildao_test.crypto.encryptListForUser(emaildao_test.list.toJSON(), receiverPubkeys, function(err, encryptedList) {
|
|
|
|
ok(!err);
|
|
|
|
equal(encryptedList.length, emaildao_test.list.length, 'Encrypt list');
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-05-31 09:51:34 -04:00
|
|
|
// add sent date to encrypted items
|
|
|
|
for (var i = 0; i < encryptedList.length; i++) {
|
|
|
|
encryptedList[i].sentDate = emaildao_test.list.at(i).get('sentDate');
|
|
|
|
}
|
|
|
|
|
|
|
|
emaildao_test.storage.storeEcryptedList(encryptedList, 'email_inbox', function() {
|
|
|
|
ok(true, 'Store encrypted list');
|
|
|
|
|
|
|
|
start();
|
|
|
|
});
|
2013-03-13 11:58:46 -04:00
|
|
|
});
|
2013-04-01 17:23:25 -04:00
|
|
|
});
|
2013-03-13 11:58:46 -04:00
|
|
|
});
|
|
|
|
|
2013-05-18 16:33:10 -04:00
|
|
|
asyncTest("List Email models", 2, function() {
|
|
|
|
emaildao_test.emailDao.listItems('inbox', 0, emaildao_test.list.length, function(err, collection) {
|
|
|
|
ok(!err);
|
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
var gotten = collection.toJSON(),
|
2013-03-21 16:58:56 -04:00
|
|
|
reference = emaildao_test.list.toJSON();
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-03-21 15:18:03 -04:00
|
|
|
deepEqual(gotten, reference, 'Compare collection');
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest("Get item", 1, function() {
|
|
|
|
var item = emaildao_test.list.toJSON()[0];
|
|
|
|
var mail = emaildao_test.emailDao.getItem('inbox', item.id);
|
|
|
|
deepEqual(mail.toJSON(), item, 'Item correct');
|
|
|
|
start();
|
2013-04-01 17:23:25 -04:00
|
|
|
});
|