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 @@ - - -
- -