1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-13 12:45:04 -05:00
mail/test/unit/keychain-dao-test.js

79 lines
1.7 KiB
JavaScript
Raw Normal View History

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,
rsaKeySize: 512
2013-05-23 17:45:26 -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-05-23 17:45:26 -04:00
var crypto = new app.crypto.Crypto(window, util);
// cloud storage stub
var cloudstorageStub = {
putPublicKey: function(pk, callback) {
2013-05-23 17:45:26 -04:00
callback();
},
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);
// 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();
});
});
asyncTest("Get Public Keys", 2, function() {
var pubkeyIds = [{
_id: keychaindao_test.keypair.publicKey._id
}];
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
start();
});
});