Fix redirect bug in login ctrl

This commit is contained in:
Tankred Hase 2014-12-18 00:27:03 +01:00
parent 6beddf4760
commit 383761e6cb
2 changed files with 21 additions and 10 deletions

View File

@ -32,19 +32,23 @@ var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, au
function redirect(availableKeys) {
if (availableKeys && availableKeys.publicKey && availableKeys.privateKey) {
// public and private key available, try empty passphrase
var passphraseIncorrect;
return email.unlock({
keypair: availableKeys,
passphrase: undefined
}).catch(function() {
passphraseIncorrect = true;
// passphrase set... ask for passphrase
return $scope.goTo('/login-existing');
}).then(function() {
if (passphraseIncorrect) {
return;
}
// no passphrase set... go to main screen
return auth.storeCredentials();
}).then(function() {
return $scope.goTo('/account');
return auth.storeCredentials().then(function() {
return $scope.goTo('/account');
});
});
} else if (availableKeys && availableKeys.publicKey && !availableKeys.privateKey) {

View File

@ -86,7 +86,8 @@ describe('Login Controller unit test', function() {
authMock.getEmailAddress.returns(resolves({}));
scope.init().then(function() {
expect(goToStub.withArgs('/add-account').calledOnce).to.be.true;
expect(goToStub.withArgs('/add-account').called).to.be.true;
expect(goToStub.calledOnce).to.be.true;
done();
});
});
@ -103,7 +104,9 @@ describe('Login Controller unit test', function() {
emailMock.unlock.returns(rejects(new Error()));
scope.init().then(function() {
expect(goToStub.withArgs('/login-existing').calledOnce).to.be.true;
expect(goToStub.withArgs('/login-existing').called).to.be.true;
expect(goToStub.calledOnce).to.be.true;
expect(authMock.storeCredentials.called).to.be.false;
done();
});
});
@ -139,7 +142,8 @@ describe('Login Controller unit test', function() {
authMock.storeCredentials.returns(resolves());
scope.init().then(function() {
expect(goToStub.withArgs('/account').calledOnce).to.be.true;
expect(goToStub.withArgs('/account').called).to.be.true;
expect(goToStub.calledOnce).to.be.true;
done();
});
});
@ -171,7 +175,8 @@ describe('Login Controller unit test', function() {
keychainMock.requestPrivateKeyDownload.returns(resolves(true));
scope.init().then(function() {
expect(goToStub.withArgs('/login-privatekey-download').calledOnce).to.be.true;
expect(goToStub.withArgs('/login-privatekey-download').called).to.be.true;
expect(goToStub.calledOnce).to.be.true;
done();
});
});
@ -187,7 +192,8 @@ describe('Login Controller unit test', function() {
keychainMock.requestPrivateKeyDownload.returns(resolves());
scope.init().then(function() {
expect(goToStub.withArgs('/login-new-device').calledOnce).to.be.true;
expect(goToStub.withArgs('/login-new-device').called).to.be.true;
expect(goToStub.calledOnce).to.be.true;
done();
});
});
@ -200,7 +206,8 @@ describe('Login Controller unit test', function() {
accountMock.init.returns(resolves({}));
scope.init().then(function() {
expect(goToStub.withArgs('/login-initial').calledOnce).to.be.true;
expect(goToStub.withArgs('/login-initial').called).to.be.true;
expect(goToStub.calledOnce).to.be.true;
done();
});
});