1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-15 05:35:05 -05:00
mail/test/unit/keychain-dao-test.js

92 lines
1.9 KiB
JavaScript
Raw Normal View History

define(['js/dao/keychain-dao', 'js/dao/lawnchair-dao'], function(KeychainDAO, LawnchairDAO) {
2013-06-10 16:45:21 -04:00
'use strict';
module("Keychain DAO");
var jsonDao,
keychaindaoTest = {
user: 'keychaindao_test@example.com',
password: 'Password',
keySize: 128,
ivSize: 128,
rsaKeySize: 512
};
2013-05-23 17:45:26 -04:00
2013-06-10 16:45:21 -04:00
asyncTest("Init", 2, function() {
// stubbing
var pubkeyDaoStub = {
put: function(pk, callback) {
2013-06-10 16:45:21 -04:00
callback();
}
};
2013-05-23 17:45:26 -04:00
2013-06-10 16:45:21 -04:00
// module instancing
jsonDao = new LawnchairDAO();
keychaindaoTest.keychainDao = new KeychainDAO(jsonDao, pubkeyDaoStub);
2013-06-10 16:45:21 -04:00
ok(keychaindaoTest.keychainDao);
2013-06-10 16:45:21 -04:00
// init and clear db before test
2013-09-26 07:26:57 -04:00
jsonDao.init(keychaindaoTest.user, function() {
jsonDao.clear(function() {
ok(true, 'cleared db');
2013-06-10 16:45:21 -04:00
2013-09-26 07:26:57 -04:00
start();
});
2013-06-10 16:45:21 -04:00
});
});
2013-06-10 16:45:21 -04:00
asyncTest("Put User Keypair", 1, function() {
2013-06-10 16:45:21 -04:00
keychaindaoTest.keypair = {
publicKey: {
_id: '123',
userId: keychaindaoTest.user,
publicKey: 'asdf'
},
privateKey: {
_id: '123',
userId: keychaindaoTest.user,
encryptedKey: 'qwer',
iv: 'yxvc'
}
};
keychaindaoTest.keychainDao.putUserKeyPair(keychaindaoTest.keypair, function(err) {
ok(!err);
start();
});
});
2013-05-23 17:45:26 -04:00
2013-06-10 16:45:21 -04:00
asyncTest("Get User Keypair", 2, function() {
keychaindaoTest.keychainDao.getUserKeyPair(keychaindaoTest.user, function(err, keypair) {
ok(!err);
ok(keypair && keypair.publicKey && keypair.privateKey);
2013-05-23 17:45:26 -04:00
2013-06-10 16:45:21 -04:00
start();
});
2013-05-23 17:45:26 -04:00
});
2013-06-10 16:45:21 -04:00
asyncTest("Get Public Keys", 2, function() {
var pubkeyIds = [{
2013-09-26 07:26:57 -04:00
_id: keychaindaoTest.keypair.publicKey._id
}];
2013-06-10 16:45:21 -04:00
keychaindaoTest.keychainDao.getPublicKeys(pubkeyIds, function(err, pubkeys) {
ok(!err);
deepEqual(pubkeys[0], keychaindaoTest.keypair.publicKey, "Fetch public key");
start();
});
});
2013-06-10 16:45:21 -04:00
asyncTest("Get User Keypair", 2, function() {
keychaindaoTest.keychainDao.getReceiverPublicKey(keychaindaoTest.user, function(err, pubkey) {
ok(!err);
ok(pubkey && pubkey.publicKey);
start();
});
});
});