mirror of
https://github.com/moparisthebest/mail
synced 2025-02-27 08:11:44 -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';
|
'use strict';
|
||||||
|
|
||||||
//
|
//
|
||||||
// Public Key
|
// Generic Ajax helper functions
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the user's corresponding public key
|
* GET (read) request
|
||||||
*/
|
*/
|
||||||
this.getPublicKey = function(keyId, callback) {
|
this.get = function(uri, callback) {
|
||||||
var uri;
|
|
||||||
|
|
||||||
uri = app.config.cloudUrl + '/publickey/key/' + keyId;
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: uri,
|
url: uri,
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(key) {
|
success: function(res) {
|
||||||
if (!key || !key._id) {
|
callback(null, res);
|
||||||
callback({
|
|
||||||
error: 'No public key for that user!'
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null, key);
|
|
||||||
},
|
},
|
||||||
error: function(xhr, textStatus, err) {
|
error: function(xhr, textStatus, err) {
|
||||||
callback({
|
callback({
|
||||||
error: err,
|
errMsg: xhr.status + ': ' + xhr.statusText
|
||||||
status: textStatus
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persist the user's publc key
|
* PUT (update) request
|
||||||
*/
|
*/
|
||||||
this.putPublicKey = function(pubkey, callback) {
|
this.put = function(item, uri, callback) {
|
||||||
var uri;
|
|
||||||
|
|
||||||
uri = app.config.cloudUrl + '/publickey/user/' + pubkey.userId + '/key/' + pubkey._id;
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: uri,
|
url: uri,
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
data: JSON.stringify(pubkey),
|
data: JSON.stringify(item),
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
success: function() {
|
success: function() {
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
error: function(xhr, textStatus, err) {
|
error: function(xhr, textStatus, err) {
|
||||||
callback({
|
callback({
|
||||||
error: err,
|
errMsg: xhr.status + ': ' + xhr.statusText
|
||||||
status: textStatus
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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'
|
* @param type [String] The type of item e.g. 'email'
|
||||||
*/
|
*/
|
||||||
this.putEncryptedItem = function(item, type, emailAddress, folderName, callback) {
|
this.putEncryptedItem = function(item, type, emailAddress, folderName, callback) {
|
||||||
var uri;
|
var uri = app.config.cloudUrl + '/' + type + '/user/' + emailAddress + '/folder/' + folderName + '/' + item.id;
|
||||||
|
this.put(item, uri, callback);
|
||||||
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
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,22 +84,8 @@ app.dao.CloudStorage = function(window, $) {
|
|||||||
* @param type [String] The type of item e.g. 'email'
|
* @param type [String] The type of item e.g. 'email'
|
||||||
*/
|
*/
|
||||||
this.deleteEncryptedItem = function(id, type, emailAddress, folderName, callback) {
|
this.deleteEncryptedItem = function(id, type, emailAddress, folderName, callback) {
|
||||||
var uri;
|
var uri = app.config.cloudUrl + '/' + type + '/user/' + emailAddress + '/folder/' + folderName + '/' + id;
|
||||||
|
this.remove(uri, callback);
|
||||||
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
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,53 +95,93 @@ app.dao.CloudStorage = function(window, $) {
|
|||||||
* @param num [Number] The number of items to fetch (null means fetch all)
|
* @param num [Number] The number of items to fetch (null means fetch all)
|
||||||
*/
|
*/
|
||||||
this.listEncryptedItems = function(type, emailAddress, folderName, callback) {
|
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;
|
// Public Key
|
||||||
$.ajax({
|
//
|
||||||
url: uri,
|
|
||||||
type: 'GET',
|
/**
|
||||||
dataType: 'json',
|
* Find the user's corresponding public key
|
||||||
success: function(list) {
|
*/
|
||||||
callback(null, list);
|
this.getPublicKey = function(keyId, callback) {
|
||||||
},
|
var uri = app.config.cloudUrl + '/publickey/key/' + keyId;
|
||||||
error: function(xhr, textStatus, err) {
|
|
||||||
callback({
|
this.get(uri, function(err, key) {
|
||||||
error: err,
|
if (err) {
|
||||||
status: textStatus
|
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
|
// 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
|
* Persist encrypted private key to cloud service
|
||||||
*/
|
*/
|
||||||
this.putPrivateKey = function(privkey, callback) {
|
this.putPrivateKey = function(privkey, callback) {
|
||||||
// fetch user's encrypted secret key from keychain/storage
|
var uri = app.config.cloudUrl + '/privatekey/user/' + privkey.userId + '/key/' + privkey._id;
|
||||||
var uri;
|
this.put(privkey, uri, callback);
|
||||||
|
};
|
||||||
|
|
||||||
uri = app.config.cloudUrl + '/privatekey/user/' + privkey.userId + '/key/' + privkey._id;
|
/**
|
||||||
$.ajax({
|
* Delete the private key from the cloud storage service
|
||||||
url: uri,
|
*/
|
||||||
type: 'PUT',
|
this.removePrivateKey = function(keyId, callback) {
|
||||||
data: JSON.stringify(privkey),
|
var uri = app.config.cloudUrl + '/privatekey/key/' + keyId;
|
||||||
contentType: 'application/json',
|
this.remove(uri, callback);
|
||||||
success: function() {
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
error: function(xhr, textStatus, err) {
|
|
||||||
callback({
|
|
||||||
error: err,
|
|
||||||
status: textStatus
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -180,15 +193,14 @@ app.dao.CloudStorage = function(window, $) {
|
|||||||
gottenKey, uri;
|
gottenKey, uri;
|
||||||
|
|
||||||
uri = app.config.cloudUrl + '/privatekey/user/' + emailAddress;
|
uri = app.config.cloudUrl + '/privatekey/user/' + emailAddress;
|
||||||
$.ajax({
|
self.get(uri, function(err, keys) {
|
||||||
url: uri,
|
if (err) {
|
||||||
type: 'GET',
|
callback(err);
|
||||||
dataType: 'json',
|
return;
|
||||||
success: function(keys) {
|
}
|
||||||
if (!keys) {
|
if (!keys) {
|
||||||
callback({
|
callback({
|
||||||
error: 'err',
|
errMsg: 'Key not synced!'
|
||||||
status: 'Key not synced!'
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -199,13 +211,6 @@ app.dao.CloudStorage = function(window, $) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleKey(gottenKey, callback);
|
handleKey(gottenKey, callback);
|
||||||
},
|
|
||||||
error: function(xhr, textStatus, err) {
|
|
||||||
callback({
|
|
||||||
error: err,
|
|
||||||
status: textStatus
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleKey(fetchedKey, callback) {
|
function handleKey(fetchedKey, callback) {
|
||||||
|
@ -19,12 +19,12 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_.each(ids, function(i) {
|
_.each(ids, function(i) {
|
||||||
// try to read public key from local storage
|
// lookup locally and in storage
|
||||||
jsonDao.read('publickey_' + i._id, function(pubkey) {
|
lookupPublicKey(i._id, function(err, pubkey) {
|
||||||
if (!pubkey) {
|
if (err || !pubkey) {
|
||||||
// TODO: fetch from cloud storage
|
|
||||||
callback({
|
callback({
|
||||||
errMsg: 'Not implemented yet!'
|
errMsg: 'Error looking up public key!',
|
||||||
|
err: err
|
||||||
});
|
});
|
||||||
return;
|
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
|
* Gets the local user's key either from local storage
|
||||||
* or fetches it from the cloud. The private key is encrypted.
|
* 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
|
// lookup public key id
|
||||||
jsonDao.read('publickey_' + userId, function(pubkeyId) {
|
jsonDao.read('publickey_' + userId, function(pubkeyId) {
|
||||||
if (!pubkeyId || !pubkeyId._id) {
|
if (!pubkeyId || !pubkeyId._id) {
|
||||||
// no public key in storage
|
// no public key by that id in storage
|
||||||
// TODO: fetch from cloud
|
// TODO: find from cloud
|
||||||
// TODO: persist in local storage
|
// TODO: persist in local storage
|
||||||
callback();
|
callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to read public key from local storage
|
// lookup public key in storage and cloud
|
||||||
jsonDao.read('publickey_' + pubkeyId._id, function(pubkey) {
|
lookupPublicKey(pubkeyId._id, function(err, pubkey) {
|
||||||
|
if (err || !pubkey) {
|
||||||
|
callback({
|
||||||
|
errMsg: 'Error looking up public key!',
|
||||||
|
err: err
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// public key found
|
// public key found
|
||||||
// get corresponding private key
|
// get corresponding private key
|
||||||
fetchEncryptedPrivateKey(pubkey);
|
fetchEncryptedPrivateKey(pubkey);
|
||||||
@ -70,21 +109,20 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
|||||||
|
|
||||||
function fetchEncryptedPrivateKey(publicKey) {
|
function fetchEncryptedPrivateKey(publicKey) {
|
||||||
// try to read private key from local storage
|
// try to read private key from local storage
|
||||||
jsonDao.read('privatekey_' + publicKey._id, function(privkey) {
|
lookupPrivateKey(publicKey._id, function(err, privkey) {
|
||||||
if (!privkey) {
|
if (err || !privkey) {
|
||||||
// no private key in storage
|
|
||||||
// TODO: fetch from cloud
|
|
||||||
// TODO: persist in local storage
|
|
||||||
callback({
|
callback({
|
||||||
errMsg: 'Not implemented yet!'
|
errMsg: 'Error looking up private key!',
|
||||||
|
err: err
|
||||||
});
|
});
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// private key found
|
// private key found
|
||||||
callback(null, {
|
callback(null, {
|
||||||
publicKey: publicKey,
|
publicKey: publicKey,
|
||||||
privateKey: privkey
|
privateKey: privkey
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -103,8 +141,6 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: persist in the cloud
|
|
||||||
|
|
||||||
// persist public key (email, _id)
|
// persist public key (email, _id)
|
||||||
var pkLookupKey = 'publickey_' + keypair.publicKey.userId;
|
var pkLookupKey = 'publickey_' + keypair.publicKey.userId;
|
||||||
jsonDao.persist(pkLookupKey, {
|
jsonDao.persist(pkLookupKey, {
|
||||||
@ -113,23 +149,33 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
|||||||
// validate result
|
// validate result
|
||||||
if (res1.key !== pkLookupKey) {
|
if (res1.key !== pkLookupKey) {
|
||||||
callback({
|
callback({
|
||||||
errMsg: 'Persisting went wrong!'
|
errMsg: 'Persisting public key in local storage went wrong!'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// persist public key
|
// persist public key in local storage
|
||||||
var pkKey = 'publickey_' + keypair.publicKey._id;
|
var pkKey = 'publickey_' + keypair.publicKey._id;
|
||||||
jsonDao.persist(pkKey, keypair.publicKey, function(res2) {
|
jsonDao.persist(pkKey, keypair.publicKey, function(res2) {
|
||||||
// validate result
|
// validate result
|
||||||
if (res2.key !== pkKey) {
|
if (res2.key !== pkKey) {
|
||||||
callback({
|
callback({
|
||||||
errMsg: 'Persisting went wrong!'
|
errMsg: 'Persisting public key in local storage went wrong!'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// persist public key (email, _id)
|
// perist in public key in cloud storage
|
||||||
|
cloudstorage.putPublicKey(keypair.publicKey, function(err) {
|
||||||
|
// validate result
|
||||||
|
if (err) {
|
||||||
|
callback({
|
||||||
|
errMsg: 'Persisting public key in cloud storage went wrong!'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// persist private key (email, _id)
|
||||||
var prkLookupKey = 'privatekey_' + keypair.privateKey.userId;
|
var prkLookupKey = 'privatekey_' + keypair.privateKey.userId;
|
||||||
jsonDao.persist(prkLookupKey, {
|
jsonDao.persist(prkLookupKey, {
|
||||||
_id: keypair.privateKey._id
|
_id: keypair.privateKey._id
|
||||||
@ -137,7 +183,7 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
|||||||
// validate result
|
// validate result
|
||||||
if (res3.key !== prkLookupKey) {
|
if (res3.key !== prkLookupKey) {
|
||||||
callback({
|
callback({
|
||||||
errMsg: 'Persisting went wrong!'
|
errMsg: 'Persisting private key in local storage went wrong!'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -148,7 +194,16 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
|||||||
// validate result
|
// validate result
|
||||||
if (res4.key !== prkKey) {
|
if (res4.key !== prkKey) {
|
||||||
callback({
|
callback({
|
||||||
errMsg: 'Persisting went wrong!'
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@ -158,6 +213,8 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
@ -2,20 +2,43 @@ module("CloudStorage DAO");
|
|||||||
|
|
||||||
var cloudstoragedao_test = {
|
var cloudstoragedao_test = {
|
||||||
user: 'email.dao.it.test@mail.whiteout.io',
|
user: 'email.dao.it.test@mail.whiteout.io',
|
||||||
password: 'hellosafe',
|
password: 'Xoza76645',
|
||||||
keySize: 128,
|
keySize: 128,
|
||||||
ivSize: 128,
|
ivSize: 128,
|
||||||
rsaKeySize: 1024
|
rsaKeySize: 1024
|
||||||
};
|
};
|
||||||
|
|
||||||
asyncTest("Init", 1, function() {
|
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
|
// init dependencies
|
||||||
cloudstoragedao_test.util = new cryptoLib.Util(window, uuid);
|
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.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.storage = new app.dao.DeviceStorage(cloudstoragedao_test.util, cloudstoragedao_test.crypto, jsonDao, null);
|
||||||
cloudstoragedao_test.cloudstorage = new app.dao.CloudStorage(window, $);
|
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
|
// clear db before tests
|
||||||
jsonDao.clear(function(err) {
|
jsonDao.clear(function(err) {
|
||||||
@ -25,39 +48,8 @@ asyncTest("Init", 1, function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("Persist public key to cloud", 1, function() {
|
asyncTest("Put public key to cloud", 1, function() {
|
||||||
|
cloudstoragedao_test.cloudstorage.putPublicKey(cloudstoragedao_test.keypair.publicKey, function(err) {
|
||||||
// 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) {
|
|
||||||
ok(!err, 'Persist key to cloud');
|
ok(!err, 'Persist key to cloud');
|
||||||
|
|
||||||
start();
|
start();
|
||||||
@ -65,76 +57,133 @@ asyncTest("Persist public key to cloud", 1, function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("Get Public key from cloud", 2, 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');
|
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();
|
start();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("Sync private key from cloud", 1, function() {
|
asyncTest("Delete Public key from cloud", 1, function() {
|
||||||
cloudstoragedao_test.cloudstorage.syncPrivateKey(cloudstoragedao_test.user, null, function(err) {
|
cloudstoragedao_test.cloudstorage.removePublicKey(cloudstoragedao_test.keypair.publicKey._id, function(err) {
|
||||||
ok(!err, 'Get/Sync key from cloud');
|
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();
|
start();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
asyncTest("Persist private key to cloud", 1, function() {
|
// asyncTest("Sync private key from cloud", 1, function() {
|
||||||
var storedKey = cloudstoragedao_test.crypto.getEncryptedPrivateKey(cloudstoragedao_test.user);
|
// 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');
|
ok(!err, 'Persist key to cloud');
|
||||||
|
|
||||||
start();
|
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");
|
module("Email DAO");
|
||||||
|
|
||||||
asyncTest("Init", 1, function() {
|
// asyncTest("Init", 1, function() {
|
||||||
|
|
||||||
var account = new app.model.Account({
|
// var account = new app.model.Account({
|
||||||
emailAddress: cloudstoragedao_test.user,
|
// emailAddress: cloudstoragedao_test.user,
|
||||||
symKeySize: cloudstoragedao_test.keySize,
|
// symKeySize: cloudstoragedao_test.keySize,
|
||||||
symIvSize: cloudstoragedao_test.ivSize,
|
// symIvSize: cloudstoragedao_test.ivSize,
|
||||||
asymKeySize: cloudstoragedao_test.rsaKeySize
|
// asymKeySize: cloudstoragedao_test.rsaKeySize
|
||||||
});
|
// });
|
||||||
|
|
||||||
cloudstoragedao_test.emailDao.init(account, cloudstoragedao_test.password, function(err) {
|
// cloudstoragedao_test.emailDao.init(account, cloudstoragedao_test.password, function(err) {
|
||||||
ok(!err, 'Init complete');
|
// 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({
|
// var email = new app.model.Email({
|
||||||
id: cloudstoragedao_test.util.UUID(),
|
// id: cloudstoragedao_test.util.UUID(),
|
||||||
from: cloudstoragedao_test.user, // sender address
|
// from: cloudstoragedao_test.user, // sender address
|
||||||
to: [cloudstoragedao_test.user], // list of receivers
|
// to: [cloudstoragedao_test.user], // list of receivers
|
||||||
subject: 'Client Email DAO Test', // Subject line
|
// subject: 'Client Email DAO Test', // Subject line
|
||||||
body: 'Hello world' // plaintext body
|
// body: 'Hello world' // plaintext body
|
||||||
});
|
// });
|
||||||
|
|
||||||
cloudstoragedao_test.emailDao.sendEmail(email, function(err) {
|
// cloudstoragedao_test.emailDao.sendEmail(email, function(err) {
|
||||||
ok(!err, 'Email sent');
|
// ok(!err, 'Email sent');
|
||||||
|
|
||||||
start();
|
// start();
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
||||||
// asyncTest("Check virtual inbox, re-encrypt and push to cloud", 1, function() {
|
// asyncTest("Check virtual inbox, re-encrypt and push to cloud", 1, function() {
|
||||||
// cloudstoragedao_test.emailDao.checkVInbox(function(err) {
|
// cloudstoragedao_test.emailDao.checkVInbox(function(err) {
|
||||||
@ -144,20 +193,20 @@ asyncTest("Send Plaintext Email item", 1, function() {
|
|||||||
// });
|
// });
|
||||||
// });
|
// });
|
||||||
|
|
||||||
asyncTest("Sync emails from cloud", 1, function() {
|
// asyncTest("Sync emails from cloud", 1, function() {
|
||||||
cloudstoragedao_test.emailDao.syncFromCloud('inbox', function(err) {
|
// cloudstoragedao_test.emailDao.syncFromCloud('inbox', function(err) {
|
||||||
ok(!err, 'Synced items');
|
// 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) {
|
// cloudstoragedao_test.emailDao.listItems('inbox', 0, null, function(err, collection) {
|
||||||
ok(!err);
|
// ok(!err);
|
||||||
ok(collection.length > 0, 'Read synced items');
|
// 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/lawnchair-dao.js"></script>
|
||||||
<script src="../../src/js/dao/devicestorage.js"></script>
|
<script src="../../src/js/dao/devicestorage.js"></script>
|
||||||
<script src="../../src/js/dao/cloudstorage-dao.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>
|
<script src="../../src/js/dao/email-dao.js"></script>
|
||||||
|
|
||||||
<!-- tests -->
|
<!-- tests -->
|
||||||
|
@ -16,10 +16,10 @@ asyncTest("Init", 3, function() {
|
|||||||
emaildao_test.storage = new app.dao.DeviceStorage(util, emaildao_test.crypto, jsonDao, null);
|
emaildao_test.storage = new app.dao.DeviceStorage(util, emaildao_test.crypto, jsonDao, null);
|
||||||
// cloud storage stub
|
// cloud storage stub
|
||||||
var cloudstorageStub = {
|
var cloudstorageStub = {
|
||||||
syncPrivateKey: function(emailAdress, storedKey, callback) {
|
putPublicKey: function(pk, callback) {
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
putPublicKey: function(pk, callback) {
|
putPrivateKey: function(prk, callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -15,10 +15,10 @@ asyncTest("Init", 2, function() {
|
|||||||
var crypto = new app.crypto.Crypto(window, util);
|
var crypto = new app.crypto.Crypto(window, util);
|
||||||
// cloud storage stub
|
// cloud storage stub
|
||||||
var cloudstorageStub = {
|
var cloudstorageStub = {
|
||||||
syncPrivateKey: function(emailAdress, storedKey, callback) {
|
putPublicKey: function(pk, callback) {
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
putPublicKey: function(pk, callback) {
|
putPrivateKey: function(prk, callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user