1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-29 12:22:22 -05:00

Delete old qunit test directory

This commit is contained in:
Tankred Hase 2014-06-05 15:26:39 +02:00
parent 18d1c39b0a
commit a810fb06d1
9 changed files with 0 additions and 594 deletions

View File

@ -1,24 +0,0 @@
define(['cryptoLib/aes-cbc', 'cryptoLib/util', 'test/test-data'], function(aes, util, testData) {
'use strict';
module("AES Crypto");
var aesTest = {
keySize: 128,
testMessage: testData.generateBigString(1000)
};
test("CBC mode", 4, function() {
var plaintext = aesTest.testMessage;
var key = util.random(aesTest.keySize);
var iv = util.random(aesTest.keySize);
ok(key, 'Key: ' + key);
equal(util.base642Str(key).length * 8, aesTest.keySize, 'Keysize ' + aesTest.keySize);
var ciphertext = aes.encrypt(plaintext, key, iv);
ok(ciphertext, 'Ciphertext lenght: ' + ciphertext.length);
var decrypted = aes.decrypt(ciphertext, key, iv);
equal(decrypted, plaintext, 'Decryption correct' + decrypted);
});
});

View File

@ -1,121 +0,0 @@
define(['js/crypto/crypto', 'cryptoLib/util', 'test/test-data'], function(Crypto, util, testData) {
'use strict';
module("Crypto Api");
var cryptoTest = {
user: 'crypto_test@example.com',
password: 'Password',
keySize: 128,
ivSize: 128,
rsaKeySize: 1024,
salt: util.random(128)
};
var crypto;
asyncTest("Init without keypair", 4, function() {
crypto = new Crypto();
// init dependencies
ok(crypto, 'Crypto');
// test without passing keys
crypto.init({
emailAddress: cryptoTest.user,
password: cryptoTest.password,
salt: cryptoTest.salt,
keySize: cryptoTest.keySize,
rsaKeySize: cryptoTest.rsaKeySize
}, function(err, generatedKeypair) {
ok(!err && generatedKeypair, 'Init crypto without keypair input');
var pk = generatedKeypair.publicKey;
ok(pk._id && pk.userId, 'Key ID: ' + pk._id);
ok(pk.publicKey.indexOf('-----BEGIN PUBLIC KEY-----') === 0, pk.publicKey);
cryptoTest.generatedKeypair = generatedKeypair;
start();
});
});
asyncTest("Init with keypair", 1, function() {
// test with passing keypair
crypto.init({
emailAddress: cryptoTest.user,
password: cryptoTest.password,
salt: cryptoTest.salt,
keySize: cryptoTest.keySize,
rsaKeySize: cryptoTest.rsaKeySize,
storedKeypair: cryptoTest.generatedKeypair
}, function(err, generatedKeypair) {
ok(!err && !generatedKeypair, 'Init crypto with keypair input');
start();
});
});
asyncTest("PBKDF2 (Async/Worker)", 2, function() {
crypto.deriveKey(cryptoTest.password, cryptoTest.salt, cryptoTest.keySize, function(err, key) {
ok(!err);
equal(util.base642Str(key).length * 8, cryptoTest.keySize, 'Keysize ' + cryptoTest.keySize);
start();
});
});
asyncTest("AES/HMAC encrypt batch (Async/Worker)", 2, function() {
// generate test data
cryptoTest.symlist = testData.getEmailCollection(10);
crypto.symEncryptList(cryptoTest.symlist, function(err, result) {
ok(!err && result.key && result.list && result.list[0].hmac, 'Encrypt list for user');
equal(result.list.length, cryptoTest.symlist.length, 'Length of list');
cryptoTest.symEncryptedList = result.list;
cryptoTest.symKey = result.key;
start();
});
});
asyncTest("AES/HMAC decrypt batch (Async/Worker)", 3, function() {
var keys = [];
for (var i = 0; i < cryptoTest.symEncryptedList.length; i++) {
keys.push(cryptoTest.symKey);
}
crypto.symDecryptList(cryptoTest.symEncryptedList, keys, function(err, decryptedList) {
ok(!err && decryptedList, 'Decrypt list');
equal(decryptedList.length, cryptoTest.symlist.length, 'Length of list');
deepEqual(decryptedList, cryptoTest.symlist, 'Decrypted list is correct');
start();
});
});
asyncTest("AES/RSA encrypt batch for User (Async/Worker)", 2, function() {
// generate test data
cryptoTest.list = testData.getEmailCollection(10);
var receiverPubkeys = [cryptoTest.generatedKeypair.publicKey];
crypto.encryptListForUser(cryptoTest.list, receiverPubkeys, function(err, encryptedList) {
ok(!err && encryptedList, 'Encrypt list for user');
equal(encryptedList.length, cryptoTest.list.length, 'Length of list');
cryptoTest.encryptedList = encryptedList;
start();
});
});
asyncTest("AES/RSA decrypt batch for User (Async/Worker)", 3, function() {
var senderPubkeys = [cryptoTest.generatedKeypair.publicKey];
crypto.decryptListForUser(cryptoTest.encryptedList, senderPubkeys, function(err, decryptedList) {
ok(!err && decryptedList, 'Decrypt list');
equal(decryptedList.length, cryptoTest.list.length, 'Length of list');
deepEqual(decryptedList, cryptoTest.list, 'Decrypted list is correct');
start();
});
});
});

