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

93 lines
1.9 KiB
JavaScript
Raw Normal View History

2013-06-10 16:45:21 -04:00
define(['js/dao/keychain-dao', 'js/dao/lawnchair-dao'], function(KeychainDAO, jsonDao) {
'use strict';
module("Keychain DAO");
var 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 cloudstorageStub = {
putPublicKey: function(pk, callback) {
callback();
},
putPrivateKey: function(prk, callback) {
callback();
}
};
2013-05-23 17:45:26 -04:00
2013-06-10 16:45:21 -04:00
// module instancing
keychaindaoTest.keychainDao = new KeychainDAO(cloudstorageStub);
ok(keychaindaoTest.keychainDao);
2013-06-10 16:45:21 -04:00
// init and clear db before test
jsonDao.init(keychaindaoTest.user);
jsonDao.clear(function() {
ok(true, 'cleared db');
start();
});
});
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 = [{
_id: keychaindaoTest.keypair.publicKey._id
}
];
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.getReveiverPublicKey(keychaindaoTest.user, function(err, pubkey) {
ok(!err);
ok(pubkey && pubkey.publicKey);
start();
});
});
});