1
0
mirror of https://github.com/moparisthebest/mail synced 2024-12-21 23:08:50 -05:00

Review imap key-sync

This commit is contained in:
Tankred Hase 2015-04-01 14:24:46 +02:00
parent f41e6e12b9
commit c8f13511c1
8 changed files with 27 additions and 19 deletions

View File

@ -204,9 +204,12 @@ var NavigationCtrl = function($scope, $location, $q, $timeout, account, email, o
showNegativeBtn: true,
callback: function(granted) {
if (granted) {
// send to key upload screen
$timeout(function() {
$location.path('/login-privatekey-upload');
// logout of the current session
email.onDisconnect().then(function() {
// send to key upload screen
$timeout(function() {
$location.path('/login-privatekey-upload');
});
});
}
}

View File

@ -54,9 +54,10 @@ var LoginPrivateKeyDownloadCtrl = function($scope, $location, $routeParams, $q,
return email.unlock({
keypair: cachedKeypair,
passphrase: undefined
}).catch(function() {
}).catch(function(err) {
// passphrase incorrct ... go to passphrase login screen
$scope.goTo('/login-existing');
throw err;
});
}).then(function() {

View File

@ -22,18 +22,17 @@ var LoginPrivateKeyUploadCtrl = function($scope, $location, $routeParams, $q, au
//
$scope.encryptAndUploadKey = function() {
if ($scope.inputCode.toUpperCase() !== $scope.code) {
$scope.errMsg = 'The code does not match. Please go back and check the generated code.';
return;
}
// register device to keychain service
return $q(function(resolve) {
$scope.busy = true;
$scope.errMsg = undefined;
$scope.incorrect = false;
resolve();
}).then(function() {
if ($scope.inputCode.toUpperCase() !== $scope.code) {
throw new Error('The code does not match. Please go back and check the generated code.');
}
}).then(function() {
// login to imap
return privateKey.init();

View File

@ -41,7 +41,7 @@ PrivateKey.prototype.init = function() {
* Cleanup by logging out of the imap client.
*/
PrivateKey.prototype.destroy = function() {
this._imap.login();
this._imap.logout();
// don't wait for logout to complete
return new Promise(function(resolve) {
resolve();
@ -111,8 +111,10 @@ PrivateKey.prototype.upload = function(options) {
path: IMAP_KEYS_FOLDER
}).then(function() {
self._axe.debug('Successfully created imap folder ' + IMAP_KEYS_FOLDER);
}).catch(function() {
self._axe.debug('Creating imap folder ' + IMAP_KEYS_FOLDER + ' failed. Probably already available.');
}).catch(function(err) {
var prettyErr = new Error('Creating imap folder ' + IMAP_KEYS_FOLDER + ' failed: ' + err.message);
self._axe.error(prettyErr);
throw prettyErr;
});
}).then(createMessage).then(function(message) {
// upload to imap folder

View File

@ -31,8 +31,11 @@
<div ng-show="step === 2">
<p class="typo-paragraph">Please confirm the backup code you have written down.</p>
<form class="form">
<p class="form__error-message" ng-show="errMsg">{{errMsg}}</p>
<div class="form__row">
<input type="text" class="input-text" ng-model="inputCode" wo-input-code wo-focus-me="step === 2"
<input type="text" class="input-text" ng-class="{'input-text--error':incorrect}"
ng-model="inputCode" wo-input-code wo-focus-me="step === 2"
required pattern="([a-zA-Z0-9\-]*)" placeholder="0000-0000-0000-0000-0000-0000"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
</div>

View File

@ -103,12 +103,11 @@ describe('Login Private Key Download Controller unit test', function() {
keyId: cachedKeypair.publicKey._id
}).returns(resolves(encryptedPrivateKey));
privateKeyStub.decrypt.returns(resolves(privkey));
emailDaoMock.unlock.returns(rejects());
emailDaoMock.unlock.returns(rejects(new Error()));
authMock.storeCredentials.returns(resolves());
privateKeyStub.destroy.returns(resolves());
scope.checkCode().then(function() {
expect(scope.errMsg).to.not.exist;
expect(scope.goTo.withArgs('/login-existing').calledOnce).to.be.true;
done();
});

View File

@ -57,8 +57,9 @@ describe('Login Private Key Upload Controller unit test', function() {
it('should fail for invalid code', function() {
scope.inputCode = 'asdf';
scope.encryptAndUploadKey();
expect(scope.errMsg).to.match(/go back and check/);
scope.encryptAndUploadKey().then(function() {
expect(scope.errMsg).to.match(/go back and check/);
});
});
it('should work', function(done) {

View File

@ -35,7 +35,7 @@ describe('Private Key DAO unit tests', function() {
describe('destroy', function() {
it('should work', function(done) {
privkeyDao.destroy().then(function() {
expect(imapClientStub.login.calledOnce).to.be.true;
expect(imapClientStub.logout.calledOnce).to.be.true;
done();
});
});