View File

@ -1,106 +0,0 @@
define(['underscore', 'cryptoLib/util', 'js/crypto/crypto', 'js/dao/devicestorage-dao', 'test/test-data', 'js/dao/lawnchair-dao'], function(_, util, Crypto, DeviceStorageDAO, testData, LawnchairDAO) {
'use strict';
module("DeviceStorage");
var devicestorageTest = {
user: 'devicestorage_test@example.com',
password: 'Password',
keySize: 128,
ivSize: 128,
rsaKeySize: 1024
};
var crypto, storage;
asyncTest("Init", 3, function() {
// init dependencies
storage = new DeviceStorageDAO(new LawnchairDAO());
storage.init(devicestorageTest.user, function() {
ok(storage, 'DeviceStorageDAO');
// generate test data
devicestorageTest.list = testData.getEmailCollection(100);
// init crypto
crypto = new Crypto();
crypto.init({
emailAddress: devicestorageTest.user,
password: devicestorageTest.password,
salt: util.random(devicestorageTest.keySize),
keySize: devicestorageTest.keySize,
rsaKeySize: devicestorageTest.rsaKeySize
}, function(err, generatedKeypair) {
ok(!err && generatedKeypair, 'Init crypto');
devicestorageTest.generatedKeypair = generatedKeypair;
// clear db before tests
storage.clear(function(err) {
ok(!err, 'DB cleared. Error status: ' + err);
start();
});
});
});
});
asyncTest("Encrypt list for user", 2, function() {
var receiverPubkeys = [devicestorageTest.generatedKeypair.publicKey];
crypto.encryptListForUser(devicestorageTest.list, receiverPubkeys, function(err, encryptedList) {
ok(!err);
equal(encryptedList.length, devicestorageTest.list.length, 'Encrypt list');
encryptedList.forEach(function(i) {
i.sentDate = _.findWhere(devicestorageTest.list, {
id: i.id
}).sentDate;
});
devicestorageTest.encryptedList = encryptedList;
start();
});
});
asyncTest("Store encrypted list", 1, function() {
storage.storeList(devicestorageTest.encryptedList, 'email_inbox', function() {
ok(true, 'Store encrypted list');
start();
});
});
asyncTest("List items", 4, function() {
var senderPubkeys = [devicestorageTest.generatedKeypair.publicKey];
var offset = 2,
num = 6;
// list encrypted items from storage
storage.listItems('email_inbox', offset, num, function(err, encryptedList) {
ok(!err);
// decrypt list
crypto.decryptListForUser(encryptedList, senderPubkeys, function(err, decryptedList) {
ok(!err);
equal(decryptedList.length, num, 'Found ' + decryptedList.length + ' items in store (and decrypted)');
var origSet = devicestorageTest.list.splice(92, num);
deepEqual(decryptedList, origSet, 'Messages decrypted correctly');
start();
});
});
});
asyncTest("Delete List items", 1, function() {
// list encrypted items from storage
storage.removeList('email_inbox', function(err) {
ok(!err);
start();
});
});
});

View File

