mirror of
https://github.com/moparisthebest/mail
synced 2024-11-25 18:32:20 -05:00
started cloudstorage integration tests and keychain dao integration tests
This commit is contained in:
parent
dca3b252ce
commit
39a9a90e26
@ -6,58 +6,61 @@ app.dao.CloudStorage = function(window, $) {
|
||||
'use strict';
|
||||
|
||||
//
|
||||
// Public Key
|
||||
// Generic Ajax helper functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Find the user's corresponding public key
|
||||
* GET (read) request
|
||||
*/
|
||||
this.getPublicKey = function(keyId, callback) {
|
||||
var uri;
|
||||
|
||||
uri = app.config.cloudUrl + '/publickey/key/' + keyId;
|
||||
this.get = function(uri, callback) {
|
||||
$.ajax({
|
||||
url: uri,
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(key) {
|
||||
if (!key || !key._id) {
|
||||
callback({
|
||||
error: 'No public key for that user!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, key);
|
||||
success: function(res) {
|
||||
callback(null, res);
|
||||
},
|
||||
error: function(xhr, textStatus, err) {
|
||||
callback({
|
||||
error: err,
|
||||
status: textStatus
|
||||
errMsg: xhr.status + ': ' + xhr.statusText
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Persist the user's publc key
|
||||
* PUT (update) request
|
||||
*/
|
||||
this.putPublicKey = function(pubkey, callback) {
|
||||
var uri;
|
||||
|
||||
uri = app.config.cloudUrl + '/publickey/user/' + pubkey.userId + '/key/' + pubkey._id;
|
||||
this.put = function(item, uri, callback) {
|
||||
$.ajax({
|
||||
url: uri,
|
||||
type: 'PUT',
|
||||
data: JSON.stringify(pubkey),
|
||||
data: JSON.stringify(item),
|
||||
contentType: 'application/json',
|
||||
success: function() {
|
||||
callback();
|
||||
},
|
||||
error: function(xhr, textStatus, err) {
|
||||
callback({
|
||||
error: err,
|
||||
status: textStatus
|
||||
errMsg: xhr.status + ': ' + xhr.statusText
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* DELETE (remove) request
|
||||
*/
|
||||
this.remove = function(uri, callback) {
|
||||
$.ajax({
|
||||
url: uri,
|
||||
type: 'DELETE',
|
||||
success: function() {
|
||||
callback();
|
||||
},
|
||||
error: function(xhr, textStatus, err) {
|
||||
callback({
|
||||
errMsg: xhr.status + ': ' + xhr.statusText
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -72,24 +75,8 @@ app.dao.CloudStorage = function(window, $) {
|
||||
* @param type [String] The type of item e.g. 'email'
|
||||
*/
|
||||
this.putEncryptedItem = function(item, type, emailAddress, folderName, callback) {
|
||||
var uri;
|
||||
|
||||
uri = app.config.cloudUrl + '/' + type + '/user/' + emailAddress + '/folder/' + folderName + '/' + item.id;
|
||||
$.ajax({
|
||||
url: uri,
|
||||
type: 'PUT',
|
||||
data: JSON.stringify(item),
|
||||
contentType: 'application/json',
|
||||
success: function() {
|
||||
callback();
|
||||
},
|
||||
error: function(xhr, textStatus, err) {
|
||||
callback({
|
||||
error: err,
|
||||
status: textStatus
|
||||
});
|
||||
}
|
||||
});
|
||||
var uri = app.config.cloudUrl + '/' + type + '/user/' + emailAddress + '/folder/' + folderName + '/' + item.id;
|
||||
this.put(item, uri, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -97,22 +84,8 @@ app.dao.CloudStorage = function(window, $) {
|
||||
* @param type [String] The type of item e.g. 'email'
|
||||
*/
|
||||
this.deleteEncryptedItem = function(id, type, emailAddress, folderName, callback) {
|
||||
var uri;
|
||||
|
||||
uri = app.config.cloudUrl + '/' + type + '/user/' + emailAddress + '/folder/' + folderName + '/' + id;
|
||||
$.ajax({
|
||||
url: uri,
|
||||
type: 'DELETE',
|
||||
success: function() {
|
||||
callback();
|
||||
},
|
||||
error: function(xhr, textStatus, err) {
|
||||
callback({
|
||||
error: err,
|
||||
status: textStatus
|
||||
});
|
||||
}
|
||||
});
|
||||
var uri = app.config.cloudUrl + '/' + type + '/user/' + emailAddress + '/folder/' + folderName + '/' + id;
|
||||
this.remove(uri, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -122,53 +95,93 @@ app.dao.CloudStorage = function(window, $) {
|
||||
* @param num [Number] The number of items to fetch (null means fetch all)
|
||||
*/
|
||||
this.listEncryptedItems = function(type, emailAddress, folderName, callback) {
|
||||
var uri;
|
||||
var uri = app.config.cloudUrl + '/' + type + '/user/' + emailAddress + '/folder/' + folderName;
|
||||
this.get(uri, callback);
|
||||
};
|
||||
|
||||
// fetch encrypted json objects from cloud service
|
||||
uri = app.config.cloudUrl + '/' + type + '/user/' + emailAddress + '/folder/' + folderName;
|
||||
$.ajax({
|
||||
url: uri,
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(list) {
|
||||
callback(null, list);
|
||||
},
|
||||
error: function(xhr, textStatus, err) {
|
||||
callback({
|
||||
error: err,
|
||||
status: textStatus
|
||||
});
|
||||
//
|
||||
// Public Key
|
||||
//
|
||||
|
||||
/**
|
||||
* Find the user's corresponding public key
|
||||
*/
|
||||
this.getPublicKey = function(keyId, callback) {
|
||||
var uri = app.config.cloudUrl + '/publickey/key/' + keyId;
|
||||
|
||||
this.get(uri, function(err, key) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!key || !key._id) {
|
||||
callback({
|
||||
errMsg: 'No public key for that user!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, key);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Persist the user's publc key
|
||||
*/
|
||||
this.putPublicKey = function(pubkey, callback) {
|
||||
var uri = app.config.cloudUrl + '/publickey/user/' + pubkey.userId + '/key/' + pubkey._id;
|
||||
this.put(pubkey, uri, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete the public key from the cloud storage service
|
||||
*/
|
||||
this.removePublicKey = function(keyId, callback) {
|
||||
var uri = app.config.cloudUrl + '/publickey/key/' + keyId;
|
||||
this.remove(uri, callback);
|
||||
};
|
||||
|
||||
//
|
||||
// Ecrypted Private Key
|
||||
//
|
||||
|
||||
/**
|
||||
* Fetch private key by id
|
||||
*/
|
||||
this.getPrivateKey = function(keyId, callback) {
|
||||
var uri = app.config.cloudUrl + '/privatekey/key/' + keyId;
|
||||
this.get(uri, function(err, key) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!key || !key._id) {
|
||||
callback({
|
||||
errMsg: 'No private key for that user!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, key);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Persist encrypted private key to cloud service
|
||||
*/
|
||||
this.putPrivateKey = function(privkey, callback) {
|
||||
// fetch user's encrypted secret key from keychain/storage
|
||||
var uri;
|
||||
var uri = app.config.cloudUrl + '/privatekey/user/' + privkey.userId + '/key/' + privkey._id;
|
||||
this.put(privkey, uri, callback);
|
||||
};
|
||||
|
||||
uri = app.config.cloudUrl + '/privatekey/user/' + privkey.userId + '/key/' + privkey._id;
|
||||
$.ajax({
|
||||
url: uri,
|
||||
type: 'PUT',
|
||||
data: JSON.stringify(privkey),
|
||||
contentType: 'application/json',
|
||||
success: function() {
|
||||
callback();
|
||||
},
|
||||
error: function(xhr, textStatus, err) {
|
||||
callback({
|
||||
error: err,
|
||||
status: textStatus
|
||||
});
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Delete the private key from the cloud storage service
|
||||
*/
|
||||
this.removePrivateKey = function(keyId, callback) {
|
||||
var uri = app.config.cloudUrl + '/privatekey/key/' + keyId;
|
||||
this.remove(uri, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -180,32 +193,24 @@ app.dao.CloudStorage = function(window, $) {
|
||||
gottenKey, uri;
|
||||
|
||||
uri = app.config.cloudUrl + '/privatekey/user/' + emailAddress;
|
||||
$.ajax({
|
||||
url: uri,
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(keys) {
|
||||
if (!keys) {
|
||||
callback({
|
||||
error: 'err',
|
||||
status: 'Key not synced!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// use first key, if it exists
|
||||
if (keys.length > 0) {
|
||||
gottenKey = keys[0];
|
||||
}
|
||||
|
||||
handleKey(gottenKey, callback);
|
||||
},
|
||||
error: function(xhr, textStatus, err) {
|
||||
callback({
|
||||
error: err,
|
||||
status: textStatus
|
||||
});
|
||||
self.get(uri, function(err, keys) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if (!keys) {
|
||||
callback({
|
||||
errMsg: 'Key not synced!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// use first key, if it exists
|
||||
if (keys.length > 0) {
|
||||
gottenKey = keys[0];
|
||||
}
|
||||
|
||||
handleKey(gottenKey, callback);
|
||||
});
|
||||
|
||||
function handleKey(fetchedKey, callback) {
|
||||
|
@ -19,12 +19,12 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
||||
});
|
||||
|
||||
_.each(ids, function(i) {
|
||||
// try to read public key from local storage
|
||||
jsonDao.read('publickey_' + i._id, function(pubkey) {
|
||||
if (!pubkey) {
|
||||
// TODO: fetch from cloud storage
|
||||
// lookup locally and in storage
|
||||
lookupPublicKey(i._id, function(err, pubkey) {
|
||||
if (err || !pubkey) {
|
||||
callback({
|
||||
errMsg: 'Not implemented yet!'
|
||||
errMsg: 'Error looking up public key!',
|
||||
err: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -43,6 +43,37 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function that looks for public key in local storage
|
||||
* and then in cloud storage
|
||||
*/
|
||||
|
||||
function lookupPublicKey(id, callback) {
|
||||
// lookup in local storage
|
||||
jsonDao.read('publickey_' + id, function(pubkey) {
|
||||
if (!pubkey) {
|
||||
// fetch from cloud storage
|
||||
cloudstorage.getPublicKey(id, callback);
|
||||
|
||||
} else {
|
||||
callback(null, pubkey);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function lookupPrivateKey(id, callback) {
|
||||
// lookup in local storage
|
||||
jsonDao.read('privatekey_' + id, function(privkey) {
|
||||
if (!privkey) {
|
||||
// fetch from cloud storage
|
||||
cloudstorage.getPrivateKey(id, callback);
|
||||
|
||||
} else {
|
||||
callback(null, privkey);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the local user's key either from local storage
|
||||
* or fetches it from the cloud. The private key is encrypted.
|
||||
@ -53,15 +84,23 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
||||
// lookup public key id
|
||||
jsonDao.read('publickey_' + userId, function(pubkeyId) {
|
||||
if (!pubkeyId || !pubkeyId._id) {
|
||||
// no public key in storage
|
||||
// TODO: fetch from cloud
|
||||
// no public key by that id in storage
|
||||
// TODO: find from cloud
|
||||
// TODO: persist in local storage
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
// try to read public key from local storage
|
||||
jsonDao.read('publickey_' + pubkeyId._id, function(pubkey) {
|
||||
// lookup public key in storage and cloud
|
||||
lookupPublicKey(pubkeyId._id, function(err, pubkey) {
|
||||
if (err || !pubkey) {
|
||||
callback({
|
||||
errMsg: 'Error looking up public key!',
|
||||
err: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// public key found
|
||||
// get corresponding private key
|
||||
fetchEncryptedPrivateKey(pubkey);
|
||||
@ -70,21 +109,20 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
||||
|
||||
function fetchEncryptedPrivateKey(publicKey) {
|
||||
// try to read private key from local storage
|
||||
jsonDao.read('privatekey_' + publicKey._id, function(privkey) {
|
||||
if (!privkey) {
|
||||
// no private key in storage
|
||||
// TODO: fetch from cloud
|
||||
// TODO: persist in local storage
|
||||
lookupPrivateKey(publicKey._id, function(err, privkey) {
|
||||
if (err || !privkey) {
|
||||
callback({
|
||||
errMsg: 'Not implemented yet!'
|
||||
});
|
||||
} else {
|
||||
// private key found
|
||||
callback(null, {
|
||||
publicKey: publicKey,
|
||||
privateKey: privkey
|
||||
errMsg: 'Error looking up private key!',
|
||||
err: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// private key found
|
||||
callback(null, {
|
||||
publicKey: publicKey,
|
||||
privateKey: privkey
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -103,8 +141,6 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: persist in the cloud
|
||||
|
||||
// persist public key (email, _id)
|
||||
var pkLookupKey = 'publickey_' + keypair.publicKey.userId;
|
||||
jsonDao.persist(pkLookupKey, {
|
||||
@ -113,47 +149,68 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
||||
// validate result
|
||||
if (res1.key !== pkLookupKey) {
|
||||
callback({
|
||||
errMsg: 'Persisting went wrong!'
|
||||
errMsg: 'Persisting public key in local storage went wrong!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// persist public key
|
||||
// persist public key in local storage
|
||||
var pkKey = 'publickey_' + keypair.publicKey._id;
|
||||
jsonDao.persist(pkKey, keypair.publicKey, function(res2) {
|
||||
// validate result
|
||||
if (res2.key !== pkKey) {
|
||||
callback({
|
||||
errMsg: 'Persisting went wrong!'
|
||||
errMsg: 'Persisting public key in local storage went wrong!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// persist public key (email, _id)
|
||||
var prkLookupKey = 'privatekey_' + keypair.privateKey.userId;
|
||||
jsonDao.persist(prkLookupKey, {
|
||||
_id: keypair.privateKey._id
|
||||
}, function(res3) {
|
||||
// perist in public key in cloud storage
|
||||
cloudstorage.putPublicKey(keypair.publicKey, function(err) {
|
||||
// validate result
|
||||
if (res3.key !== prkLookupKey) {
|
||||
if (err) {
|
||||
callback({
|
||||
errMsg: 'Persisting went wrong!'
|
||||
errMsg: 'Persisting public key in cloud storage went wrong!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// persist private key
|
||||
var prkKey = 'privatekey_' + keypair.privateKey._id;
|
||||
jsonDao.persist(prkKey, keypair.privateKey, function(res4) {
|
||||
// persist private key (email, _id)
|
||||
var prkLookupKey = 'privatekey_' + keypair.privateKey.userId;
|
||||
jsonDao.persist(prkLookupKey, {
|
||||
_id: keypair.privateKey._id
|
||||
}, function(res3) {
|
||||
// validate result
|
||||
if (res4.key !== prkKey) {
|
||||
if (res3.key !== prkLookupKey) {
|
||||
callback({
|
||||
errMsg: 'Persisting went wrong!'
|
||||
errMsg: 'Persisting private key in local storage went wrong!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null);
|
||||
// persist private key
|
||||
var prkKey = 'privatekey_' + keypair.privateKey._id;
|
||||
jsonDao.persist(prkKey, keypair.privateKey, function(res4) {
|
||||
// validate result
|
||||
if (res4.key !== prkKey) {
|
||||
callback({
|
||||
errMsg: 'Persisting private key in local storage went wrong!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
cloudstorage.putPrivateKey(keypair.privateKey, function(err) {
|
||||
// validate result
|
||||
if (err) {
|
||||
callback({
|
||||
errMsg: 'Persisting private key in cloud storage went wrong!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -2,20 +2,43 @@ module("CloudStorage DAO");
|
||||
|
||||
var cloudstoragedao_test = {
|
||||
user: 'email.dao.it.test@mail.whiteout.io',
|
||||
password: 'hellosafe',
|
||||
password: 'Xoza76645',
|
||||
keySize: 128,
|
||||
ivSize: 128,
|
||||
rsaKeySize: 1024
|
||||
};
|
||||
|
||||
asyncTest("Init", 1, function() {
|
||||
|
||||
// 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: "zXBmmR7fz6sfR0AIeOzvwKOb6BrBQBgyweJ4c0LZS9h7C18SgPSMcvpSgBIwJadi577DPmwfXPl6zCNtwoqlLqD6xdS6P/bDY6rIWbaGbRrWzs/KXJ7UjWq0uyZSUFQK8w/woHkyQ4eLqdwj+duPZzrerDyi1XX8XXCcNDpDwR+1L2TxWlDzShN7IiA4OUeFsDbgqN3lKUBSHw5USnassv7nRwWlSNWPVaIlx3YT2T/VIaNoBbX5jDDwhDT4h/1fOOEbxTIBEN65mGGNW9GPLbi/PVgKibrF6l8bHwW5FjIkoYZdzgPe5nowhbFb2FB7mWX4gXMzqT3wuOP9fCOCEj4muxYkV7daedAGFRKl5mTPd9Cu+vSY+SnZX55m1yXQixn55J50AgW+aY/LXV+UqYwVObp7o5qs0B+OhQIRxH2Sp6IjRRFAqsQgBoRXS1qWPLCGVLMoSUkOSOCQd6rsr70fGXxGpguJFigAMWDXAzuPH98UFaB7kCiohhFLZ25vMhd/cOz1MXTKKPQJXfpBr8uX/hhhdsZReVfqLFKpvs1MzdFoV6FiTwZwyDyRnANYRHnqnP148q5s0JOkFcHaHqYdbLvVU6jm/B3QYJ/IO/uKyHoIhVobSSUBLzLDV0Eila9LhCdfWVXIVfFNUr5ut1YyOoJ23G5ItBSq5VFaZv79lNIhWjw/effq1IJd4eKeBe2X2DoYv85FZifAf/kUN38g0rTfAmKedsTGGhMLo+3Aa12MzRF93aTOMyKpHSA0G/5dA5PSVSlgDd/hwn4AlKzfo8M2PF1fh+9q5YtWqs4+mSOmyvYKxg9g+ZBhAvHbVBUN2emoNoJTC6JToB9jeRvksl1iehx+3C8nHUzXsxqApA3a79RJ+izRT2f0GguEAlAz4B6EozFRJwjNyRL2Fe7bgtadJxTNZfcG+oCgCFNCOyOvSgcpkjvj2DlFdPvw5BXXodV5D0jIg+OnszWcgLUDLFMkPPJgYrx9smRqdPjFnjWvnm6bRVZbxaU+FXKFvplmOG3XK1sR9g91bg5nnKDHRf6OuwBBgX0AyzOz2ohO3NVuIcppHjecUEY8t9QgezGal/R1PepW/uNPn/zJgGthTb4rK/KrXZTEsvC3XI55VlSnhORfNJvjn5Up/iusKeKXEGb/lhyc058GZY5UCmoIsV30TYgzXeuj6VZBEtcvAvza0mYmGvXf91ebVZR+",
|
||||
iv: "XE4c3X134YNkapbeSXP6GA=="
|
||||
}
|
||||
};
|
||||
|
||||
// init dependencies
|
||||
cloudstoragedao_test.util = new cryptoLib.Util(window, uuid);
|
||||
var jsonDao = new app.dao.LawnchairDAO(window);
|
||||
var jsonDao = new app.dao.LawnchairDAO(Lawnchair);
|
||||
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);
|
||||
cloudstoragedao_test.cloudstorage = new app.dao.CloudStorage(window, $);
|
||||
cloudstoragedao_test.emailDao = new app.dao.EmailDAO(_, cloudstoragedao_test.crypto, cloudstoragedao_test.storage, cloudstoragedao_test.cloudstorage, cloudstoragedao_test.util);
|
||||
cloudstoragedao_test.keychain = new app.dao.KeychainDAO(jsonDao, cloudstoragedao_test.cloudstorage);
|
||||
cloudstoragedao_test.emailDao = new app.dao.EmailDAO(_, cloudstoragedao_test.crypto, cloudstoragedao_test.storage, cloudstoragedao_test.cloudstorage, cloudstoragedao_test.util, cloudstoragedao_test.keychain);
|
||||
|
||||
// clear db before tests
|
||||
jsonDao.clear(function(err) {
|
||||
@ -25,39 +48,8 @@ asyncTest("Init", 1, function() {
|
||||
});
|
||||
});
|
||||
|
||||
asyncTest("Persist public key to cloud", 1, function() {
|
||||
|
||||
// testdata
|
||||
cloudstoragedao_test.privateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n" +
|
||||
"MIICXAIBAAKBgQDK6H7BiPcwiRWnWDuqndw+t+3vIhSmwEEn38kPLenbd+iWb2dX\r\n" +
|
||||
"M5y5aBFIgqqHBrcZLwzhMQ10BUTcOgB6Kr3AK7lONKxZ+HD5hX6koj9X5uHtFYF1\r\n" +
|
||||
"NYkQv+5WKzHGHRFqoKityZ6AqTxgPss29s6EIOqF/dvvKMiFhgp+4JPsJQIDAQAB\r\n" +
|
||||
"AoGAQxIM7C44/zshBDrfJiueJMEpjhUm3GPKZcLMNA9KMPh20lsqvqFZ2dNzexNu\r\n" +
|
||||
"CMoIdfOef0V2m/Yt59noVHmSVL7itN4nvbTcD39UQacFiyzT7GRQjeaVAs8ZyeO5\r\n" +
|
||||
"2AXtJTNipEyvJ3TbJZCOCML/wOEvCimyHLNCMcoDvkjAbMECQQD81xbRonOZt/7E\r\n" +
|
||||
"fBHZQonaTQU/x88l8bXDHvcPfMfg4QkPO+pZ8dBQ4+IpuG60kl4TSmmme4frcJoj\r\n" +
|
||||
"jSqd54VVAkEAzXGon2gP+9ZjhbOWESpw+JXiRBytAgailnblFnCJt+o+UoXU8hwH\r\n" +
|
||||
"1D5rG2yOIO1vOiqGDQq/Bs61DsfeotvLkQJBAKo6tmZWFba9Jo5raij4n4+Wo54Z\r\n" +
|
||||
"jOJjJplEU9rdjEVfvZXAJTyBjlun0jF8tyxkD2q1gwRPz2c43M5q0PKXWjECQCl4\r\n" +
|
||||
"UO5khh1yyEIb3yX16Dn1n2faVf37suQmedXOv631RcFIrJR2ngn005AEmKgC5Znb\r\n" +
|
||||
"LZYCXk8UeK3UIJfFQFECQGkP1NPyd10Z76LR0lXeL15iP22M/OCaQUIsSi/S+idL\r\n" +
|
||||
"YCVcgDpdgVXef0NeNk6w821rlqUjseZyGGKpJ4VNywU=\r\n" +
|
||||
"-----END RSA PRIVATE KEY-----";
|
||||
|
||||
var pk = "-----BEGIN PUBLIC KEY-----\r\n" +
|
||||
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDK6H7BiPcwiRWnWDuqndw+t+3v\r\n" +
|
||||
"IhSmwEEn38kPLenbd+iWb2dXM5y5aBFIgqqHBrcZLwzhMQ10BUTcOgB6Kr3AK7lO\r\n" +
|
||||
"NKxZ+HD5hX6koj9X5uHtFYF1NYkQv+5WKzHGHRFqoKityZ6AqTxgPss29s6EIOqF\r\n" +
|
||||
"/dvvKMiFhgp+4JPsJQIDAQAB\r\n" +
|
||||
"-----END PUBLIC KEY-----";
|
||||
|
||||
cloudstoragedao_test.publicKey = new app.model.PublicKey({
|
||||
_id: "e91f04a2-a634-42df-a1a4-6a7f1448dbf6",
|
||||
userId: 'integration@atlasdev.onmicrosoft.com',
|
||||
publicKey: pk
|
||||
});
|
||||
|
||||
cloudstoragedao_test.cloudstorage.putPublicKey(cloudstoragedao_test.publicKey.toJSON(), function(err) {
|
||||
asyncTest("Put public key to cloud", 1, function() {
|
||||
cloudstoragedao_test.cloudstorage.putPublicKey(cloudstoragedao_test.keypair.publicKey, function(err) {
|
||||
ok(!err, 'Persist key to cloud');
|
||||
|
||||
start();
|
||||
@ -65,76 +57,133 @@ asyncTest("Persist public key to cloud", 1, function() {
|
||||
});
|
||||
|
||||
asyncTest("Get Public key from cloud", 2, function() {
|
||||
cloudstoragedao_test.cloudstorage.getPublicKey(cloudstoragedao_test.publicKey.get('_id'), function(err, data) {
|
||||
cloudstoragedao_test.cloudstorage.getPublicKey(cloudstoragedao_test.keypair.publicKey._id, function(err, data) {
|
||||
ok(!err && data && data.publicKey, 'Get public key from cloud');
|
||||
deepEqual(data, cloudstoragedao_test.publicKey.toJSON(), 'Public key is equal');
|
||||
deepEqual(data, cloudstoragedao_test.keypair.publicKey, 'Public key is equal');
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
asyncTest("Sync private key from cloud", 1, function() {
|
||||
cloudstoragedao_test.cloudstorage.syncPrivateKey(cloudstoragedao_test.user, null, function(err) {
|
||||
ok(!err, 'Get/Sync key from cloud');
|
||||
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');
|
||||
|
||||
start();
|
||||
}, function(fetchedKey) {
|
||||
// replace local key with cloud key
|
||||
cloudstoragedao_test.crypto.putEncryptedPrivateKey(fetchedKey);
|
||||
// whipe local storage
|
||||
cloudstoragedao_test.storage.clear(function(err) {
|
||||
ok(!err, 'DB cleared. Error status: ' + err);
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
asyncTest("Persist private key to cloud", 1, function() {
|
||||
var storedKey = cloudstoragedao_test.crypto.getEncryptedPrivateKey(cloudstoragedao_test.user);
|
||||
// asyncTest("Sync private key from cloud", 1, function() {
|
||||
// cloudstoragedao_test.cloudstorage.syncPrivateKey(cloudstoragedao_test.user, null, function(err) {
|
||||
// ok(!err, 'Get/Sync key from cloud');
|
||||
|
||||
cloudstoragedao_test.cloudstorage.putPrivateKey(storedKey, function(err) {
|
||||
// start();
|
||||
// }, function(fetchedKey) {
|
||||
// // replace local key with cloud key
|
||||
// cloudstoragedao_test.crypto.putEncryptedPrivateKey(fetchedKey);
|
||||
// // whipe local storage
|
||||
// cloudstoragedao_test.storage.clear(function(err) {
|
||||
// ok(!err, 'DB cleared. Error status: ' + err);
|
||||
|
||||
// start();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
asyncTest("Put private key to cloud", 1, function() {
|
||||
cloudstoragedao_test.cloudstorage.putPrivateKey(cloudstoragedao_test.keypair.privateKey, function(err) {
|
||||
ok(!err, 'Persist key to cloud');
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
module("Keychain DAO");
|
||||
|
||||
asyncTest("Put User Keypair", 1, function() {
|
||||
cloudstoragedao_test.keychain.putUserKeyPair(cloudstoragedao_test.keypair, function(err) {
|
||||
ok(!err);
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
asyncTest("Get User Keypair", 2, function() {
|
||||
cloudstoragedao_test.keychain.getUserKeyPair(cloudstoragedao_test.user, function(err, keypair) {
|
||||
ok(!err);
|
||||
ok(keypair && keypair.publicKey && keypair.privateKey);
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
asyncTest("Get Public Keys", 2, function() {
|
||||
var pubkeyIds = [{
|
||||
_id: cloudstoragedao_test.keypair.publicKey._id
|
||||
}];
|
||||
cloudstoragedao_test.keychain.getPublicKeys(pubkeyIds, function(err, pubkeys) {
|
||||
ok(!err);
|
||||
deepEqual(pubkeys[0], cloudstoragedao_test.keypair.publicKey, "Fetch public key");
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
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() {
|
||||
// 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
|
||||
});
|
||||
// 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
|
||||
// });
|
||||
|
||||
cloudstoragedao_test.emailDao.sendEmail(email, function(err) {
|
||||
ok(!err, 'Email sent');
|
||||
// cloudstoragedao_test.emailDao.sendEmail(email, function(err) {
|
||||
// ok(!err, 'Email sent');
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
// start();
|
||||
// });
|
||||
// });
|
||||
|
||||
// asyncTest("Check virtual inbox, re-encrypt and push to cloud", 1, function() {
|
||||
// cloudstoragedao_test.emailDao.checkVInbox(function(err) {
|
||||
@ -144,20 +193,20 @@ asyncTest("Send Plaintext Email item", 1, function() {
|
||||
// });
|
||||
// });
|
||||
|
||||
asyncTest("Sync emails from cloud", 1, function() {
|
||||
cloudstoragedao_test.emailDao.syncFromCloud('inbox', function(err) {
|
||||
ok(!err, 'Synced items');
|
||||
// asyncTest("Sync emails from cloud", 1, function() {
|
||||
// cloudstoragedao_test.emailDao.syncFromCloud('inbox', function(err) {
|
||||
// ok(!err, 'Synced items');
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
// start();
|
||||
// });
|
||||
// });
|
||||
|
||||
asyncTest("List emails from cloud", 3, function() {
|
||||
// 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');
|
||||
// cloudstoragedao_test.emailDao.listItems('inbox', 0, null, function(err, collection) {
|
||||
// ok(!err);
|
||||
// ok(collection.length > 0, 'Read synced items');
|
||||
|
||||
start();
|
||||
});
|
||||
});
|
||||
// start();
|
||||
// });
|
||||
// });
|
@ -48,6 +48,7 @@
|
||||
<script src="../../src/js/dao/lawnchair-dao.js"></script>
|
||||
<script src="../../src/js/dao/devicestorage.js"></script>
|
||||
<script src="../../src/js/dao/cloudstorage-dao.js"></script>
|
||||
<script src="../../src/js/dao/keychain-dao.js"></script>
|
||||
<script src="../../src/js/dao/email-dao.js"></script>
|
||||
|
||||
<!-- tests -->
|
||||
|
@ -16,10 +16,10 @@ asyncTest("Init", 3, function() {
|
||||
emaildao_test.storage = new app.dao.DeviceStorage(util, emaildao_test.crypto, jsonDao, null);
|
||||
// cloud storage stub
|
||||
var cloudstorageStub = {
|
||||
syncPrivateKey: function(emailAdress, storedKey, callback) {
|
||||
putPublicKey: function(pk, callback) {
|
||||
callback();
|
||||
},
|
||||
putPublicKey: function(pk, callback) {
|
||||
putPrivateKey: function(prk, callback) {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
@ -15,10 +15,10 @@ asyncTest("Init", 2, function() {
|
||||
var crypto = new app.crypto.Crypto(window, util);
|
||||
// cloud storage stub
|
||||
var cloudstorageStub = {
|
||||
syncPrivateKey: function(emailAdress, storedKey, callback) {
|
||||
putPublicKey: function(pk, callback) {
|
||||
callback();
|
||||
},
|
||||
putPublicKey: function(pk, callback) {
|
||||
putPrivateKey: function(prk, callback) {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user