2013-05-23 17:45:26 -04:00
|
|
|
module("Keychain DAO");
|
|
|
|
|
|
|
|
var keychaindao_test = {
|
|
|
|
user: 'keychaindao_test@example.com',
|
|
|
|
password: 'Password',
|
|
|
|
keySize: 128,
|
|
|
|
ivSize: 128,
|
2013-05-27 13:25:45 -04:00
|
|
|
rsaKeySize: 512
|
2013-05-23 17:45:26 -04:00
|
|
|
};
|
|
|
|
|
2013-05-27 13:25:45 -04:00
|
|
|
asyncTest("Init", 2, function() {
|
2013-05-23 17:45:26 -04:00
|
|
|
// init dependencies
|
|
|
|
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(keychaindao_test.user);
|
2013-05-23 17:45:26 -04:00
|
|
|
var crypto = new app.crypto.Crypto(window, util);
|
|
|
|
// cloud storage stub
|
|
|
|
var cloudstorageStub = {
|
2013-05-31 17:27:19 -04:00
|
|
|
putPublicKey: function(pk, callback) {
|
2013-05-23 17:45:26 -04:00
|
|
|
callback();
|
|
|
|
},
|
2013-05-31 17:27:19 -04:00
|
|
|
putPrivateKey: function(prk, callback) {
|
2013-05-23 17:45:26 -04:00
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
keychaindao_test.keychainDao = new app.dao.KeychainDAO(jsonDao, cloudstorageStub);
|
|
|
|
ok(keychaindao_test.keychainDao);
|
|
|
|
|
2013-05-27 13:25:45 -04:00
|
|
|
// clear db before test
|
|
|
|
jsonDao.clear(function() {
|
|
|
|
ok(true, 'cleared db');
|
|
|
|
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest("Put User Keypair", 1, function() {
|
|
|
|
|
|
|
|
keychaindao_test.keypair = {
|
|
|
|
publicKey: {
|
|
|
|
_id: '1',
|
|
|
|
userId: keychaindao_test.user,
|
|
|
|
publicKey: 'asdf'
|
|
|
|
},
|
|
|
|
privateKey: {
|
|
|
|
_id: '1',
|
|
|
|
userId: keychaindao_test.user,
|
|
|
|
encryptedKey: 'qwer',
|
|
|
|
iv: 'yxvc'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
keychaindao_test.keychainDao.putUserKeyPair(keychaindao_test.keypair, function(err) {
|
|
|
|
ok(!err);
|
|
|
|
|
|
|
|
start();
|
|
|
|
});
|
2013-05-23 17:45:26 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest("Get User Keypair", 2, function() {
|
|
|
|
keychaindao_test.keychainDao.getUserKeyPair(keychaindao_test.user, function(err, keypair) {
|
|
|
|
ok(!err);
|
|
|
|
ok(keypair && keypair.publicKey && keypair.privateKey);
|
|
|
|
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-05-31 09:51:34 -04:00
|
|
|
asyncTest("Get Public Keys", 2, function() {
|
|
|
|
var pubkeyIds = [{
|
2013-06-02 22:26:17 -04:00
|
|
|
_id: keychaindao_test.keypair.publicKey._id
|
|
|
|
}
|
|
|
|
];
|
2013-05-31 09:51:34 -04:00
|
|
|
keychaindao_test.keychainDao.getPublicKeys(pubkeyIds, function(err, pubkeys) {
|
|
|
|
ok(!err);
|
|
|
|
deepEqual(pubkeys[0], keychaindao_test.keypair.publicKey, "Fetch public key");
|
2013-05-23 17:45:26 -04:00
|
|
|
|
2013-05-31 09:51:34 -04:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|