mirror of
https://github.com/moparisthebest/mail
synced 2024-11-22 17:02:17 -05:00
fix tests
This commit is contained in:
parent
f3b3a4b496
commit
f8e0c90b5b
@ -2,8 +2,7 @@ define(function(require) {
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var appController = require('js/app-controller'),
|
var appController = require('js/app-controller'),
|
||||||
errorUtil = require('js/util/error'),
|
errorUtil = require('js/util/error');
|
||||||
dl = require('js/util/download');
|
|
||||||
|
|
||||||
var LoginInitialCtrl = function($scope, $location) {
|
var LoginInitialCtrl = function($scope, $location) {
|
||||||
var emailDao = appController._emailDao,
|
var emailDao = appController._emailDao,
|
||||||
|
@ -291,32 +291,11 @@ define(function(require) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail due to error in onConnect', function(done) {
|
|
||||||
devicestorageStub.init.yields();
|
|
||||||
updateHandlerStub.update.yields();
|
|
||||||
emailDaoStub.init.yields();
|
|
||||||
|
|
||||||
onConnectStub.yields({});
|
|
||||||
|
|
||||||
controller.init({
|
|
||||||
emailAddress: emailAddress
|
|
||||||
}, function(err) {
|
|
||||||
expect(err).to.exist;
|
|
||||||
expect(updateHandlerStub.update.calledOnce).to.be.true;
|
|
||||||
expect(emailDaoStub.init.calledOnce).to.be.true;
|
|
||||||
expect(devicestorageStub.init.calledOnce).to.be.true;
|
|
||||||
expect(onConnectStub.calledOnce).to.be.true;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should work and return a keypair', function(done) {
|
it('should work and return a keypair', function(done) {
|
||||||
devicestorageStub.init.withArgs(emailAddress).yields();
|
devicestorageStub.init.withArgs(emailAddress).yields();
|
||||||
emailDaoStub.init.yields(null, {});
|
emailDaoStub.init.yields(null, {});
|
||||||
updateHandlerStub.update.yields();
|
updateHandlerStub.update.yields();
|
||||||
|
|
||||||
onConnectStub.yields();
|
|
||||||
|
|
||||||
controller.init({
|
controller.init({
|
||||||
emailAddress: emailAddress
|
emailAddress: emailAddress
|
||||||
}, function(err, keypair) {
|
}, function(err, keypair) {
|
||||||
@ -325,7 +304,6 @@ define(function(require) {
|
|||||||
expect(updateHandlerStub.update.calledOnce).to.be.true;
|
expect(updateHandlerStub.update.calledOnce).to.be.true;
|
||||||
expect(emailDaoStub.init.calledOnce).to.be.true;
|
expect(emailDaoStub.init.calledOnce).to.be.true;
|
||||||
expect(devicestorageStub.init.calledOnce).to.be.true;
|
expect(devicestorageStub.init.calledOnce).to.be.true;
|
||||||
expect(onConnectStub.calledOnce).to.be.true;
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -133,14 +133,18 @@ define(function(require) {
|
|||||||
dao._account.folders = [];
|
dao._account.folders = [];
|
||||||
imapClientStub.login.yields();
|
imapClientStub.login.yields();
|
||||||
|
|
||||||
|
var listFolderStub = sinon.stub(dao, '_imapListFolders').yields(null, []);
|
||||||
|
|
||||||
dao.onConnect({
|
dao.onConnect({
|
||||||
imapClient: imapClientStub,
|
imapClient: imapClientStub,
|
||||||
pgpMailer: pgpMailerStub
|
pgpMailer: pgpMailerStub
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
expect(err).to.not.exist;
|
expect(err).to.not.exist;
|
||||||
expect(dao._account.online).to.be.true;
|
expect(dao._account.online).to.be.true;
|
||||||
|
expect(dao._account.folders).to.deep.equal([]);
|
||||||
expect(dao._imapClient).to.equal(dao._imapClient);
|
expect(dao._imapClient).to.equal(dao._imapClient);
|
||||||
expect(dao._smtpClient).to.equal(dao._smtpClient);
|
expect(dao._smtpClient).to.equal(dao._smtpClient);
|
||||||
|
listFolderStub.restore();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -306,23 +310,7 @@ define(function(require) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work when folder already initiated', function(done) {
|
it('should work', function(done) {
|
||||||
dao._account.folders = [];
|
|
||||||
imapLoginStub.yields();
|
|
||||||
|
|
||||||
dao.onConnect({
|
|
||||||
imapClient: imapClientStub,
|
|
||||||
pgpMailer: pgpMailerStub
|
|
||||||
}, function(err) {
|
|
||||||
expect(err).to.not.exist;
|
|
||||||
expect(dao._account.online).to.be.true;
|
|
||||||
expect(dao._imapClient).to.equal(dao._imapClient);
|
|
||||||
expect(dao._smtpClient).to.equal(dao._smtpClient);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should work when folder not yet initiated', function(done) {
|
|
||||||
var folders = [];
|
var folders = [];
|
||||||
imapLoginStub.yields();
|
imapLoginStub.yields();
|
||||||
imapListFoldersStub.yields(null, folders);
|
imapListFoldersStub.yields(null, folders);
|
||||||
|
@ -60,13 +60,55 @@ define(function(require) {
|
|||||||
initStub.restore();
|
initStub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should forward to existing user login', function(done) {
|
it('should forward directly to desktop for empty passphrase', function(done) {
|
||||||
startAppStub.yields();
|
var testKeys = {
|
||||||
getEmailAddressStub.yields(null, emailAddress);
|
|
||||||
initStub.yields(null, {
|
|
||||||
privateKey: 'a',
|
privateKey: 'a',
|
||||||
publicKey: 'b'
|
publicKey: 'b'
|
||||||
|
};
|
||||||
|
|
||||||
|
startAppStub.yields();
|
||||||
|
getEmailAddressStub.yields(null, emailAddress);
|
||||||
|
initStub.yields(null, testKeys);
|
||||||
|
|
||||||
|
emailDaoMock.unlock.withArgs({
|
||||||
|
keypair: testKeys,
|
||||||
|
passphrase: undefined
|
||||||
|
}).yields();
|
||||||
|
|
||||||
|
angular.module('logintest', []);
|
||||||
|
mocks.module('logintest');
|
||||||
|
mocks.inject(function($controller, $rootScope, $location) {
|
||||||
|
location = $location;
|
||||||
|
sinon.stub(location, 'path', function(path) {
|
||||||
|
expect(path).to.equal('/desktop');
|
||||||
|
expect(startAppStub.calledOnce).to.be.true;
|
||||||
|
expect(checkForUpdateStub.calledOnce).to.be.true;
|
||||||
|
expect(getEmailAddressStub.calledOnce).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
scope = $rootScope.$new();
|
||||||
|
scope.state = {};
|
||||||
|
ctrl = $controller(LoginCtrl, {
|
||||||
|
$location: location,
|
||||||
|
$scope: scope
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should forward to existing user login', function(done) {
|
||||||
|
var testKeys = {
|
||||||
|
privateKey: 'a',
|
||||||
|
publicKey: 'b'
|
||||||
|
};
|
||||||
|
|
||||||
|
startAppStub.yields();
|
||||||
|
getEmailAddressStub.yields(null, emailAddress);
|
||||||
|
initStub.yields(null, testKeys);
|
||||||
|
|
||||||
|
emailDaoMock.unlock.withArgs({
|
||||||
|
keypair: testKeys,
|
||||||
|
passphrase: undefined
|
||||||
|
}).yields({});
|
||||||
|
|
||||||
angular.module('logintest', []);
|
angular.module('logintest', []);
|
||||||
mocks.module('logintest');
|
mocks.module('logintest');
|
||||||
|
@ -5,7 +5,6 @@ define(function(require) {
|
|||||||
angular = require('angular'),
|
angular = require('angular'),
|
||||||
mocks = require('angularMocks'),
|
mocks = require('angularMocks'),
|
||||||
LoginInitialCtrl = require('js/controller/login-initial'),
|
LoginInitialCtrl = require('js/controller/login-initial'),
|
||||||
dl = require('js/util/download'),
|
|
||||||
PGP = require('js/crypto/pgp'),
|
PGP = require('js/crypto/pgp'),
|
||||||
EmailDAO = require('js/dao/email-dao'),
|
EmailDAO = require('js/dao/email-dao'),
|
||||||
appController = require('js/app-controller');
|
appController = require('js/app-controller');
|
||||||
@ -54,8 +53,6 @@ define(function(require) {
|
|||||||
|
|
||||||
describe('initial state', function() {
|
describe('initial state', function() {
|
||||||
it('should be well defined', function() {
|
it('should be well defined', function() {
|
||||||
expect(scope.proceed).to.exist;
|
|
||||||
expect(scope.exportKeypair).to.exist;
|
|
||||||
expect(scope.confirmPassphrase).to.exist;
|
expect(scope.confirmPassphrase).to.exist;
|
||||||
expect(scope.state.ui).to.equal(1);
|
expect(scope.state.ui).to.equal(1);
|
||||||
});
|
});
|
||||||
@ -63,10 +60,10 @@ define(function(require) {
|
|||||||
|
|
||||||
describe('check passphrase quality', function() {
|
describe('check passphrase quality', function() {
|
||||||
it('should be too short', function() {
|
it('should be too short', function() {
|
||||||
scope.state.passphrase = '&§DG36abc';
|
scope.state.passphrase = '&§DG36';
|
||||||
scope.checkPassphraseQuality();
|
scope.checkPassphraseQuality();
|
||||||
|
|
||||||
expect(scope.passphraseMsg).to.equal('Too short');
|
expect(scope.passphraseMsg).to.equal('Very weak');
|
||||||
expect(scope.passphraseRating).to.equal(0);
|
expect(scope.passphraseRating).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -112,16 +109,12 @@ define(function(require) {
|
|||||||
emailDaoMock.unlock.withArgs({
|
emailDaoMock.unlock.withArgs({
|
||||||
passphrase: passphrase
|
passphrase: passphrase
|
||||||
}).yields();
|
}).yields();
|
||||||
setStateStub = sinon.stub(scope, 'setState', function(state) {
|
|
||||||
if (setStateStub.calledOnce) {
|
scope.$apply = function() {
|
||||||
expect(state).to.equal(2);
|
expect(location.$$path).to.equal('/desktop');
|
||||||
} else if (setStateStub.calledTwice) {
|
expect(emailDaoMock.unlock.calledOnce).to.be.true;
|
||||||
expect(state).to.equal(4);
|
done();
|
||||||
expect(emailDaoMock.unlock.calledOnce).to.be.true;
|
};
|
||||||
scope.setState.restore();
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
scope.confirmPassphrase();
|
scope.confirmPassphrase();
|
||||||
});
|
});
|
||||||
@ -139,6 +132,7 @@ define(function(require) {
|
|||||||
emailDaoMock.unlock.withArgs({
|
emailDaoMock.unlock.withArgs({
|
||||||
passphrase: passphrase
|
passphrase: passphrase
|
||||||
}).yields(new Error('asd'));
|
}).yields(new Error('asd'));
|
||||||
|
|
||||||
setStateStub = sinon.stub(scope, 'setState', function(state) {
|
setStateStub = sinon.stub(scope, 'setState', function(state) {
|
||||||
if (setStateStub.calledOnce) {
|
if (setStateStub.calledOnce) {
|
||||||
expect(state).to.equal(2);
|
expect(state).to.equal(2);
|
||||||
@ -154,64 +148,5 @@ define(function(require) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('proceed', function() {
|
|
||||||
it('should forward', function() {
|
|
||||||
var locationSpy = sinon.spy(location, 'path');
|
|
||||||
|
|
||||||
scope.proceed();
|
|
||||||
|
|
||||||
expect(locationSpy.calledWith('/desktop')).to.be.true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('export keypair', function() {
|
|
||||||
it('should work', function() {
|
|
||||||
var locationSpy, createDownloadMock;
|
|
||||||
|
|
||||||
createDownloadMock = sinon.stub(dl, 'createDownload');
|
|
||||||
cryptoMock.exportKeys.yields(null, {
|
|
||||||
publicKeyArmored: 'a',
|
|
||||||
privateKeyArmored: 'b',
|
|
||||||
keyId: keyId
|
|
||||||
});
|
|
||||||
createDownloadMock.withArgs(sinon.match(function(arg) {
|
|
||||||
return arg.content === 'ab' && arg.filename === 'whiteout_mail_' + emailAddress + '_' + expectedKeyId + '.asc' && arg.contentType === 'text/plain';
|
|
||||||
})).yields();
|
|
||||||
|
|
||||||
locationSpy = sinon.spy(location, 'path');
|
|
||||||
|
|
||||||
scope.exportKeypair();
|
|
||||||
|
|
||||||
expect(cryptoMock.exportKeys.calledOnce).to.be.true;
|
|
||||||
expect(createDownloadMock.calledOnce).to.be.true;
|
|
||||||
expect(locationSpy.calledWith('/desktop')).to.be.true;
|
|
||||||
dl.createDownload.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not work when download fails', function() {
|
|
||||||
var createDownloadMock = sinon.stub(dl, 'createDownload');
|
|
||||||
cryptoMock.exportKeys.yields(null, {
|
|
||||||
publicKeyArmored: 'a',
|
|
||||||
privateKeyArmored: 'b',
|
|
||||||
keyId: keyId
|
|
||||||
});
|
|
||||||
createDownloadMock.yields({
|
|
||||||
errMsg: 'snafu.'
|
|
||||||
});
|
|
||||||
scope.exportKeypair();
|
|
||||||
|
|
||||||
expect(cryptoMock.exportKeys.calledOnce).to.be.true;
|
|
||||||
expect(createDownloadMock.calledOnce).to.be.true;
|
|
||||||
dl.createDownload.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not work when export fails', function() {
|
|
||||||
cryptoMock.exportKeys.yields(new Error('snafu.'));
|
|
||||||
|
|
||||||
scope.exportKeypair();
|
|
||||||
|
|
||||||
expect(cryptoMock.exportKeys.calledOnce).to.be.true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -98,14 +98,6 @@ define(function(require) {
|
|||||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not do anything without passphrase', function() {
|
|
||||||
scope.state.passphrase = '';
|
|
||||||
|
|
||||||
scope.confirmPassphrase();
|
|
||||||
|
|
||||||
expect(scope.incorrect).to.be.true;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not work when keypair upload fails', function() {
|
it('should not work when keypair upload fails', function() {
|
||||||
scope.passphrase = passphrase;
|
scope.passphrase = passphrase;
|
||||||
scope.key = {
|
scope.key = {
|
||||||
|
Loading…
Reference in New Issue
Block a user