merge maildb.js into mail.js
This commit is contained in:
@@ -16,7 +16,6 @@ const appdb = require('../appdb.js'),
|
||||
expect = require('expect.js'),
|
||||
hat = require('../hat.js'),
|
||||
mailboxdb = require('../mailboxdb.js'),
|
||||
maildb = require('../maildb.js'),
|
||||
reverseProxy = require('../reverseproxy.js'),
|
||||
settingsdb = require('../settingsdb.js'),
|
||||
taskdb = require('../taskdb.js'),
|
||||
@@ -1287,44 +1286,4 @@ describe('database', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('mail', function () {
|
||||
const MAIL_DOMAIN_0 = {
|
||||
domain: DOMAIN_0.domain,
|
||||
enabled: false,
|
||||
relay: { provider: 'cloudron-smtp' },
|
||||
catchAll: [ ],
|
||||
mailFromValidation: true,
|
||||
dkimSelector: 'cloudron',
|
||||
banner: { html: null, text: null }
|
||||
};
|
||||
|
||||
before(function (done) {
|
||||
domaindb.add(DOMAIN_0.domain, DOMAIN_0, done);
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
database._clear(done);
|
||||
});
|
||||
|
||||
it('can get all domains', function (done) {
|
||||
maildb.list(function (error, result) {
|
||||
expect(error).to.equal(null);
|
||||
expect(result).to.be.an(Array);
|
||||
expect(result[0]).to.be.an('object');
|
||||
expect(result[0].domain).to.eql(MAIL_DOMAIN_0.domain);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can get domain', function (done) {
|
||||
maildb.get(MAIL_DOMAIN_0.domain, function (error, result) {
|
||||
expect(error).to.equal(null);
|
||||
expect(result).to.be.an('object');
|
||||
expect(result).to.eql(MAIL_DOMAIN_0);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+45
-89
@@ -2,116 +2,72 @@
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
/* global beforeEach:false */
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
database = require('../database.js'),
|
||||
domains = require('../domains.js'),
|
||||
const common = require('./common.js'),
|
||||
expect = require('expect.js'),
|
||||
mail = require('../mail.js'),
|
||||
maildb = require('../maildb.js'),
|
||||
nock = require('nock'),
|
||||
settings = require('../settings.js');
|
||||
|
||||
const DOMAIN_0 = {
|
||||
domain: 'example.com',
|
||||
zoneName: 'example.com',
|
||||
provider: 'manual',
|
||||
config: {},
|
||||
fallbackCertificate: null,
|
||||
tlsConfig: { provider: 'fallback' },
|
||||
wellKnown: null
|
||||
};
|
||||
|
||||
const AUDIT_SOURCE = {
|
||||
ip: '1.2.3.4'
|
||||
};
|
||||
|
||||
function setup(done) {
|
||||
async.series([
|
||||
database.initialize,
|
||||
database._clear,
|
||||
domains.add.bind(null, DOMAIN_0.domain, DOMAIN_0, AUDIT_SOURCE),
|
||||
settings.setDashboardLocation.bind(null, DOMAIN_0.domain, 'my.' + DOMAIN_0.domain),
|
||||
], done);
|
||||
}
|
||||
|
||||
function cleanup(done) {
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
}
|
||||
mail = require('../mail.js');
|
||||
|
||||
describe('Mail', function () {
|
||||
const { setup, cleanup, DOMAIN, AUDIT_SOURCE } = common;
|
||||
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
beforeEach(nock.cleanAll);
|
||||
|
||||
describe('values', function () {
|
||||
it('can get default', function (done) {
|
||||
mail.getDomain(DOMAIN_0.domain, function (error, mailConfig) {
|
||||
expect(error).to.be(null);
|
||||
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' });
|
||||
done();
|
||||
});
|
||||
it('can get default', async function () {
|
||||
const mailConfig = await mail.getDomain(DOMAIN.domain);
|
||||
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' });
|
||||
});
|
||||
|
||||
it('can set mail from validation', function (done) {
|
||||
mail.setMailFromValidation(DOMAIN_0.domain, false, function (error) {
|
||||
expect(error).to.be(null);
|
||||
|
||||
mail.getDomain(DOMAIN_0.domain, function (error, mailConfig) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailConfig.mailFromValidation).to.be(false);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('can get all domains', async function () {
|
||||
const result = await mail.listDomains();
|
||||
expect(result).to.be.an(Array);
|
||||
expect(result[0]).to.be.an('object');
|
||||
expect(result[0].domain).to.eql(DOMAIN.domain);
|
||||
});
|
||||
|
||||
it('can set catch all address', function (done) {
|
||||
mail.setCatchAllAddress(DOMAIN_0.domain, [ 'user1', 'user2' ], function (error) {
|
||||
expect(error).to.be(null);
|
||||
it('can set mail from validation', async function () {
|
||||
await mail.setMailFromValidation(DOMAIN.domain, false);
|
||||
|
||||
mail.getDomain(DOMAIN_0.domain, function (error, mailConfig) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailConfig.catchAll).to.eql([ 'user1', 'user2' ]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
const mailConfig = await mail.getDomain(DOMAIN.domain);
|
||||
expect(mailConfig.mailFromValidation).to.be(false);
|
||||
});
|
||||
|
||||
it('can set mail relay', function (done) {
|
||||
var relay = { provider: 'external-smtp', host: 'mx.foo.com', port: 25 };
|
||||
it('can set catch all address', async function () {
|
||||
await mail.setCatchAllAddress(DOMAIN.domain, [ 'user1', 'user2' ]);
|
||||
|
||||
maildb.update(DOMAIN_0.domain, { relay: relay }, function (error) { // skip the mail server verify()
|
||||
expect(error).to.be(null);
|
||||
|
||||
mail.getDomain(DOMAIN_0.domain, function (error, mailConfig) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailConfig.relay).to.eql(relay);
|
||||
done();
|
||||
});
|
||||
});
|
||||
const mailConfig = await mail.getDomain(DOMAIN.domain);
|
||||
expect(mailConfig.catchAll).to.eql([ 'user1', 'user2' ]);
|
||||
});
|
||||
|
||||
it('can enable mail', function (done) {
|
||||
mail.setMailEnabled(DOMAIN_0.domain, true, AUDIT_SOURCE, function (error) {
|
||||
expect(error).to.be(null);
|
||||
it('can set mail relay', async function () {
|
||||
const relay = { provider: 'external-smtp', host: 'mx.foo.com', port: 25 };
|
||||
|
||||
mail.getDomain(DOMAIN_0.domain, function (error, mailConfig) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailConfig.enabled).to.be(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
await mail.setMailRelay(DOMAIN.domain, relay, { skipVerify: true });
|
||||
|
||||
const mailConfig = await mail.getDomain(DOMAIN.domain);
|
||||
expect(mailConfig.relay).to.eql(relay);
|
||||
});
|
||||
|
||||
it('can set banner', async function () {
|
||||
const banner = { text: 'text', html: 'html' };
|
||||
|
||||
await mail.setBanner(DOMAIN.domain, banner);
|
||||
|
||||
const mailConfig = await mail.getDomain(DOMAIN.domain);
|
||||
expect(mailConfig.banner).to.eql(banner);
|
||||
});
|
||||
|
||||
it('can enable mail', async function () {
|
||||
await mail.setMailEnabled(DOMAIN.domain, true, AUDIT_SOURCE);
|
||||
|
||||
const mailConfig = await mail.getDomain(DOMAIN.domain);
|
||||
expect(mailConfig.enabled).to.be(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,7 +11,6 @@ const async = require('async'),
|
||||
expect = require('expect.js'),
|
||||
fs = require('fs'),
|
||||
mailboxdb = require('../mailboxdb.js'),
|
||||
maildb = require('../maildb.js'),
|
||||
mailer = require('../mailer.js'),
|
||||
paths = require('../paths.js'),
|
||||
provision = require('../provision.js'),
|
||||
@@ -555,25 +554,6 @@ describe('User', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('succeeds with email enabled', function (done) {
|
||||
// use maildb to not trigger further events
|
||||
maildb.update(DOMAIN_0.domain, { enabled: true }, function (error) {
|
||||
expect(error).not.to.be.ok();
|
||||
|
||||
users.get(userObject.id, function (error, result) {
|
||||
expect(error).to.not.be.ok();
|
||||
expect(result).to.be.ok();
|
||||
expect(result.id).to.equal(userObject.id);
|
||||
expect(result.email).to.equal(EMAIL.toLowerCase());
|
||||
expect(result.fallbackEmail).to.equal(EMAIL.toLowerCase());
|
||||
expect(result.username).to.equal(USERNAME.toLowerCase());
|
||||
expect(result.displayName).to.equal(DISPLAY_NAME);
|
||||
|
||||
maildb.update(DOMAIN_0.domain, { enabled: false }, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('update', function () {
|
||||
|
||||
Reference in New Issue
Block a user