From a810fb06d1ce3199177870364daf926115f72ba0 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Thu, 5 Jun 2014 15:26:39 +0200 Subject: [PATCH] Delete old qunit test directory --- test/unit/aes-test.js | 24 ------ test/unit/crypto-test.js | 121 ---------------------------- test/unit/devicestorage-dao-test.js | 106 ------------------------ test/unit/email-dao-test.js | 105 ------------------------ test/unit/forge-test.js | 42 ---------- test/unit/index.html | 17 ---- test/unit/keychain-dao-test.js | 92 --------------------- test/unit/main.js | 34 -------- test/unit/rsa-test.js | 53 ------------ 9 files changed, 594 deletions(-) delete mode 100644 test/unit/aes-test.js delete mode 100644 test/unit/crypto-test.js delete mode 100644 test/unit/devicestorage-dao-test.js delete mode 100644 test/unit/email-dao-test.js delete mode 100644 test/unit/forge-test.js delete mode 100644 test/unit/index.html delete mode 100644 test/unit/keychain-dao-test.js delete mode 100644 test/unit/main.js delete mode 100644 test/unit/rsa-test.js diff --git a/test/unit/aes-test.js b/test/unit/aes-test.js deleted file mode 100644 index 130546f..0000000 --- a/test/unit/aes-test.js +++ /dev/null @@ -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); - }); -}); \ No newline at end of file diff --git a/test/unit/crypto-test.js b/test/unit/crypto-test.js deleted file mode 100644 index 05e4ea4..0000000 --- a/test/unit/crypto-test.js +++ /dev/null @@ -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(); - }); - }); - -}); \ No newline at end of file diff --git a/test/unit/devicestorage-dao-test.js b/test/unit/devicestorage-dao-test.js deleted file mode 100644 index 627918f..0000000 --- a/test/unit/devicestorage-dao-test.js +++ /dev/null @@ -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(); - }); - }); - -}); \ No newline at end of file diff --git a/test/unit/email-dao-test.js b/test/unit/email-dao-test.js deleted file mode 100644 index a216657..0000000 --- a/test/unit/email-dao-test.js +++ /dev/null @@ -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(); - }); - -}); \ No newline at end of file diff --git a/test/unit/forge-test.js b/test/unit/forge-test.js deleted file mode 100644 index 36ad9db..0000000 --- a/test/unit/forge-test.js +++ /dev/null @@ -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); - }); -}); \ No newline at end of file diff --git a/test/unit/index.html b/test/unit/index.html deleted file mode 100644 index 54ceadf..0000000 --- a/test/unit/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - JavaScript Unit Tests - - - -
-
- - - - - - - \ No newline at end of file diff --git a/test/unit/keychain-dao-test.js b/test/unit/keychain-dao-test.js deleted file mode 100644 index c29d8c8..0000000 --- a/test/unit/keychain-dao-test.js +++ /dev/null @@ -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(); - }); - }); - -}); \ No newline at end of file diff --git a/test/unit/main.js b/test/unit/main.js deleted file mode 100644 index f6da06d..0000000 --- a/test/unit/main.js +++ /dev/null @@ -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(); - } - ); -} \ No newline at end of file diff --git a/test/unit/rsa-test.js b/test/unit/rsa-test.js deleted file mode 100644 index 8f0fad5..0000000 --- a/test/unit/rsa-test.js +++ /dev/null @@ -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); - }); -}); \ No newline at end of file