2018-01-20 18:56:17 -08:00
|
|
|
/* global it:false */
|
|
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
2018-05-29 23:59:53 +02:00
|
|
|
/* global beforeEach:false */
|
2018-01-20 18:56:17 -08:00
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var async = require('async'),
|
|
|
|
|
config = require('../config.js'),
|
|
|
|
|
database = require('../database.js'),
|
2018-01-26 21:10:53 +01:00
|
|
|
domains = require('../domains.js'),
|
2018-01-20 18:56:17 -08:00
|
|
|
expect = require('expect.js'),
|
|
|
|
|
mail = require('../mail.js'),
|
2018-05-29 23:59:53 +02:00
|
|
|
maildb = require('../maildb.js'),
|
2019-05-03 16:27:47 -07:00
|
|
|
nock = require('nock');
|
2018-01-21 00:06:08 -08:00
|
|
|
|
|
|
|
|
const DOMAIN_0 = {
|
|
|
|
|
domain: 'example.com',
|
|
|
|
|
zoneName: 'example.com',
|
|
|
|
|
provider: 'manual',
|
2018-01-26 21:10:53 +01:00
|
|
|
config: {},
|
2018-01-31 18:09:38 +01:00
|
|
|
fallbackCertificate: null,
|
|
|
|
|
tlsConfig: { provider: 'fallback' }
|
2018-01-21 00:06:08 -08:00
|
|
|
};
|
2018-01-20 18:56:17 -08:00
|
|
|
|
2018-11-10 00:22:38 -08:00
|
|
|
const AUDIT_SOURCE = {
|
|
|
|
|
ip: '1.2.3.4'
|
|
|
|
|
};
|
|
|
|
|
|
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,
|
2018-11-10 00:43:46 -08:00
|
|
|
domains.add.bind(null, DOMAIN_0.domain, DOMAIN_0, AUDIT_SOURCE),
|
2019-05-03 16:27:47 -07:00
|
|
|
mail.addDomain.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-05-29 23:59:53 +02:00
|
|
|
beforeEach(nock.cleanAll);
|
|
|
|
|
|
2018-01-21 00:06:08 -08:00
|
|
|
describe('values', function () {
|
|
|
|
|
it('can get default', function (done) {
|
2018-04-03 14:37:52 -07:00
|
|
|
mail.getDomain(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-04-03 14:37:52 -07:00
|
|
|
mail.getDomain(DOMAIN_0.domain, function (error, mailConfig) {
|
2018-01-21 00:06:08 -08:00
|
|
|
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-04-03 14:37:52 -07:00
|
|
|
mail.getDomain(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
|
|
|
|
2018-01-21 00:40:30 -08:00
|
|
|
maildb.update(DOMAIN_0.domain, { relay: relay }, function (error) { // skip the mail server verify()
|
2018-01-20 18:56:17 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
|
2018-04-03 14:37:52 -07:00
|
|
|
mail.getDomain(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) {
|
2018-11-10 00:22:38 -08:00
|
|
|
mail.setMailEnabled(DOMAIN_0.domain, true, AUDIT_SOURCE, function (error) {
|
2018-01-20 18:56:17 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
|
2018-04-03 14:37:52 -07:00
|
|
|
mail.getDomain(DOMAIN_0.domain, function (error, mailConfig) {
|
2018-01-21 00:06:08 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(mailConfig.enabled).to.be(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2018-01-20 18:56:17 -08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|