From 0e9be73791978c57dcb6d7f40172fe4d4775a91d Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Tue, 11 Jun 2013 00:17:08 +0200 Subject: [PATCH] integration tests work too now --- src/require-config.js | 7 - test/integration/cloudstorage-dao-test.js | 350 +++++++++++----------- test/integration/index.html | 66 +--- test/integration/main.js | 29 ++ test/unit/main.js | 2 +- 5 files changed, 218 insertions(+), 236 deletions(-) create mode 100644 test/integration/main.js diff --git a/src/require-config.js b/src/require-config.js index a28fe0e..e4d3357 100644 --- a/src/require-config.js +++ b/src/require-config.js @@ -26,18 +26,11 @@ deps: ['lawnchair', 'lawnchairSQL'] }, backbone: { - //These script dependencies should be loaded before loading - //backbone.js deps: ['underscore', 'jquery'], - //Once loaded, use the global 'Backbone' as the - //module value. exports: 'Backbone' }, underscore: { exports: '_' - }, - cordova: { - exports: 'cordova' } } }); diff --git a/test/integration/cloudstorage-dao-test.js b/test/integration/cloudstorage-dao-test.js index 58e64a1..5251aa5 100644 --- a/test/integration/cloudstorage-dao-test.js +++ b/test/integration/cloudstorage-dao-test.js @@ -1,197 +1,197 @@ -'use strict'; +define(['js/dao/email-dao', 'js/dao/keychain-dao', 'js/dao/lawnchair-dao', + 'js/dao/cloudstorage-dao' +], function(EmailDAO, KeychainDAO, jsonDao, cloudstorage) { + 'use strict'; -module("CloudStorage DAO"); + module("CloudStorage DAO"); -var cloudstoragedao_test = { - user: 'email.dao.it.test@mail.whiteout.io', - password: 'Xoza76645', - keySize: 128, - ivSize: 128, - rsaKeySize: 1024 -}; - -asyncTest("Init", 1, function() { - - // test keys - var pk = "-----BEGIN PUBLIC KEY-----\r\n" + - "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDTIupLSuRD5gh6wHx1f4Q2Qv61\r\n" + - "trOWgqfi/eJUtheoOWkW6KGoLqo5xdklPVIqyP9702PDQtf1upwVB8MCGSiYMDyj\r\n" + - "Fr0XlYJnJM2ERVrSGkDNSI2+6bVq1k2TB4YeZoMVhel/igCr5Rbr8LyNswCQMIXl\r\n" + - "oiMEqmiN/YtLwD1z+QIDAQAB\r\n" + - "-----END PUBLIC KEY-----"; - cloudstoragedao_test.keypair = { - publicKey: { - _id: "01ca6e54-a6b3-4b5f-bb43-ede30aaccc9e", - userId: cloudstoragedao_test.user, - publicKey: pk - }, - privateKey: { - _id: "01ca6e54-a6b3-4b5f-bb43-ede30aaccc9e", - userId: cloudstoragedao_test.user, - encryptedKey: "zXBmmR7fz6sfR0AIeOzvwKOb6BrBQBgyweJ4c0LZS9h7C18SgPSMcvpSgBIwJadi577DPmwfXPl6zCNtwoqlLqD6xdS6P/bDY6rIWbaGbRrWzs/KXJ7UjWq0uyZSUFQK8w/woHkyQ4eLqdwj+duPZzrerDyi1XX8XXCcNDpDwR+1L2TxWlDzShN7IiA4OUeFsDbgqN3lKUBSHw5USnassv7nRwWlSNWPVaIlx3YT2T/VIaNoBbX5jDDwhDT4h/1fOOEbxTIBEN65mGGNW9GPLbi/PVgKibrF6l8bHwW5FjIkoYZdzgPe5nowhbFb2FB7mWX4gXMzqT3wuOP9fCOCEj4muxYkV7daedAGFRKl5mTPd9Cu+vSY+SnZX55m1yXQixn55J50AgW+aY/LXV+UqYwVObp7o5qs0B+OhQIRxH2Sp6IjRRFAqsQgBoRXS1qWPLCGVLMoSUkOSOCQd6rsr70fGXxGpguJFigAMWDXAzuPH98UFaB7kCiohhFLZ25vMhd/cOz1MXTKKPQJXfpBr8uX/hhhdsZReVfqLFKpvs1MzdFoV6FiTwZwyDyRnANYRHnqnP148q5s0JOkFcHaHqYdbLvVU6jm/B3QYJ/IO/uKyHoIhVobSSUBLzLDV0Eila9LhCdfWVXIVfFNUr5ut1YyOoJ23G5ItBSq5VFaZv79lNIhWjw/effq1IJd4eKeBe2X2DoYv85FZifAf/kUN38g0rTfAmKedsTGGhMLo+3Aa12MzRF93aTOMyKpHSA0G/5dA5PSVSlgDd/hwn4AlKzfo8M2PF1fh+9q5YtWqs4+mSOmyvYKxg9g+ZBhAvHbVBUN2emoNoJTC6JToB9jeRvksl1iehx+3C8nHUzXsxqApA3a79RJ+izRT2f0GguEAlAz4B6EozFRJwjNyRL2Fe7bgtadJxTNZfcG+oCgCFNCOyOvSgcpkjvj2DlFdPvw5BXXodV5D0jIg+OnszWcgLUDLFMkPPJgYrx9smRqdPjFnjWvnm6bRVZbxaU+FXKFvplmOG3XK1sR9g91bg5nnKDHRf6OuwBBgX0AyzOz2ohO3NVuIcppHjecUEY8t9QgezGal/R1PepW/uNPn/zJgGthTb4rK/KrXZTEsvC3XI55VlSnhORfNJvjn5Up/iusKeKXEGb/lhyc058GZY5UCmoIsV30TYgzXeuj6VZBEtcvAvza0mYmGvXf91ebVZR+", - iv: "XE4c3X134YNkapbeSXP6GA==" - } + var cloudstoragedaoTest = { + user: 'email.dao.it.test@mail.whiteout.io', + password: 'Xoza76645', + keySize: 128, + ivSize: 128, + rsaKeySize: 1024 }; - // init dependencies - cloudstoragedao_test.util = new cryptoLib.Util(window, uuid); - var jsonDao = new app.dao.LawnchairDAO(Lawnchair); - jsonDao.init(cloudstoragedao_test.user); - cloudstoragedao_test.crypto = new app.crypto.Crypto(window, cloudstoragedao_test.util); - cloudstoragedao_test.storage = new app.dao.DeviceStorage(cloudstoragedao_test.util, cloudstoragedao_test.crypto, jsonDao, null); - cloudstoragedao_test.cloudstorage = new app.dao.CloudStorage(window, $); - cloudstoragedao_test.keychain = new app.dao.KeychainDAO(jsonDao, cloudstoragedao_test.cloudstorage); - cloudstoragedao_test.emailDao = new app.dao.EmailDAO(jsonDao, cloudstoragedao_test.crypto, cloudstoragedao_test.storage, cloudstoragedao_test.cloudstorage, cloudstoragedao_test.util, cloudstoragedao_test.keychain); + asyncTest("Init", 1, function() { - // clear db before tests - jsonDao.clear(function(err) { - ok(!err, 'DB cleared. Error status: ' + err); + // test keys + var pk = "-----BEGIN PUBLIC KEY-----\r\n" + + "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDTIupLSuRD5gh6wHx1f4Q2Qv61\r\n" + + "trOWgqfi/eJUtheoOWkW6KGoLqo5xdklPVIqyP9702PDQtf1upwVB8MCGSiYMDyj\r\n" + + "Fr0XlYJnJM2ERVrSGkDNSI2+6bVq1k2TB4YeZoMVhel/igCr5Rbr8LyNswCQMIXl\r\n" + + "oiMEqmiN/YtLwD1z+QIDAQAB\r\n" + + "-----END PUBLIC KEY-----"; + cloudstoragedaoTest.keypair = { + publicKey: { + _id: "01ca6e54-a6b3-4b5f-bb43-ede30aaccc9e", + userId: cloudstoragedaoTest.user, + publicKey: pk + }, + privateKey: { + _id: "01ca6e54-a6b3-4b5f-bb43-ede30aaccc9e", + userId: cloudstoragedaoTest.user, + encryptedKey: "zXBmmR7fz6sfR0AIeOzvwKOb6BrBQBgyweJ4c0LZS9h7C18SgPSMcvpSgBIwJadi577DPmwfXPl6zCNtwoqlLqD6xdS6P/bDY6rIWbaGbRrWzs/KXJ7UjWq0uyZSUFQK8w/woHkyQ4eLqdwj+duPZzrerDyi1XX8XXCcNDpDwR+1L2TxWlDzShN7IiA4OUeFsDbgqN3lKUBSHw5USnassv7nRwWlSNWPVaIlx3YT2T/VIaNoBbX5jDDwhDT4h/1fOOEbxTIBEN65mGGNW9GPLbi/PVgKibrF6l8bHwW5FjIkoYZdzgPe5nowhbFb2FB7mWX4gXMzqT3wuOP9fCOCEj4muxYkV7daedAGFRKl5mTPd9Cu+vSY+SnZX55m1yXQixn55J50AgW+aY/LXV+UqYwVObp7o5qs0B+OhQIRxH2Sp6IjRRFAqsQgBoRXS1qWPLCGVLMoSUkOSOCQd6rsr70fGXxGpguJFigAMWDXAzuPH98UFaB7kCiohhFLZ25vMhd/cOz1MXTKKPQJXfpBr8uX/hhhdsZReVfqLFKpvs1MzdFoV6FiTwZwyDyRnANYRHnqnP148q5s0JOkFcHaHqYdbLvVU6jm/B3QYJ/IO/uKyHoIhVobSSUBLzLDV0Eila9LhCdfWVXIVfFNUr5ut1YyOoJ23G5ItBSq5VFaZv79lNIhWjw/effq1IJd4eKeBe2X2DoYv85FZifAf/kUN38g0rTfAmKedsTGGhMLo+3Aa12MzRF93aTOMyKpHSA0G/5dA5PSVSlgDd/hwn4AlKzfo8M2PF1fh+9q5YtWqs4+mSOmyvYKxg9g+ZBhAvHbVBUN2emoNoJTC6JToB9jeRvksl1iehx+3C8nHUzXsxqApA3a79RJ+izRT2f0GguEAlAz4B6EozFRJwjNyRL2Fe7bgtadJxTNZfcG+oCgCFNCOyOvSgcpkjvj2DlFdPvw5BXXodV5D0jIg+OnszWcgLUDLFMkPPJgYrx9smRqdPjFnjWvnm6bRVZbxaU+FXKFvplmOG3XK1sR9g91bg5nnKDHRf6OuwBBgX0AyzOz2ohO3NVuIcppHjecUEY8t9QgezGal/R1PepW/uNPn/zJgGthTb4rK/KrXZTEsvC3XI55VlSnhORfNJvjn5Up/iusKeKXEGb/lhyc058GZY5UCmoIsV30TYgzXeuj6VZBEtcvAvza0mYmGvXf91ebVZR+", + iv: "XE4c3X134YNkapbeSXP6GA==" + } + }; - start(); - }); -}); + // init dependencies + jsonDao.init(cloudstoragedaoTest.user); + cloudstoragedaoTest.keychain = new KeychainDAO(cloudstorage); + cloudstoragedaoTest.emailDao = new EmailDAO(cloudstorage, cloudstoragedaoTest.keychain); -asyncTest("Put public key to cloud", 1, function() { - cloudstoragedao_test.cloudstorage.putPublicKey(cloudstoragedao_test.keypair.publicKey, function(err) { - ok(!err, 'Persist key to cloud'); + // clear db before tests + jsonDao.clear(function(err) { + ok(!err, 'DB cleared. Error status: ' + err); - start(); - }); -}); - -asyncTest("Get Public key from cloud by id", 2, function() { - cloudstoragedao_test.cloudstorage.getPublicKey(cloudstoragedao_test.keypair.publicKey._id, function(err, data) { - ok(!err && data && data.publicKey, 'Get public key from cloud'); - deepEqual(data, cloudstoragedao_test.keypair.publicKey, 'Public key is equal'); - - start(); - }); -}); - -asyncTest("Get Public key from cloud by email", 2, function() { - cloudstoragedao_test.cloudstorage.getPublicKeyByUserId(cloudstoragedao_test.keypair.publicKey.userId, function(err, data) { - ok(!err && data && data.publicKey, 'Get public key from cloud'); - deepEqual(data, cloudstoragedao_test.keypair.publicKey, 'Public key is equal'); - - start(); - }); -}); - -asyncTest("Delete Public key from cloud", 1, function() { - cloudstoragedao_test.cloudstorage.removePublicKey(cloudstoragedao_test.keypair.publicKey._id, function(err) { - ok(!err, 'Delete public key from cloud'); - - start(); - }); -}); - -asyncTest("Put private key to cloud", 1, function() { - cloudstoragedao_test.cloudstorage.putPrivateKey(cloudstoragedao_test.keypair.privateKey, function(err) { - ok(!err, 'Persist key to cloud'); - - start(); - }); -}); - -asyncTest("Get Private key from cloud", 2, function() { - cloudstoragedao_test.cloudstorage.getPrivateKey(cloudstoragedao_test.keypair.privateKey._id, function(err, data) { - ok(!err && data && data.encryptedKey, 'Get private key from cloud'); - deepEqual(data, cloudstoragedao_test.keypair.privateKey, 'Private key is equal'); - - start(); - }); -}); - -asyncTest("Delete Private key from cloud", 1, function() { - cloudstoragedao_test.cloudstorage.removePrivateKey(cloudstoragedao_test.keypair.privateKey._id, function(err) { - ok(!err, 'Delete private key from cloud'); - - start(); - }); -}); - - - -module("Keychain DAO"); - -asyncTest("Put User Keypair", 1, function() { - cloudstoragedao_test.keychain.putUserKeyPair(cloudstoragedao_test.keypair, function(err) { - ok(!err); - - start(); - }); -}); - -asyncTest("Get User Keypair", 2, function() { - cloudstoragedao_test.keychain.getUserKeyPair(cloudstoragedao_test.user, function(err, keypair) { - ok(!err); - ok(keypair && keypair.publicKey && keypair.privateKey); - - start(); - }); -}); - -asyncTest("Get Public Keys", 2, function() { - var pubkeyIds = [{ - _id: cloudstoragedao_test.keypair.publicKey._id - } - ]; - cloudstoragedao_test.keychain.getPublicKeys(pubkeyIds, function(err, pubkeys) { - ok(!err); - deepEqual(pubkeys[0], cloudstoragedao_test.keypair.publicKey, "Fetch public key"); - - start(); - }); -}); - - - -module("Email DAO"); - -asyncTest("Init", 1, function() { - var account = new app.model.Account({ - emailAddress: cloudstoragedao_test.user, - symKeySize: cloudstoragedao_test.keySize, - symIvSize: cloudstoragedao_test.ivSize, - asymKeySize: cloudstoragedao_test.rsaKeySize + start(); + }); }); - cloudstoragedao_test.emailDao.init(account, cloudstoragedao_test.password, function(err) { - ok(!err, 'Init complete'); + asyncTest("Put public key to cloud", 1, function() { + cloudstorage.putPublicKey(cloudstoragedaoTest.keypair.publicKey, function(err) { + ok(!err, 'Persist key to cloud'); - start(); + start(); + }); }); -}); -asyncTest("Send Plaintext Email item", 1, function() { - var email = { - from: cloudstoragedao_test.user, // sender address - to: [cloudstoragedao_test.user], // list of receivers - subject: 'Client Email DAO Test', // Subject line - body: 'Hello world' // plaintext body - }; + asyncTest("Get Public key from cloud by id", 2, function() { + cloudstorage.getPublicKey(cloudstoragedaoTest.keypair.publicKey._id, function(err, data) { + ok(!err && data && data.publicKey, 'Get public key from cloud'); + deepEqual(data, cloudstoragedaoTest.keypair.publicKey, 'Public key is equal'); - cloudstoragedao_test.emailDao.sendEmail(email, function(err) { - ok(!err, 'Email sent'); - - start(); + start(); + }); }); -}); -asyncTest("Sync emails from cloud", 1, function() { - cloudstoragedao_test.emailDao.syncFromCloud('inbox', function(err) { - ok(!err, 'Synced items'); + asyncTest("Get Public key from cloud by email", 2, function() { + cloudstorage.getPublicKeyByUserId(cloudstoragedaoTest.keypair.publicKey.userId, function(err, data) { + ok(!err && data && data.publicKey, 'Get public key from cloud'); + deepEqual(data, cloudstoragedaoTest.keypair.publicKey, 'Public key is equal'); - start(); + start(); + }); }); -}); -asyncTest("List emails from cloud", 2, function() { + asyncTest("Delete Public key from cloud", 1, function() { + cloudstorage.removePublicKey(cloudstoragedaoTest.keypair.publicKey._id, function(err) { + ok(!err, 'Delete public key from cloud'); - cloudstoragedao_test.emailDao.listItems('inbox', 0, null, function(err, gotten) { - ok(!err); - ok(gotten.length > 0, 'Read synced items'); - - start(); + start(); + }); }); + + asyncTest("Put private key to cloud", 1, function() { + cloudstorage.putPrivateKey(cloudstoragedaoTest.keypair.privateKey, function(err) { + ok(!err, 'Persist key to cloud'); + + start(); + }); + }); + + asyncTest("Get Private key from cloud", 2, function() { + cloudstorage.getPrivateKey(cloudstoragedaoTest.keypair.privateKey._id, function(err, data) { + ok(!err && data && data.encryptedKey, 'Get private key from cloud'); + deepEqual(data, cloudstoragedaoTest.keypair.privateKey, 'Private key is equal'); + + start(); + }); + }); + + asyncTest("Delete Private key from cloud", 1, function() { + cloudstorage.removePrivateKey(cloudstoragedaoTest.keypair.privateKey._id, function(err) { + ok(!err, 'Delete private key from cloud'); + + start(); + }); + }); + + + + module("Keychain DAO"); + + asyncTest("Put User Keypair", 1, function() { + cloudstoragedaoTest.keychain.putUserKeyPair(cloudstoragedaoTest.keypair, function(err) { + ok(!err); + + start(); + }); + }); + + asyncTest("Get User Keypair", 2, function() { + cloudstoragedaoTest.keychain.getUserKeyPair(cloudstoragedaoTest.user, function(err, keypair) { + ok(!err); + ok(keypair && keypair.publicKey && keypair.privateKey); + + start(); + }); + }); + + asyncTest("Get Public Keys", 2, function() { + var pubkeyIds = [{ + _id: cloudstoragedaoTest.keypair.publicKey._id + } + ]; + cloudstoragedaoTest.keychain.getPublicKeys(pubkeyIds, function(err, pubkeys) { + ok(!err); + deepEqual(pubkeys[0], cloudstoragedaoTest.keypair.publicKey, "Fetch public key"); + + start(); + }); + }); + + + + module("Email DAO"); + + asyncTest("Init", 1, function() { + var account = new app.model.Account({ + emailAddress: cloudstoragedaoTest.user, + symKeySize: cloudstoragedaoTest.keySize, + symIvSize: cloudstoragedaoTest.ivSize, + asymKeySize: cloudstoragedaoTest.rsaKeySize + }); + + cloudstoragedaoTest.emailDao.init(account, cloudstoragedaoTest.password, function(err) { + ok(!err, 'Init complete'); + + start(); + }); + }); + + asyncTest("Send Plaintext Email item", 1, function() { + var email = { + from: cloudstoragedaoTest.user, // sender address + to: [cloudstoragedaoTest.user], // list of receivers + subject: 'Client Email DAO Test', // Subject line + body: 'Hello world' // plaintext body + }; + + cloudstoragedaoTest.emailDao.sendEmail(email, function(err) { + ok(!err, 'Email sent'); + + start(); + }); + }); + + asyncTest("Sync emails from cloud", 1, function() { + cloudstoragedaoTest.emailDao.syncFromCloud('inbox', function(err) { + ok(!err, 'Synced items'); + + start(); + }); + }); + + asyncTest("List emails from cloud", 2, function() { + + cloudstoragedaoTest.emailDao.listItems('inbox', 0, null, function(err, gotten) { + ok(!err); + ok(gotten.length > 0, 'Read synced items'); + + start(); + }); + }); + }); \ No newline at end of file diff --git a/test/integration/index.html b/test/integration/index.html index 467e9c6..b40a1a7 100644 --- a/test/integration/index.html +++ b/test/integration/index.html @@ -1,57 +1,17 @@ - - - JavaScript Integration Tests - - - -
-
- - - - - - - - - - - - + + + JavaScript Integration Tests + + + +
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/test/integration/main.js b/test/integration/main.js new file mode 100644 index 0000000..3ef4007 --- /dev/null +++ b/test/integration/main.js @@ -0,0 +1,29 @@ +'use strict'; + +require(['../../src/require-config'], function() { + + require.config({ + baseUrl: '../../src/lib' + }); + + // Start the main app logic. + require(['cordova', 'js/app-config'], function() { + // clear session storage of failed tests, so async order is correct after fail & refresh + window.sessionStorage.clear(); + window.Worker = undefined; + + app.config.workerPath = '../../src/js'; + app.config.cloudUrl = 'http://localhost:8888'; + + startTests(); + }); +}); + +function startTests() { + require([ + 'test/integration/cloudstorage-dao-test' + ], function() { + //Tests loaded, run tests + QUnit.start(); + }); +} \ No newline at end of file diff --git a/test/unit/main.js b/test/unit/main.js index d1c30c0..4e298ab 100644 --- a/test/unit/main.js +++ b/test/unit/main.js @@ -7,7 +7,7 @@ require(['../../src/require-config'], function() { }); // Start the main app logic. - require(['js/app-config'], function() { + require(['cordova', 'js/app-config'], function() { // clear session storage of failed tests, so async order is correct after fail & refresh window.sessionStorage.clear(); window.Worker = undefined;