1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-04 16:25:07 -05:00
mail/test/unit/login-set-credentials-ctrl-test.js
Felix Hammerl 3e80138a10 [WO-188][WO-421] introduce password-based login
* add custom login ability
* encrypt email password
* allow arbitrary tcp connections
* add db migration script v3 -> v4
* add bug reporting capability with the axe logger
* fix nonexistent folder handling
* enable message upload after sent
* use plain text alternative body when replying to html mails
* Move set-credentials.* -> login-set-credentials.*
* Use login styles for set-credentials
* Make OAuth optional
2014-07-23 13:51:10 +02:00

100 lines
3.7 KiB
JavaScript

define(function(require) {
'use strict';
var expect = chai.expect,
angular = require('angular'),
mocks = require('angularMocks'),
ImapClient = require('imap-client'),
SmtpClient = require('smtpclient'),
SetCredentialsCtrl = require('js/controller/login-set-credentials'),
appController = require('js/app-controller');
describe('Login (Set Credentials) Controller unit test', function() {
var scope, location, setCredentialsCtrl;
var imap, smtp;
var origAuth;
var provider = 'providerproviderprovider';
beforeEach(function() {
origAuth = appController._auth;
appController._auth = {};
imap = sinon.createStubInstance(ImapClient);
smtp = sinon.createStubInstance(SmtpClient);
angular.module('setcredentialstest', []);
mocks.module('setcredentialstest');
mocks.inject(function($rootScope, $controller, $location) {
scope = $rootScope.$new();
location = $location;
location.search({
provider: provider
});
scope.state = {};
setCredentialsCtrl = $controller(SetCredentialsCtrl, {
$scope: scope
});
});
});
afterEach(function() {
appController._auth = origAuth;
});
describe('set credentials', function() {
it('should work', function(done) {
var imapCert = 'imapcertimapcertimapcertimapcertimapcertimapcert',
smtpCert = 'smtpcertsmtpcertsmtpcertsmtpcertsmtpcertsmtpcert';
var emailAddress, password, smtpHost, smtpPort, smtpSecure, imapHost, imapPort, imapSecure, realname;
scope.emailAddress = emailAddress = 'emailemailemailemail';
scope.password = password = 'passwdpasswdpasswdpasswd';
scope.smtpHost = smtpHost = 'hosthosthost';
scope.smtpPort = smtpPort = 1337;
scope.smtpSecure = smtpSecure = true;
scope.imapHost = imapHost = 'hosthosthost';
scope.imapPort = imapPort = 1337;
scope.imapSecure = imapSecure = true;
scope.realname = realname = 'peter pan';
imap.login.yields();
appController._auth.setCredentials = function(args) {
expect(smtp.connect.calledOnce).to.be.true;
expect(imap.login.calledOnce).to.be.true;
expect(args).to.deep.equal({
provider: provider,
emailAddress: scope.emailAddress,
username: scope.username || scope.emailAddress,
realname: scope.realname,
password: scope.password,
imap: {
host: scope.imapHost.toLowerCase(),
port: scope.imapPort,
secure: scope.imapSecure,
ca: scope.imapCert,
pinned: false
},
smtp: {
host: scope.smtpHost.toLowerCase(),
port: scope.smtpPort,
secure: scope.smtpSecure,
ca: scope.smtpCert,
pinned: false
}
});
done();
};
scope.test(imap, smtp);
imap.onCert(imapCert);
smtp.oncert(smtpCert);
smtp.onidle();
});
});
});
});