1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 02:42:17 -05:00

integration tests work too now

This commit is contained in:
Tankred Hase 2013-06-11 00:17:08 +02:00
parent f1fd936141
commit 0e9be73791
5 changed files with 218 additions and 236 deletions

View File

@ -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'
}
}
});

View File

@ -1,16 +1,19 @@
'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 = {
var cloudstoragedaoTest = {
user: 'email.dao.it.test@mail.whiteout.io',
password: 'Xoza76645',
keySize: 128,
ivSize: 128,
rsaKeySize: 1024
};
};
asyncTest("Init", 1, function() {
asyncTest("Init", 1, function() {
// test keys
var pk = "-----BEGIN PUBLIC KEY-----\r\n" +
@ -19,29 +22,24 @@ asyncTest("Init", 1, function() {
"Fr0XlYJnJM2ERVrSGkDNSI2+6bVq1k2TB4YeZoMVhel/igCr5Rbr8LyNswCQMIXl\r\n" +
"oiMEqmiN/YtLwD1z+QIDAQAB\r\n" +
"-----END PUBLIC KEY-----";
cloudstoragedao_test.keypair = {
cloudstoragedaoTest.keypair = {
publicKey: {
_id: "01ca6e54-a6b3-4b5f-bb43-ede30aaccc9e",
userId: cloudstoragedao_test.user,
userId: cloudstoragedaoTest.user,
publicKey: pk
},
privateKey: {
_id: "01ca6e54-a6b3-4b5f-bb43-ede30aaccc9e",
userId: cloudstoragedao_test.user,
userId: cloudstoragedaoTest.user,
encryptedKey: "zXBmmR7fz6sfR0AIeOzvwKOb6BrBQBgyweJ4c0LZS9h7C18SgPSMcvpSgBIwJ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NJvjn5Up/iusKeKXEGb/lhyc058GZY5UCmoIsV30TYgzXeuj6VZBEtcvAvza0mYmGvXf91ebVZR+",
iv: "XE4c3X134YNkapbeSXP6GA=="
}
};
// 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);
jsonDao.init(cloudstoragedaoTest.user);
cloudstoragedaoTest.keychain = new KeychainDAO(cloudstorage);
cloudstoragedaoTest.emailDao = new EmailDAO(cloudstorage, cloudstoragedaoTest.keychain);
// clear db before tests
jsonDao.clear(function(err) {
@ -49,149 +47,151 @@ asyncTest("Init", 1, function() {
start();
});
});
});
asyncTest("Put public key to cloud", 1, function() {
cloudstoragedao_test.cloudstorage.putPublicKey(cloudstoragedao_test.keypair.publicKey, function(err) {
asyncTest("Put public key to cloud", 1, function() {
cloudstorage.putPublicKey(cloudstoragedaoTest.keypair.publicKey, function(err) {
ok(!err, 'Persist key to cloud');
start();
});
});
});
asyncTest("Get Public key from cloud by id", 2, function() {
cloudstoragedao_test.cloudstorage.getPublicKey(cloudstoragedao_test.keypair.publicKey._id, function(err, data) {
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, cloudstoragedao_test.keypair.publicKey, 'Public key is equal');
deepEqual(data, cloudstoragedaoTest.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) {
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, cloudstoragedao_test.keypair.publicKey, 'Public key is equal');
deepEqual(data, cloudstoragedaoTest.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) {
asyncTest("Delete Public key from cloud", 1, function() {
cloudstorage.removePublicKey(cloudstoragedaoTest.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) {
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() {
cloudstoragedao_test.cloudstorage.getPrivateKey(cloudstoragedao_test.keypair.privateKey._id, function(err, data) {
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, cloudstoragedao_test.keypair.privateKey, 'Private key is equal');
deepEqual(data, cloudstoragedaoTest.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) {
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");
module("Keychain DAO");
asyncTest("Put User Keypair", 1, function() {
cloudstoragedao_test.keychain.putUserKeyPair(cloudstoragedao_test.keypair, function(err) {
asyncTest("Put User Keypair", 1, function() {
cloudstoragedaoTest.keychain.putUserKeyPair(cloudstoragedaoTest.keypair, function(err) {
ok(!err);
start();
});
});
});
asyncTest("Get User Keypair", 2, function() {
cloudstoragedao_test.keychain.getUserKeyPair(cloudstoragedao_test.user, function(err, keypair) {
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() {
asyncTest("Get Public Keys", 2, function() {
var pubkeyIds = [{
_id: cloudstoragedao_test.keypair.publicKey._id
_id: cloudstoragedaoTest.keypair.publicKey._id
}
];
cloudstoragedao_test.keychain.getPublicKeys(pubkeyIds, function(err, pubkeys) {
cloudstoragedaoTest.keychain.getPublicKeys(pubkeyIds, function(err, pubkeys) {
ok(!err);
deepEqual(pubkeys[0], cloudstoragedao_test.keypair.publicKey, "Fetch public key");
deepEqual(pubkeys[0], cloudstoragedaoTest.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
});
cloudstoragedao_test.emailDao.init(account, cloudstoragedao_test.password, function(err) {
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() {
asyncTest("Send Plaintext Email item", 1, function() {
var email = {
from: cloudstoragedao_test.user, // sender address
to: [cloudstoragedao_test.user], // list of receivers
from: cloudstoragedaoTest.user, // sender address
to: [cloudstoragedaoTest.user], // list of receivers
subject: 'Client Email DAO Test', // Subject line
body: 'Hello world' // plaintext body
};
cloudstoragedao_test.emailDao.sendEmail(email, function(err) {
cloudstoragedaoTest.emailDao.sendEmail(email, function(err) {
ok(!err, 'Email sent');
start();
});
});
});
asyncTest("Sync emails from cloud", 1, function() {
cloudstoragedao_test.emailDao.syncFromCloud('inbox', function(err) {
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() {
asyncTest("List emails from cloud", 2, function() {
cloudstoragedao_test.emailDao.listItems('inbox', 0, null, function(err, gotten) {
cloudstoragedaoTest.emailDao.listItems('inbox', 0, null, function(err, gotten) {
ok(!err);
ok(gotten.length > 0, 'Read synced items');
start();
});
});
});

View File

@ -1,57 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<head>
<meta charset="utf-8">
<title>JavaScript Integration Tests</title>
<link rel="stylesheet" href="../qunit-1.11.0.css">
</head>
<body>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script>
// clear session storage of failed tests, so async order is correct after fail & refresh
window.sessionStorage.clear();
</script>
<!-- dependencies -->
<script src="../../src/lib/cordova-2.5.0.js"></script>
<script src="../qunit-1.11.0.js"></script>
<script src="../../src/lib/jquery-1.8.2.min.js"></script>
<script src="../../src/lib/underscore-1.4.4.min.js"></script>
<script src="../../src/lib/backbone-1.0.0.min.js"></script>
<script src="../../src/lib/lawnchair/lawnchair-git.js"></script>
<script src="../../src/lib/lawnchair/lawnchair-adapter-webkit-sqlite-git.js"></script>
<script src="../../src/lib/lawnchair/lawnchair-adapter-indexed-db-git.js"></script>
<script>QUnit.config.autostart = false;</script>
<script data-main="main.js" src="../../src/lib/require.js"></script>
<script src="../../src/lib/forge/forge.rsa.bundle.js"></script>
<script src="../../src/lib/uuid.js"></script>
<script src="../../src/js/app-config.js"></script>
<script>
app.config.workerPath = '../../src/js';
app.config.cloudUrl = 'http://localhost:8888';
</script>
<script src="../../src/js/model/email-model.js"></script>
<script src="../../src/js/model/folder-model.js"></script>
<script src="../../src/js/model/account-model.js"></script>
<script src="../../src/js/crypto/util.js"></script>
<script src="../../src/js/crypto/pbkdf2.js"></script>
<script src="../../src/js/crypto/aes-cbc.js"></script>
<script src="../../src/js/crypto/rsa.js"></script>
<script src="../../src/js/crypto/crypto-batch.js"></script>
<script src="../../src/js/crypto/crypto.js"></script>
<script src="../../src/js/dao/lawnchair-dao.js"></script>
<script src="../../src/js/dao/devicestorage.js"></script>
<script src="../../src/js/dao/cloudstorage-dao.js"></script>
<script src="../../src/js/dao/keychain-dao.js"></script>
<script src="../../src/js/dao/email-dao.js"></script>
<!-- tests -->
<script src="cloudstorage-dao-test.js"></script>
</body>
</body>
</html>

29
test/integration/main.js Normal file
View File

@ -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();
});
}

View File

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