merge domaindb.js into domains.js

This commit is contained in:
Girish Ramakrishnan
2021-08-13 17:22:28 -07:00
parent 74febcd30a
commit 5bcf1bc47b
40 changed files with 2233 additions and 2395 deletions

View File

@@ -10,7 +10,7 @@ const appdb = require('../appdb.js'),
async = require('async'),
BoxError = require('../boxerror.js'),
database = require('../database'),
domaindb = require('../domaindb'),
domains = require('../domains.js'),
expect = require('expect.js'),
mailboxdb = require('../mailboxdb.js'),
reverseProxy = require('../reverseproxy.js'),
@@ -27,6 +27,8 @@ const DOMAIN_0 = {
};
DOMAIN_0.fallbackCertificate = reverseProxy.generateFallbackCertificateSync(DOMAIN_0.domain);
const auditSource = { ip: '1.2.3.4' };
const DOMAIN_1 = {
domain: 'foo.cloudron.io',
zoneName: 'cloudron.io',
@@ -52,158 +54,6 @@ describe('database', function () {
], done);
});
describe('domains', function () {
after(function (done) {
database._clear(done);
});
it('can add domain', function (done) {
domaindb.add(DOMAIN_0.domain, DOMAIN_0, done);
});
it('can add another domain', function (done) {
domaindb.add(DOMAIN_1.domain, DOMAIN_1, done);
});
it('cannot add same domain twice', function (done) {
domaindb.add(DOMAIN_0.domain, DOMAIN_0, function (error) {
expect(error).to.be.ok();
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
done();
});
});
it('can get domain', function (done) {
domaindb.get(DOMAIN_0.domain, function (error, result) {
expect(error).to.equal(null);
expect(result).to.be.an('object');
expect(result.domain).to.equal(DOMAIN_0.domain);
expect(result.zoneName).to.equal(DOMAIN_0.zoneName);
expect(result.config).to.eql(DOMAIN_0.config);
done();
});
});
it('can update domain', function (done) {
const newConfig = { provider: 'manual' };
const newTlsConfig = { provider: 'foobar' };
domaindb.update(DOMAIN_1.domain, { provider: DOMAIN_1.provider, config: newConfig, tlsConfig: newTlsConfig }, function (error) {
expect(error).to.equal(null);
domaindb.get(DOMAIN_1.domain, function (error, result) {
expect(error).to.equal(null);
expect(result).to.be.an('object');
expect(result.domain).to.equal(DOMAIN_1.domain);
expect(result.zoneName).to.equal(DOMAIN_1.zoneName);
expect(result.provider).to.equal(DOMAIN_1.provider);
expect(result.config).to.eql(newConfig);
expect(result.tlsConfig).to.eql(newTlsConfig);
DOMAIN_1.config = newConfig;
DOMAIN_1.tlsConfig = newTlsConfig;
done();
});
});
});
it('can get all domains', function (done) {
domaindb.getAll(function (error, result) {
expect(error).to.equal(null);
expect(result).to.be.an('array');
expect(result.length).to.equal(2);
// sorted by domain
expect(result[0].domain).to.equal(DOMAIN_1.domain);
expect(result[0].zoneName).to.equal(DOMAIN_1.zoneName);
expect(result[0].provider).to.equal(DOMAIN_1.provider);
expect(result[0].config).to.eql(DOMAIN_1.config);
expect(result[0].tlsConfig).to.eql(DOMAIN_1.tlsConfig);
expect(result[1].domain).to.equal(DOMAIN_0.domain);
expect(result[1].zoneName).to.equal(DOMAIN_0.zoneName);
expect(result[1].provider).to.equal(DOMAIN_0.provider);
expect(result[1].config).to.eql(DOMAIN_0.config);
expect(result[1].tlsConfig).to.eql(DOMAIN_0.tlsConfig);
done();
});
});
it('cannot delete non-existing domain', function (done) {
domaindb.del('not.exists', function (error) {
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
done();
});
});
var APP_0 = {
id: 'appid-0',
appStoreId: 'appStoreId-0',
installationState: apps.ISTATE_PENDING_INSTALL,
error: null,
runState: 'running',
location: 'some-location-0',
domain: DOMAIN_0.domain,
manifest: { version: '0.1', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0' },
containerId: null,
containerIp: null,
portBindings: { port: { hostPort: 5678, type: 'tcp' } },
health: null,
accessRestriction: null,
lastBackupId: null,
memoryLimit: 4294967296,
cpuShares: 1024,
sso: true,
debugMode: null,
reverseProxyConfig: {},
enableBackup: true,
env: {},
mailboxName: 'talktome',
mailboxDomain: DOMAIN_0.domain,
enableAutomaticUpdate: true,
dataDir: null,
tags: [],
label: null,
taskId: null,
mounts: [],
proxyAuth: false,
servicesConfig: {},
hasIcon: false,
hasAppStoreIcon: false
};
it('cannot delete referenced domain', function (done) {
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0, function (error) {
expect(error).to.be(null);
domaindb.del(DOMAIN_0.domain, function (error) {
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.CONFLICT);
appdb.del(APP_0.id, done);
});
});
});
it('can delete existing domain', function (done) {
domaindb.del(DOMAIN_0.domain, function (error) {
expect(error).to.be(null);
domaindb.get(DOMAIN_0.domain, function (error) {
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
done();
});
});
});
});
describe('apps', function () {
var APP_0 = {
id: 'appid-0',
@@ -286,7 +136,7 @@ describe('database', function () {
before(function (done) {
async.series([
database._clear,
domaindb.add.bind(null, DOMAIN_0.domain, DOMAIN_0)
domains.add.bind(null, DOMAIN_0.domain, DOMAIN_0, auditSource)
], done);
});
@@ -626,7 +476,7 @@ describe('database', function () {
describe('mailboxes', function () {
before(function (done) {
async.series([
domaindb.add.bind(null, DOMAIN_0.domain, DOMAIN_0),
domains.add.bind(null, DOMAIN_0.domain, DOMAIN_0),
], done);
});