2018-01-20 18:56:17 -08:00
|
|
|
/* global it:false */
|
|
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var async = require('async'),
|
|
|
|
|
config = require('../config.js'),
|
|
|
|
|
database = require('../database.js'),
|
|
|
|
|
expect = require('expect.js'),
|
|
|
|
|
mail = require('../mail.js'),
|
2018-01-21 00:06:08 -08:00
|
|
|
maildb = require('../maildb.js');
|
|
|
|
|
|
|
|
|
|
const DOMAIN_0 = {
|
|
|
|
|
domain: 'example.com',
|
|
|
|
|
zoneName: 'example.com',
|
|
|
|
|
provider: 'manual',
|
|
|
|
|
config: { }
|
|
|
|
|
};
|
2018-01-20 18:56:17 -08:00
|
|
|
|
|
|
|
|
function setup(done) {
|
|
|
|
|
config._reset();
|
|
|
|
|
config.set('fqdn', 'example.com');
|
|
|
|
|
config.set('provider', 'caas');
|
|
|
|
|
|
|
|
|
|
async.series([
|
|
|
|
|
database.initialize,
|
2018-01-21 00:06:08 -08:00
|
|
|
database._clear,
|
|
|
|
|
// DOMAIN_0 already added for test through domaindb.addDefaultDomain(),
|
|
|
|
|
maildb.add.bind(null, DOMAIN_0.domain)
|
2018-01-20 18:56:17 -08:00
|
|
|
], done);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cleanup(done) {
|
|
|
|
|
async.series([
|
|
|
|
|
database._clear,
|
|
|
|
|
database.uninitialize
|
|
|
|
|
], done);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-21 00:06:08 -08:00
|
|
|
describe('Mail', function () {
|
|
|
|
|
before(setup);
|
|
|
|
|
after(cleanup);
|
2018-01-20 18:56:17 -08:00
|
|
|
|
2018-01-21 00:06:08 -08:00
|
|
|
describe('values', function () {
|
|
|
|
|
it('can get default', function (done) {
|
|
|
|
|
mail.get(DOMAIN_0.domain, function (error, mailConfig) {
|
2018-01-20 18:56:17 -08:00
|
|
|
expect(error).to.be(null);
|
2018-01-21 00:06:08 -08:00
|
|
|
expect(mailConfig.enabled).to.be(false);
|
|
|
|
|
expect(mailConfig.mailFromValidation).to.be(true);
|
|
|
|
|
expect(mailConfig.catchAll).to.eql([]);
|
|
|
|
|
expect(mailConfig.relay).to.eql({ provider: 'cloudron-smtp' });
|
2018-01-20 18:56:17 -08:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-01-21 00:06:08 -08:00
|
|
|
it('can set mail from validation', function (done) {
|
|
|
|
|
mail.setMailFromValidation(DOMAIN_0.domain, false, function (error) {
|
2018-01-20 18:56:17 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
|
2018-01-21 00:06:08 -08:00
|
|
|
mail.get(DOMAIN_0.domain, function (error, mailConfig) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(mailConfig.mailFromValidation).to.be(false);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
2018-01-20 18:56:17 -08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can set catch all address', function (done) {
|
2018-01-21 00:06:08 -08:00
|
|
|
mail.setCatchAllAddress(DOMAIN_0.domain, [ 'user1', 'user2' ], function (error) {
|
2018-01-20 18:56:17 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
|
2018-01-21 00:06:08 -08:00
|
|
|
mail.get(DOMAIN_0.domain, function (error, mailConfig) {
|
2018-01-20 18:56:17 -08:00
|
|
|
expect(error).to.be(null);
|
2018-01-21 00:06:08 -08:00
|
|
|
expect(mailConfig.catchAll).to.eql([ 'user1', 'user2' ]);
|
2018-01-20 18:56:17 -08:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can set mail relay', function (done) {
|
|
|
|
|
var relay = { provider: 'external-smtp', host: 'mx.foo.com', port: 25 };
|
2018-01-21 00:06:08 -08:00
|
|
|
|
|
|
|
|
mail.setMailRelay(DOMAIN_0.domain, relay, function (error) { // skip the mail server verify()
|
2018-01-20 18:56:17 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
|
2018-01-21 00:06:08 -08:00
|
|
|
mail.get(DOMAIN_0.domain, function (error, mailConfig) {
|
2018-01-20 18:56:17 -08:00
|
|
|
expect(error).to.be(null);
|
2018-01-21 00:06:08 -08:00
|
|
|
expect(mailConfig.relay).to.eql(relay);
|
2018-01-20 18:56:17 -08:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-01-21 00:06:08 -08:00
|
|
|
it('can enable mail', function (done) {
|
|
|
|
|
mail.setMailEnabled(DOMAIN_0.domain, true, function (error) {
|
2018-01-20 18:56:17 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
|
2018-01-21 00:06:08 -08:00
|
|
|
mail.get(DOMAIN_0.domain, function (error, mailConfig) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(mailConfig.enabled).to.be(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2018-01-20 18:56:17 -08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|