[WO-939] Fix TLS cert rejection bug

This commit is contained in:
Felix Hammerl 2015-04-27 18:15:36 +02:00
parent d36ddcef7f
commit 55add6a6d3
5 changed files with 24 additions and 31 deletions

View File

@ -11,7 +11,7 @@ var NOTIFICATION_SENT_TIMEOUT = 2000;
// Controller // Controller
// //
var NavigationCtrl = function($scope, $location, $q, $timeout, account, email, outbox, notification, appConfig, dialog, dummy, privateKey, axe) { var NavigationCtrl = function($scope, $location, $q, $timeout, account, email, outbox, notification, status, appConfig, dialog, dummy, privateKey, axe) {
if (!$location.search().dev && !account.isLoggedIn()) { if (!$location.search().dev && !account.isLoggedIn()) {
$location.path('/'); // init app $location.path('/'); // init app
return; return;
@ -90,10 +90,10 @@ var NavigationCtrl = function($scope, $location, $q, $timeout, account, email, o
// scope functions // scope functions
// //
$scope.onOutboxUpdate = function(err, count) { $scope.onOutboxUpdate = function(err) {
if (err) { if (err) {
dialog.error(err); axe.error('Sending from outbox failed: ' + err.message);
return; status.update('Error sending messages...');
} }
// update the outbox mail count // update the outbox mail count
@ -106,8 +106,6 @@ var NavigationCtrl = function($scope, $location, $q, $timeout, account, email, o
return; return;
} }
ob.count = count;
return $q(function(resolve) { return $q(function(resolve) {
resolve(); resolve();

View File

@ -809,7 +809,7 @@ Email.prototype.refreshOutbox = function() {
outbox.messages.splice(index, 1); outbox.messages.splice(index, 1);
}); });
updateUnreadCount(outbox); // update the unread count updateUnreadCount(outbox, true); // update the unread count, count all messages
}); });
}; };
@ -1731,16 +1731,13 @@ Email.prototype.isOnline = function() {
/** /**
* Updates a folder's unread count: * Updates a folder's unread count:
* - For the outbox, that's the total number of messages, * - For the outbox, that's the total number of messages (countAllMessages === true),
* - For every other folder, it's the number of unread messages * - For every other folder, it's the number of unread messages (countAllMessages === falsy)
*/ */
function updateUnreadCount(folder) { function updateUnreadCount(folder, countAllMessages) {
var allMsgs = folder.messages.length, folder.count = countAllMessages ? folder.messages.length : _.filter(folder.messages, function(msg) {
unreadMsgs = _.filter(folder.messages, function(msg) { return msg.unread;
return msg.unread; }).length;
}).length;
folder.count = folder.path === config.outboxMailboxPath ? allMsgs : unreadMsgs;
} }
/** /**

View File

@ -124,8 +124,7 @@ Outbox.prototype.put = function(mail) {
* @param {Function} callback(error, pendingMailsCount) Callback that informs you about the count of pending mails. * @param {Function} callback(error, pendingMailsCount) Callback that informs you about the count of pending mails.
*/ */
Outbox.prototype._processOutbox = function(callback) { Outbox.prototype._processOutbox = function(callback) {
var self = this, var self = this;
unsentMails = 0;
// also, if a _processOutbox call is still in progress, ignore it. // also, if a _processOutbox call is still in progress, ignore it.
if (self._outboxBusy) { if (self._outboxBusy) {
@ -138,7 +137,6 @@ Outbox.prototype._processOutbox = function(callback) {
self._devicestorage.listItems(outboxDb).then(function(pendingMails) { self._devicestorage.listItems(outboxDb).then(function(pendingMails) {
// if we're not online, don't even bother sending mails. // if we're not online, don't even bother sending mails.
if (!self._emailDao._account.online || _.isEmpty(pendingMails)) { if (!self._emailDao._account.online || _.isEmpty(pendingMails)) {
unsentMails = pendingMails.length;
return; return;
} }
@ -154,7 +152,7 @@ Outbox.prototype._processOutbox = function(callback) {
}).then(function() { }).then(function() {
self._outboxBusy = false; self._outboxBusy = false;
callback(null, unsentMails); callback();
}).catch(function(err) { }).catch(function(err) {
self._outboxBusy = false; self._outboxBusy = false;

View File

@ -75,17 +75,20 @@ describe('Navigation Controller unit test', function() {
}); });
describe('empty outbox', function() { describe('empty outbox', function() {
it('should work', function() { it('should work', function(done) {
var callback; var onOutboxUpdate;
expect(outboxBoMock.startChecking.callCount).to.equal(1); expect(outboxBoMock.startChecking.callCount).to.equal(1);
outboxBoMock.startChecking.calledWith(sinon.match(function(cb) { outboxBoMock.startChecking.calledWith(sinon.match(function(cb) {
callback = cb; onOutboxUpdate = cb;
})); }));
callback(null, 5); emailDaoMock.refreshOutbox.returns(resolves());
expect(outboxFolder.count).to.equal(5);
onOutboxUpdate().then(function() {
expect(emailDaoMock.refreshOutbox.calledOnce).to.be.true;
done();
});
}); });
}); });

View File

@ -263,10 +263,8 @@ describe('Outbox unit test', function() {
devicestorageStub.removeList.returns(resolves()); devicestorageStub.removeList.returns(resolves());
function onOutboxUpdate(err, count) { function onOutboxUpdate(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(count).to.equal(0);
expect(outbox._outboxBusy).to.be.false; expect(outbox._outboxBusy).to.be.false;
expect(emailDaoStub.sendEncrypted.callCount).to.equal(2); expect(emailDaoStub.sendEncrypted.callCount).to.equal(2);
expect(emailDaoStub.sendPlaintext.callCount).to.equal(2); expect(emailDaoStub.sendPlaintext.callCount).to.equal(2);
@ -284,9 +282,8 @@ describe('Outbox unit test', function() {
emailDaoStub._account.online = false; emailDaoStub._account.online = false;
devicestorageStub.listItems.returns(resolves([{}])); devicestorageStub.listItems.returns(resolves([{}]));
outbox._processOutbox(function(err, count) { outbox._processOutbox(function(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(count).to.equal(1);
expect(devicestorageStub.listItems.callCount).to.equal(1); expect(devicestorageStub.listItems.callCount).to.equal(1);
expect(outbox._outboxBusy).to.be.false; expect(outbox._outboxBusy).to.be.false;
done(); done();