@ -1,105 +0,0 @@
define(['js/dao/email-dao', 'js/dao/keychain-dao', 'js/dao/lawnchair-dao',
'js/crypto/crypto', 'js/dao/devicestorage-dao', 'test/test-data', 'js/app-config'
], function(EmailDAO, KeychainDAO, jsonDao, crypto, storage, testData, app) {
'use strict';
module("Email DAO");
var emaildaoTest = {
user: 'test@atlasdev.onmicrosoft.com',
password: 'Xoza76645',
keySize: 128,
ivSize: 128,
rsaKeySize: 1024
};
asyncTest("Init", 3, function() {
// init dependencies
jsonDao.init(emaildaoTest.user);
// cloud storage stub
emaildaoTest.cloudstorageStub = {
putPublicKey: function(pk, callback) {
callback();
},
putPrivateKey: function(prk, callback) {
callback();
},
getPublicKeyByUserId: function(userId, callback) {
callback();
}
};
emaildaoTest.keychain = new KeychainDAO(emaildaoTest.cloudstorageStub);
emaildaoTest.emailDao = new EmailDAO(emaildaoTest.cloudstorageStub, emaildaoTest.keychain);
// generate test data
emaildaoTest.list = testData.getEmailCollection(100);
var account = new app.model.Account({
emailAddress: emaildaoTest.user,
symKeySize: emaildaoTest.keySize,
symIvSize: emaildaoTest.ivSize,
asymKeySize: emaildaoTest.rsaKeySize
});
// clear db before tests
jsonDao.clear(function(err) {
ok(!err, 'DB cleared. Error status: ' + err);
emaildaoTest.emailDao.init(account, emaildaoTest.password, function(err) {
ok(!err);
equal(emaildaoTest.emailDao.account.get('emailAddress'), emaildaoTest.user, 'Email DAO Account');
start();
});
});
});
asyncTest("Persist test emails (stubbed sync from cloud)", 4, function() {
emaildaoTest.keychain.getUserKeyPair(emaildaoTest.user, function(err, keypair) {
ok(!err && keypair, 'Fetch keypair from keychain');
var receiverPubkeys = [keypair.publicKey];
crypto.encryptListForUser(emaildaoTest.list, receiverPubkeys, function(err, encryptedList) {
ok(!err);
equal(encryptedList.length, emaildaoTest.list.length, 'Encrypt list');
// add sent date to encrypted items
for (var i = 0; i < encryptedList.length; i++) {
encryptedList[i].sentDate = emaildaoTest.list[i].sentDate;
}
// set encrypted test list as return value for cloud storage stub
emaildaoTest.cloudstorageStub.listEncryptedItems = function(type, emailAddress, folderName, callback) {
callback(null, encryptedList);
};
emaildaoTest.emailDao.syncFromCloud('inbox', function() {
ok(true, 'Stored encrypted list');
start();
});
});
});
});
asyncTest("List Email models", 2, function() {
emaildaoTest.emailDao.listItems('inbox', 0, emaildaoTest.list.length, function(err, gotten) {
ok(!err);
var reference = emaildaoTest.list;
deepEqual(gotten, reference, 'Compare collection');
start();
});
});
asyncTest("Get item", 1, function() {
var item = emaildaoTest.list[0];
var mail = emaildaoTest.emailDao.getItem('inbox', item.id);
deepEqual(mail, item, 'Item correct');
start();
});
});

View File

@ -1,42 +0,0 @@
define(['node-forge', 'cryptoLib/util', 'test/test-data'], function(forge, util, testData) {
'use strict';
module("Forge Crypto");
var forgeRsaTest = {
keySize: 1024,
testMessage: '06a9214036b8a15b512e03d534120006'
};
var forgeAesTest = {
keySize: 128,
testMessage: testData.generateBigString(1000)
};
test("SHA-1 Hash", 1, function() {
var sha1 = forge.md.sha1.create();
sha1.update(forgeAesTest.testMessage);
var digest = sha1.digest().toHex();
ok(digest, digest);
});
test("SHA-256 Hash", 1, function() {
forgeRsaTest.md = forge.md.sha256.create();
forgeRsaTest.md.update(forgeAesTest.testMessage);
var digest = forgeRsaTest.md.digest().toHex();
ok(digest, digest);
});
test("HMAC SHA-256", 1, function() {
var key = util.base642Str(util.random(forgeAesTest.keySize));
var iv = util.base642Str(util.random(forgeAesTest.keySize));
var hmac = forge.hmac.create();
hmac.start('sha256', key);
hmac.update(iv);
hmac.update(forgeAesTest.testMessage);
var digest = hmac.digest().toHex();
ok(digest, digest);
});
});

View File

