mailboxdb: merge into mail.js
This commit is contained in:
@@ -15,7 +15,6 @@ const appdb = require('../appdb.js'),
|
||||
ldap = require('ldapjs'),
|
||||
ldapServer = require('../ldap.js'),
|
||||
mail = require('../mail.js'),
|
||||
mailboxdb = require('../mailboxdb.js'),
|
||||
safe = require('safetydance'),
|
||||
util = require('util');
|
||||
|
||||
@@ -61,12 +60,19 @@ async function ldapSearch(dn, opts) {
|
||||
}
|
||||
|
||||
describe('Ldap', function () {
|
||||
const { setup, cleanup, admin, user, app, domain, mailbox, mailAlias, mailboxName } = common;
|
||||
const { setup, cleanup, admin, user, app, domain, auditSource } = common;
|
||||
let group;
|
||||
|
||||
const mailboxName = 'support';
|
||||
const mailbox = `support@${domain.domain}`;
|
||||
const mailAliasName = 'alsosupport';
|
||||
const mailAlias = `alsosupport@${domain.domain}`;
|
||||
|
||||
before(function (done) {
|
||||
async.series([
|
||||
setup,
|
||||
async () => await mail.addMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: true }, auditSource),
|
||||
async () => await mail.setAliases(mailboxName, domain.domain, [ { name: mailAliasName, domain: domain.domain} ], auditSource),
|
||||
ldapServer.start.bind(null),
|
||||
async () => {
|
||||
group = await groups.add({ name: 'ldap-test' });
|
||||
@@ -285,13 +291,11 @@ describe('Ldap', function () {
|
||||
});
|
||||
|
||||
it('cannot get inactive mailbox', async function () {
|
||||
const updateMailbox = util.promisify(mailboxdb.updateMailbox);
|
||||
|
||||
await updateMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: false });
|
||||
await mail.updateMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: false }, auditSource);
|
||||
const [error] = await safe(ldapSearch(`cn=${mailbox},ou=mailboxes,dc=cloudron`, 'objectclass=mailbox'));
|
||||
expect(error).to.be.a(ldap.NoSuchObjectError);
|
||||
|
||||
await updateMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: true });
|
||||
await mail.updateMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: true }, auditSource);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -317,8 +321,8 @@ describe('Ldap', function () {
|
||||
describe('search mailing list', function () {
|
||||
const LIST_NAME = 'devs', LIST = `devs@${domain.domain}`;
|
||||
|
||||
before(function (done) {
|
||||
mailboxdb.addList(LIST_NAME, domain.domain, { members: [ mailbox , 'outsider@external.com' ], membersOnly: false, active: true }, done);
|
||||
before(async function () {
|
||||
await mail.addList(LIST_NAME, domain.domain, { members: [ mailbox , 'outsider@external.com' ], membersOnly: false, active: true }, auditSource);
|
||||
});
|
||||
|
||||
it('get specific list', async function () {
|
||||
@@ -334,9 +338,7 @@ describe('Ldap', function () {
|
||||
});
|
||||
|
||||
it('inactive list', async function () {
|
||||
const updateList = util.promisify(mailboxdb.updateList);
|
||||
|
||||
await updateList(LIST_NAME, domain.domain, { members: [ mailbox , 'outsider@external.com' ], membersOnly: false, active: false });
|
||||
await mail.updateList(LIST_NAME, domain.domain, { members: [ mailbox , 'outsider@external.com' ], membersOnly: false, active: false }, auditSource);
|
||||
const [error] = await safe(ldapSearch('cn=devs@example.com,ou=mailinglists,dc=cloudron', 'objectclass=mailGroup'));
|
||||
expect(error).to.be.a(ldap.NoSuchObjectError);
|
||||
});
|
||||
@@ -390,13 +392,11 @@ describe('Ldap', function () {
|
||||
});
|
||||
|
||||
it('does not allow for inactive mailbox', async function () {
|
||||
const updateMailbox = util.promisify(mailboxdb.updateMailbox);
|
||||
|
||||
await mail._updateDomain(domain.domain, { enabled: true });
|
||||
await updateMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: false });
|
||||
await mail.updateMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: false }, auditSource);
|
||||
const [error] = await safe(ldapBind(`cn=${mailbox},ou=sendmail,dc=cloudron`, 'badpassword'));
|
||||
expect(error).to.be.a(ldap.NoSuchObjectError);
|
||||
await updateMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: true });
|
||||
await mail.updateMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: true }, auditSource);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -444,14 +444,12 @@ describe('Ldap', function () {
|
||||
});
|
||||
|
||||
it('does not allow for inactive mailbox', async function () {
|
||||
const updateMailbox = util.promisify(mailboxdb.updateMailbox);
|
||||
|
||||
await mail._updateDomain(domain.domain, { enabled: true });
|
||||
await updateMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: false });
|
||||
await mail.updateMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: false }, auditSource);
|
||||
const [error] = await safe(ldapBind(`cn=${mailbox},ou=recvmail,dc=cloudron`, 'badpassword'));
|
||||
expect(error).to.be.a(ldap.NoSuchObjectError);
|
||||
await mail._updateDomain(domain.domain, { enabled: false });
|
||||
await updateMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: true });
|
||||
await mail.updateMailbox(mailboxName, domain.domain, { ownerId: user.id, ownerType: mail.OWNERTYPE_USER, active: true }, auditSource);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user