2014-10-07 14:32:23 -04:00
|
|
|
'use strict';
|
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
var Auth = require('../../../../src/js/service/auth'),
|
2015-02-20 11:55:11 -05:00
|
|
|
PublicKeyVerifier = require('../../../../src/js/service/publickey-verifier'),
|
2014-11-25 12:19:40 -05:00
|
|
|
LoginInitialCtrl = require('../../../../src/js/controller/login/login-initial'),
|
|
|
|
Email = require('../../../../src/js/email/email');
|
2014-10-07 14:32:23 -04:00
|
|
|
|
|
|
|
describe('Login (initial user) Controller unit test', function() {
|
2015-02-20 11:55:11 -05:00
|
|
|
var scope, ctrl, location, emailMock, authMock, newsletterStub, verifierMock,
|
2014-10-07 14:32:23 -04:00
|
|
|
emailAddress = 'fred@foo.com',
|
2014-11-25 12:19:40 -05:00
|
|
|
keyId, expectedKeyId;
|
2014-10-07 14:32:23 -04:00
|
|
|
|
|
|
|
beforeEach(function() {
|
2014-11-25 12:19:40 -05:00
|
|
|
emailMock = sinon.createStubInstance(Email);
|
|
|
|
authMock = sinon.createStubInstance(Auth);
|
2015-02-20 11:55:11 -05:00
|
|
|
verifierMock = sinon.createStubInstance(PublicKeyVerifier);
|
2014-10-07 14:32:23 -04:00
|
|
|
|
|
|
|
keyId = '9FEB47936E712926';
|
|
|
|
expectedKeyId = '6E712926';
|
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
authMock.emailAddress = emailAddress;
|
2014-10-07 14:32:23 -04:00
|
|
|
|
2014-11-12 10:12:26 -05:00
|
|
|
angular.module('logininitialtest', ['woServices']);
|
2014-11-25 12:19:40 -05:00
|
|
|
angular.mock.module('logininitialtest');
|
|
|
|
angular.mock.inject(function($rootScope, $controller, $location, newsletter) {
|
2014-10-07 14:32:23 -04:00
|
|
|
scope = $rootScope.$new();
|
|
|
|
location = $location;
|
2014-11-12 10:12:26 -05:00
|
|
|
newsletterStub = sinon.stub(newsletter, 'signup');
|
2014-10-07 14:32:23 -04:00
|
|
|
scope.state = {
|
|
|
|
ui: {}
|
|
|
|
};
|
|
|
|
ctrl = $controller(LoginInitialCtrl, {
|
|
|
|
$scope: scope,
|
2014-11-12 10:12:26 -05:00
|
|
|
$routeParams: {},
|
2014-12-17 16:41:57 -05:00
|
|
|
$q: window.qMock,
|
2014-11-25 12:19:40 -05:00
|
|
|
newsletter: newsletter,
|
2015-02-20 11:55:11 -05:00
|
|
|
publickeyVerifier: verifierMock,
|
2014-11-25 12:19:40 -05:00
|
|
|
email: emailMock,
|
|
|
|
auth: authMock
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
afterEach(function() {});
|
2014-10-07 14:32:23 -04:00
|
|
|
|
|
|
|
describe('initial state', function() {
|
|
|
|
it('should be well defined', function() {
|
|
|
|
expect(scope.state.ui).to.equal(1);
|
|
|
|
});
|
|
|
|
});
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('go to import key', function() {
|
2014-11-12 10:12:26 -05:00
|
|
|
it('should not continue if terms are not accepted', function() {
|
|
|
|
scope.agree = undefined;
|
2014-07-31 15:39:43 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
scope.importKey();
|
2014-11-12 10:12:26 -05:00
|
|
|
|
|
|
|
expect(scope.errMsg).to.contain('Terms');
|
|
|
|
expect(newsletterStub.called).to.be.false;
|
2014-07-31 15:39:43 -04:00
|
|
|
});
|
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should work', function() {
|
2014-11-12 10:12:26 -05:00
|
|
|
scope.agree = true;
|
2014-10-07 14:32:23 -04:00
|
|
|
scope.importKey();
|
2014-11-12 10:12:26 -05:00
|
|
|
expect(newsletterStub.calledOnce).to.be.true;
|
2014-10-07 14:32:23 -04:00
|
|
|
expect(location.$$path).to.equal('/login-new-device');
|
|
|
|
});
|
|
|
|
});
|
2014-07-31 15:39:43 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('generate key', function() {
|
2015-01-20 06:55:19 -05:00
|
|
|
beforeEach(function() {
|
|
|
|
authMock.realname = 'Hans Dampf';
|
|
|
|
});
|
|
|
|
|
2014-11-12 10:12:26 -05:00
|
|
|
it('should not continue if terms are not accepted', function() {
|
|
|
|
scope.agree = undefined;
|
2014-04-15 11:43:33 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
scope.generateKey();
|
2014-11-12 10:12:26 -05:00
|
|
|
|
|
|
|
expect(scope.errMsg).to.contain('Terms');
|
|
|
|
expect(scope.state.ui).to.equal(1);
|
|
|
|
expect(newsletterStub.called).to.be.false;
|
2014-04-15 11:43:33 -04:00
|
|
|
});
|
|
|
|
|
2014-12-17 16:41:57 -05:00
|
|
|
it('should fail due to error in emailDao.unlock', function(done) {
|
2014-11-12 10:12:26 -05:00
|
|
|
scope.agree = true;
|
2014-04-15 11:43:33 -04:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
emailMock.unlock.withArgs({
|
2015-01-20 06:55:19 -05:00
|
|
|
passphrase: undefined,
|
|
|
|
realname: authMock.realname
|
2014-12-17 16:41:57 -05:00
|
|
|
}).returns(rejects(new Error('asdf')));
|
|
|
|
authMock.storeCredentials.returns(resolves());
|
|
|
|
|
|
|
|
scope.generateKey().then(function() {
|
|
|
|
expect(scope.errMsg).to.exist;
|
|
|
|
expect(scope.state.ui).to.equal(1);
|
|
|
|
expect(newsletterStub.called).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2014-07-31 13:08:21 -04:00
|
|
|
|
2014-12-17 16:41:57 -05:00
|
|
|
it('should unlock crypto', function(done) {
|
2014-11-12 10:12:26 -05:00
|
|
|
scope.agree = true;
|
2014-09-12 11:11:05 -04:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
emailMock.unlock.withArgs({
|
2015-01-20 06:55:19 -05:00
|
|
|
passphrase: undefined,
|
|
|
|
realname: authMock.realname
|
2015-02-20 11:55:11 -05:00
|
|
|
}).returns(resolves('foofoo'));
|
2014-12-17 16:41:57 -05:00
|
|
|
authMock.storeCredentials.returns(resolves());
|
|
|
|
|
|
|
|
scope.generateKey().then(function() {
|
|
|
|
expect(scope.errMsg).to.not.exist;
|
|
|
|
expect(scope.state.ui).to.equal(2);
|
|
|
|
expect(newsletterStub.called).to.be.true;
|
2015-02-27 14:04:44 -05:00
|
|
|
expect(location.$$path).to.equal('/login-privatekey-upload');
|
2014-12-17 16:41:57 -05:00
|
|
|
expect(emailMock.unlock.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|