@ -1,17 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Unit Tests</title>
<link rel="stylesheet" href="../qunit-1.11.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="../qunit-1.11.0.js"></script>
<script>QUnit.config.autostart = false;</script>
<script data-main="main.js" src="../../src/lib/require.js"></script>
</body>
</html>

View File

@ -1,92 +0,0 @@
define(['js/dao/keychain-dao', 'js/dao/lawnchair-dao'], function(KeychainDAO, LawnchairDAO) {
'use strict';
module("Keychain DAO");
var jsonDao,
keychaindaoTest = {
user: 'keychaindao_test@example.com',
password: 'Password',
keySize: 128,
ivSize: 128,
rsaKeySize: 512
};
asyncTest("Init", 2, function() {
// stubbing
var pubkeyDaoStub = {
put: function(pk, callback) {
callback();
}
};
// module instancing
jsonDao = new LawnchairDAO();
keychaindaoTest.keychainDao = new KeychainDAO(jsonDao, pubkeyDaoStub);
ok(keychaindaoTest.keychainDao);
// init and clear db before test
jsonDao.init(keychaindaoTest.user, function() {
jsonDao.clear(function() {
ok(true, 'cleared db');
start();
});
});
});
asyncTest("Put User Keypair", 1, function() {
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();
});
});
asyncTest("Get User Keypair", 2, function() {
keychaindaoTest.keychainDao.getUserKeyPair(keychaindaoTest.user, function(err, keypair) {
ok(!err);
ok(keypair && keypair.publicKey && keypair.privateKey);
start();
});
});
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();
});
});
asyncTest("Get User Keypair", 2, function() {
keychaindaoTest.keychainDao.getReceiverPublicKey(keychaindaoTest.user, function(err, pubkey) {
ok(!err);
ok(pubkey && pubkey.publicKey);
start();
});
});
});

View File

@ -1,34 +0,0 @@
'use strict';
require(['../../src/require-config'], function() {
require.config({
baseUrl: '../../src/lib'
});
// Start the main app logic.
require(['js/app-config', 'cordova'], function(app) {
// clear session storage of failed tests, so async order is correct after fail & refresh
window.sessionStorage.clear();
app.config.workerPath = '../../src/js';
startTests();
});
});
function startTests() {
require(
[
'test/unit/forge-test',
'test/unit/aes-test',
'test/unit/rsa-test',
'test/unit/keychain-dao-test',
'test/unit/crypto-test',
'test/unit/devicestorage-dao-test'
], function() {
//Tests loaded, run tests
QUnit.start();
}
);
}

View File

@ -1,53 +0,0 @@
define(['cryptoLib/rsa'], function(rsa) {
'use strict';
module("RSA Crypto");
var rsaTest = {
keySize: 1024,
testMessage: '06a9214036b8a15b512e03d534120006'
};
asyncTest("Generate keypair", 1, function() {
rsa.generateKeypair(rsaTest.keySize, function(err) {
ok(!err);
start();
});
});
test("Export keys", 2, function() {
rsaTest.keypair = rsa.exportKeys();
ok(rsaTest.keypair.pubkeyPem.indexOf('-----BEGIN PUBLIC KEY-----') === 0, rsaTest.keypair.pubkeyPem);
ok(rsaTest.keypair.privkeyPem.indexOf('-----BEGIN RSA PRIVATE KEY-----') === 0, rsaTest.keypair.privkeyPem);
});
test("Init", 2, function() {
rsa.init(rsaTest.keypair.pubkeyPem, rsaTest.keypair.privkeyPem);
var exported = rsa.exportKeys();
ok(exported.pubkeyPem.indexOf('-----BEGIN PUBLIC KEY-----') === 0);
ok(exported.privkeyPem.indexOf('-----BEGIN RSA PRIVATE KEY-----') === 0);
});
test("Encrypt", 1, function() {
rsaTest.ct = rsa.encrypt(rsaTest.testMessage);
ok(rsaTest.ct);
});
test("Decrypt", 1, function() {
var pt = rsa.decrypt(rsaTest.ct);
equal(pt, rsaTest.testMessage);
});
test("Sign", 1, function() {
rsaTest.sig = rsa.sign([btoa('iv'), btoa(rsaTest.testMessage)]);
ok(rsaTest.sig);
});
test("Verify", 1, function() {
var res = rsa.verify([btoa('iv'), btoa(rsaTest.testMessage)], rsaTest.sig);
ok(res);
});
});