2013-06-06 13:19:37 -04:00
|
|
|
'use strict';
|
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
module("CloudStorage DAO");
|
|
|
|
|
|
|
|
var cloudstoragedao_test = {
|
2013-05-02 12:49:22 -04:00
|
|
|
user: 'email.dao.it.test@mail.whiteout.io',
|
2013-05-31 17:27:19 -04:00
|
|
|
password: 'Xoza76645',
|
2013-03-13 11:58:46 -04:00
|
|
|
keySize: 128,
|
2013-05-18 22:00:53 -04:00
|
|
|
ivSize: 128,
|
|
|
|
rsaKeySize: 1024
|
2013-03-13 11:58:46 -04:00
|
|
|
};
|
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
asyncTest("Init", 1, function() {
|
2013-05-31 17:27:19 -04:00
|
|
|
|
|
|
|
// test keys
|
|
|
|
var pk = "-----BEGIN PUBLIC KEY-----\r\n" +
|
|
|
|
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDTIupLSuRD5gh6wHx1f4Q2Qv61\r\n" +
|
|
|
|
"trOWgqfi/eJUtheoOWkW6KGoLqo5xdklPVIqyP9702PDQtf1upwVB8MCGSiYMDyj\r\n" +
|
|
|
|
"Fr0XlYJnJM2ERVrSGkDNSI2+6bVq1k2TB4YeZoMVhel/igCr5Rbr8LyNswCQMIXl\r\n" +
|
|
|
|
"oiMEqmiN/YtLwD1z+QIDAQAB\r\n" +
|
|
|
|
"-----END PUBLIC KEY-----";
|
|
|
|
cloudstoragedao_test.keypair = {
|
|
|
|
publicKey: {
|
|
|
|
_id: "01ca6e54-a6b3-4b5f-bb43-ede30aaccc9e",
|
|
|
|
userId: cloudstoragedao_test.user,
|
|
|
|
publicKey: pk
|
|
|
|
},
|
|
|
|
privateKey: {
|
|
|
|
_id: "01ca6e54-a6b3-4b5f-bb43-ede30aaccc9e",
|
|
|
|
userId: cloudstoragedao_test.user,
|
|
|
|
encryptedKey: "zXBmmR7fz6sfR0AIeOzvwKOb6BrBQBgyweJ4c0LZS9h7C18SgPSMcv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VlSnhORfNJvjn5Up/iusKeKXEGb/lhyc058GZY5UCmoIsV30TYgzXeuj6VZBEtcvAvza0mYmGvXf91ebVZR+",
|
|
|
|
iv: "XE4c3X134YNkapbeSXP6GA=="
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
// init dependencies
|
2013-05-27 13:25:45 -04:00
|
|
|
cloudstoragedao_test.util = new cryptoLib.Util(window, uuid);
|
2013-05-31 17:27:19 -04:00
|
|
|
var jsonDao = new app.dao.LawnchairDAO(Lawnchair);
|
2013-06-02 22:26:17 -04:00
|
|
|
jsonDao.init(cloudstoragedao_test.user);
|
2013-05-18 22:00:53 -04:00
|
|
|
cloudstoragedao_test.crypto = new app.crypto.Crypto(window, cloudstoragedao_test.util);
|
|
|
|
cloudstoragedao_test.storage = new app.dao.DeviceStorage(cloudstoragedao_test.util, cloudstoragedao_test.crypto, jsonDao, null);
|
2013-03-13 11:58:46 -04:00
|
|
|
cloudstoragedao_test.cloudstorage = new app.dao.CloudStorage(window, $);
|
2013-05-31 17:27:19 -04:00
|
|
|
cloudstoragedao_test.keychain = new app.dao.KeychainDAO(jsonDao, cloudstoragedao_test.cloudstorage);
|
2013-06-03 13:57:15 -04:00
|
|
|
cloudstoragedao_test.emailDao = new app.dao.EmailDAO(jsonDao, cloudstoragedao_test.crypto, cloudstoragedao_test.storage, cloudstoragedao_test.cloudstorage, cloudstoragedao_test.util, cloudstoragedao_test.keychain);
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-03-13 11:58:46 -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-03-13 11:58:46 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-05-31 17:27:19 -04:00
|
|
|
asyncTest("Put public key to cloud", 1, function() {
|
|
|
|
cloudstoragedao_test.cloudstorage.putPublicKey(cloudstoragedao_test.keypair.publicKey, function(err) {
|
2013-04-19 07:55:21 -04:00
|
|
|
ok(!err, 'Persist key to cloud');
|
|
|
|
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-06-03 13:57:15 -04:00
|
|
|
asyncTest("Get Public key from cloud by id", 2, function() {
|
2013-05-31 17:27:19 -04:00
|
|
|
cloudstoragedao_test.cloudstorage.getPublicKey(cloudstoragedao_test.keypair.publicKey._id, function(err, data) {
|
2013-04-19 07:55:21 -04:00
|
|
|
ok(!err && data && data.publicKey, 'Get public key from cloud');
|
2013-05-31 17:27:19 -04:00
|
|
|
deepEqual(data, cloudstoragedao_test.keypair.publicKey, 'Public key is equal');
|
2013-04-19 07:55:21 -04:00
|
|
|
|
2013-06-03 13:57:15 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest("Get Public key from cloud by email", 2, function() {
|
|
|
|
cloudstoragedao_test.cloudstorage.getPublicKeyByUserId(cloudstoragedao_test.keypair.publicKey.userId, function(err, data) {
|
|
|
|
ok(!err && data && data.publicKey, 'Get public key from cloud');
|
|
|
|
deepEqual(data, cloudstoragedao_test.keypair.publicKey, 'Public key is equal');
|
|
|
|
|
2013-04-19 07:55:21 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-05-31 17:27:19 -04:00
|
|
|
asyncTest("Delete Public key from cloud", 1, function() {
|
|
|
|
cloudstoragedao_test.cloudstorage.removePublicKey(cloudstoragedao_test.keypair.publicKey._id, function(err) {
|
|
|
|
ok(!err, 'Delete public key from cloud');
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-05-31 17:27:19 -04:00
|
|
|
asyncTest("Put private key to cloud", 1, function() {
|
|
|
|
cloudstoragedao_test.cloudstorage.putPrivateKey(cloudstoragedao_test.keypair.privateKey, function(err) {
|
2013-03-13 11:58:46 -04:00
|
|
|
ok(!err, 'Persist key to cloud');
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-03-13 11:58:46 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-05-31 17:27:19 -04:00
|
|
|
asyncTest("Get Private key from cloud", 2, function() {
|
|
|
|
cloudstoragedao_test.cloudstorage.getPrivateKey(cloudstoragedao_test.keypair.privateKey._id, function(err, data) {
|
|
|
|
ok(!err && data && data.encryptedKey, 'Get private key from cloud');
|
|
|
|
deepEqual(data, cloudstoragedao_test.keypair.privateKey, 'Private key is equal');
|
2013-04-19 10:38:32 -04:00
|
|
|
|
2013-05-31 17:27:19 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
2013-04-19 10:38:32 -04:00
|
|
|
|
2013-05-31 17:27:19 -04:00
|
|
|
asyncTest("Delete Private key from cloud", 1, function() {
|
|
|
|
cloudstoragedao_test.cloudstorage.removePrivateKey(cloudstoragedao_test.keypair.privateKey._id, function(err) {
|
|
|
|
ok(!err, 'Delete private key from cloud');
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-05-31 17:27:19 -04:00
|
|
|
start();
|
2013-03-13 11:58:46 -04:00
|
|
|
});
|
2013-05-31 17:27:19 -04:00
|
|
|
});
|
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-05-31 17:27:19 -04:00
|
|
|
|
|
|
|
module("Keychain DAO");
|
|
|
|
|
|
|
|
asyncTest("Put User Keypair", 1, function() {
|
|
|
|
cloudstoragedao_test.keychain.putUserKeyPair(cloudstoragedao_test.keypair, function(err) {
|
|
|
|
ok(!err);
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-04-19 10:38:32 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-05-31 17:27:19 -04:00
|
|
|
asyncTest("Get User Keypair", 2, function() {
|
|
|
|
cloudstoragedao_test.keychain.getUserKeyPair(cloudstoragedao_test.user, function(err, keypair) {
|
|
|
|
ok(!err);
|
|
|
|
ok(keypair && keypair.publicKey && keypair.privateKey);
|
2013-05-02 12:49:22 -04:00
|
|
|
|
2013-05-31 17:27:19 -04:00
|
|
|
start();
|
2013-05-27 13:25:45 -04:00
|
|
|
});
|
2013-05-31 17:27:19 -04:00
|
|
|
});
|
2013-05-02 12:49:22 -04:00
|
|
|
|
2013-05-31 17:27:19 -04:00
|
|
|
asyncTest("Get Public Keys", 2, function() {
|
|
|
|
var pubkeyIds = [{
|
2013-06-02 22:26:17 -04:00
|
|
|
_id: cloudstoragedao_test.keypair.publicKey._id
|
|
|
|
}
|
|
|
|
];
|
2013-05-31 17:27:19 -04:00
|
|
|
cloudstoragedao_test.keychain.getPublicKeys(pubkeyIds, function(err, pubkeys) {
|
|
|
|
ok(!err);
|
|
|
|
deepEqual(pubkeys[0], cloudstoragedao_test.keypair.publicKey, "Fetch public key");
|
2013-05-02 12:49:22 -04:00
|
|
|
|
2013-05-27 13:25:45 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
2013-05-02 12:49:22 -04:00
|
|
|
|
2013-05-31 17:27:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
module("Email DAO");
|
|
|
|
|
2013-05-31 18:04:58 -04:00
|
|
|
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
|
|
|
|
});
|
2013-05-31 17:27:19 -04:00
|
|
|
|
2013-05-31 18:04:58 -04:00
|
|
|
cloudstoragedao_test.emailDao.init(account, cloudstoragedao_test.password, function(err) {
|
|
|
|
ok(!err, 'Init complete');
|
2013-05-31 17:27:19 -04:00
|
|
|
|
2013-05-31 18:04:58 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
2013-05-31 17:27:19 -04:00
|
|
|
|
2013-05-31 18:04:58 -04:00
|
|
|
asyncTest("Send Plaintext Email item", 1, function() {
|
2013-06-06 14:41:25 -04:00
|
|
|
var email = {
|
2013-05-31 18:04:58 -04:00
|
|
|
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
|
2013-06-06 14:41:25 -04:00
|
|
|
};
|
2013-05-31 17:27:19 -04:00
|
|
|
|
2013-05-31 18:04:58 -04:00
|
|
|
cloudstoragedao_test.emailDao.sendEmail(email, function(err) {
|
|
|
|
ok(!err, 'Email sent');
|
2013-04-19 13:13:27 -04:00
|
|
|
|
2013-05-31 18:04:58 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
2013-04-19 10:38:32 -04:00
|
|
|
|
2013-05-31 18:04:58 -04:00
|
|
|
asyncTest("Sync emails from cloud", 1, function() {
|
|
|
|
cloudstoragedao_test.emailDao.syncFromCloud('inbox', function(err) {
|
|
|
|
ok(!err, 'Synced items');
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-05-31 18:04:58 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
2013-04-19 10:38:32 -04:00
|
|
|
|
2013-05-31 18:04:58 -04:00
|
|
|
asyncTest("List emails from cloud", 2, function() {
|
2013-05-27 13:25:45 -04:00
|
|
|
|
2013-06-06 13:19:37 -04:00
|
|
|
cloudstoragedao_test.emailDao.listItems('inbox', 0, null, function(err, gotten) {
|
2013-05-31 18:04:58 -04:00
|
|
|
ok(!err);
|
2013-06-06 13:19:37 -04:00
|
|
|
ok(gotten.length > 0, 'Read synced items');
|
2013-05-27 13:25:45 -04:00
|
|
|
|
2013-05-31 18:04:58 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|