Merge remote-tracking branch 'origin/master' into feature/gcs
# Conflicts: # webadmin/src/views/certs.js # webadmin/src/views/settings.js
This commit is contained in:
+45
-19
@@ -12,6 +12,7 @@ var appdb = require('../appdb.js'),
|
||||
config = require('../config.js'),
|
||||
constants = require('../constants.js'),
|
||||
database = require('../database.js'),
|
||||
domaindb = require('../domaindb.js'),
|
||||
expect = require('expect.js'),
|
||||
groupdb = require('../groupdb.js'),
|
||||
groups = require('../groups.js'),
|
||||
@@ -66,10 +67,23 @@ describe('Apps', function () {
|
||||
name: 'group1'
|
||||
};
|
||||
|
||||
const DOMAIN_0 = {
|
||||
domain: 'example.com',
|
||||
zoneName: 'example.com',
|
||||
config: { provider: 'manual' }
|
||||
};
|
||||
|
||||
const DOMAIN_1 = {
|
||||
domain: 'example2.com',
|
||||
zoneName: 'example2.com',
|
||||
config: { provider: 'manual' }
|
||||
};
|
||||
|
||||
var APP_0 = {
|
||||
id: 'appid-0',
|
||||
appStoreId: 'appStoreId-0',
|
||||
location: 'some-location-0',
|
||||
domain: DOMAIN_0.domain,
|
||||
manifest: {
|
||||
version: '0.1', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0',
|
||||
tcpPorts: {
|
||||
@@ -88,6 +102,7 @@ describe('Apps', function () {
|
||||
id: 'appid-1',
|
||||
appStoreId: 'appStoreId-1',
|
||||
location: 'some-location-1',
|
||||
domain: DOMAIN_0.domain,
|
||||
manifest: {
|
||||
version: '0.1', dockerImage: 'docker/app1', healthCheckPath: '/', httpPort: 80, title: 'app1',
|
||||
tcpPorts: {}
|
||||
@@ -101,6 +116,7 @@ describe('Apps', function () {
|
||||
id: 'appid-2',
|
||||
appStoreId: 'appStoreId-2',
|
||||
location: 'some-location-2',
|
||||
domain: DOMAIN_1.domain,
|
||||
manifest: {
|
||||
version: '0.1', dockerImage: 'docker/app2', healthCheckPath: '/', httpPort: 80, title: 'app2',
|
||||
tcpPorts: {}
|
||||
@@ -111,10 +127,15 @@ describe('Apps', function () {
|
||||
};
|
||||
|
||||
before(function (done) {
|
||||
config._reset();
|
||||
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
|
||||
async.series([
|
||||
database.initialize,
|
||||
database._clear,
|
||||
// DOMAIN_0 already added for test through domaindb.addDefaultDomain()
|
||||
domaindb.add.bind(null, DOMAIN_1.domain, DOMAIN_1.zoneName, DOMAIN_1.config),
|
||||
userdb.add.bind(null, ADMIN_0.id, ADMIN_0),
|
||||
userdb.add.bind(null, USER_0.id, USER_0),
|
||||
userdb.add.bind(null, USER_1.id, USER_1),
|
||||
@@ -122,48 +143,51 @@ describe('Apps', function () {
|
||||
groupdb.add.bind(null, GROUP_1.id, GROUP_1.name),
|
||||
groups.addMember.bind(null, constants.ADMIN_GROUP_ID, ADMIN_0.id),
|
||||
groups.addMember.bind(null, GROUP_0.id, USER_1.id),
|
||||
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.portBindings, APP_0),
|
||||
appdb.add.bind(null, APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, APP_1.portBindings, APP_1),
|
||||
appdb.add.bind(null, APP_2.id, APP_2.appStoreId, APP_2.manifest, APP_2.location, APP_2.portBindings, APP_2),
|
||||
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0),
|
||||
appdb.add.bind(null, APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, APP_1.domain, APP_1.portBindings, APP_1),
|
||||
appdb.add.bind(null, APP_2.id, APP_2.appStoreId, APP_2.manifest, APP_2.location, APP_2.domain, APP_2.portBindings, APP_2),
|
||||
settingsdb.set.bind(null, settings.BACKUP_CONFIG_KEY, JSON.stringify({ provider: 'caas', token: 'BACKUP_TOKEN', bucket: 'Bucket', prefix: 'Prefix' }))
|
||||
], done);
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
database._clear(done);
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
});
|
||||
|
||||
describe('validateHostname', function () {
|
||||
it('does not allow admin subdomain', function () {
|
||||
expect(apps._validateHostname('my', 'cloudron.us')).to.be.an(Error);
|
||||
expect(apps._validateHostname('my', 'example.com')).to.be.an(Error);
|
||||
});
|
||||
|
||||
it('cannot have >63 length subdomains', function () {
|
||||
var s = '';
|
||||
for (var i = 0; i < 64; i++) s += 's';
|
||||
expect(apps._validateHostname(s, 'cloudron.us')).to.be.an(Error);
|
||||
expect(apps._validateHostname(s, 'example.com')).to.be.an(Error);
|
||||
});
|
||||
|
||||
it('allows only alphanumerics and hypen', function () {
|
||||
expect(apps._validateHostname('#2r', 'cloudron.us')).to.be.an(Error);
|
||||
expect(apps._validateHostname('a%b', 'cloudron.us')).to.be.an(Error);
|
||||
expect(apps._validateHostname('ab_', 'cloudron.us')).to.be.an(Error);
|
||||
expect(apps._validateHostname('a.b', 'cloudron.us')).to.be.an(Error);
|
||||
expect(apps._validateHostname('-ab', 'cloudron.us')).to.be.an(Error);
|
||||
expect(apps._validateHostname('ab-', 'cloudron.us')).to.be.an(Error);
|
||||
expect(apps._validateHostname('#2r', 'example.com')).to.be.an(Error);
|
||||
expect(apps._validateHostname('a%b', 'example.com')).to.be.an(Error);
|
||||
expect(apps._validateHostname('ab_', 'example.com')).to.be.an(Error);
|
||||
expect(apps._validateHostname('a.b', 'example.com')).to.be.an(Error);
|
||||
expect(apps._validateHostname('-ab', 'example.com')).to.be.an(Error);
|
||||
expect(apps._validateHostname('ab-', 'example.com')).to.be.an(Error);
|
||||
});
|
||||
|
||||
it('total length cannot exceed 255', function () {
|
||||
var s = '';
|
||||
for (var i = 0; i < (255 - 'cloudron.us'.length); i++) s += 's';
|
||||
for (var i = 0; i < (255 - 'example.com'.length); i++) s += 's';
|
||||
|
||||
expect(apps._validateHostname(s, 'cloudron.us')).to.be.an(Error);
|
||||
expect(apps._validateHostname(s, 'example.com')).to.be.an(Error);
|
||||
});
|
||||
|
||||
it('allow valid domains', function () {
|
||||
expect(apps._validateHostname('a', 'cloudron.us')).to.be(null);
|
||||
expect(apps._validateHostname('a0-x', 'cloudron.us')).to.be(null);
|
||||
expect(apps._validateHostname('01', 'cloudron.us')).to.be(null);
|
||||
expect(apps._validateHostname('a', 'example.com')).to.be(null);
|
||||
expect(apps._validateHostname('a0-x', 'example.com')).to.be(null);
|
||||
expect(apps._validateHostname('01', 'example.com')).to.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -325,11 +349,13 @@ describe('Apps', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('succeeds with admin not being special', function (done) {
|
||||
it('returns all apps for admin', function (done) {
|
||||
apps.getAllByUser(ADMIN_0, function (error, result) {
|
||||
expect(error).to.equal(null);
|
||||
expect(result.length).to.equal(1);
|
||||
expect(result.length).to.equal(3);
|
||||
expect(result[0].id).to.equal(APP_0.id);
|
||||
expect(result[1].id).to.equal(APP_1.id);
|
||||
expect(result[2].id).to.equal(APP_2.id);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ var addons = require('../addons.js'),
|
||||
async = require('async'),
|
||||
config = require('../config.js'),
|
||||
database = require('../database.js'),
|
||||
domains = require('../domains.js'),
|
||||
expect = require('expect.js'),
|
||||
fs = require('fs'),
|
||||
js2xml = require('js2xmlparser').parse,
|
||||
@@ -48,12 +49,24 @@ var MANIFEST = {
|
||||
}
|
||||
};
|
||||
|
||||
const DOMAIN_0 = {
|
||||
domain: 'example.com',
|
||||
zoneName: 'example.com',
|
||||
config: {
|
||||
provider: 'route53',
|
||||
accessKeyId: 'accessKeyId',
|
||||
secretAccessKey: 'secretAccessKey',
|
||||
endpoint: 'http://localhost:5353'
|
||||
}
|
||||
};
|
||||
|
||||
var APP = {
|
||||
id: 'appid',
|
||||
appStoreId: 'appStoreId',
|
||||
installationState: appdb.ISTATE_PENDING_INSTALL,
|
||||
runState: null,
|
||||
location: 'applocation',
|
||||
domain: DOMAIN_0.domain,
|
||||
manifest: MANIFEST,
|
||||
containerId: null,
|
||||
httpPort: 4567,
|
||||
@@ -63,13 +76,12 @@ var APP = {
|
||||
memoryLimit: 0
|
||||
};
|
||||
|
||||
var awsHostedZones;
|
||||
var awsHostedZones;
|
||||
|
||||
describe('apptask', function () {
|
||||
before(function (done) {
|
||||
config.set('version', '0.5.0');
|
||||
config.setFqdn('foobar.com');
|
||||
config.setZoneName('foobar.com');
|
||||
config._reset();
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
config.set('provider', 'caas');
|
||||
|
||||
awsHostedZones = {
|
||||
@@ -89,15 +101,18 @@ describe('apptask', function () {
|
||||
|
||||
async.series([
|
||||
database.initialize,
|
||||
appdb.add.bind(null, APP.id, APP.appStoreId, APP.manifest, APP.location, APP.portBindings, APP),
|
||||
domains.update.bind(null, DOMAIN_0.domain, DOMAIN_0.config, null),
|
||||
appdb.add.bind(null, APP.id, APP.appStoreId, APP.manifest, APP.location, APP.domain, APP.portBindings, APP),
|
||||
settings.initialize,
|
||||
settings.setDnsConfig.bind(null, { provider: 'route53', accessKeyId: 'accessKeyId', secretAccessKey: 'secretAccessKey', endpoint: 'http://localhost:5353' }, config.fqdn(), config.zoneName()),
|
||||
settings.setTlsConfig.bind(null, { provider: 'caas' })
|
||||
], done);
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
database._clear(done);
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
});
|
||||
|
||||
it('initializes succesfully', function (done) {
|
||||
@@ -246,7 +261,7 @@ describe('apptask', function () {
|
||||
.post('/2013-04-01/hostedzone/ZONEID/rrset/')
|
||||
.reply(200, js2xml('ChangeResourceRecordSetsResponse', { ChangeInfo: { Id: 'RRID', Status: 'INSYNC' } }));
|
||||
|
||||
apptask._unregisterSubdomain(APP, APP.location, function (error) {
|
||||
apptask._unregisterSubdomain(APP, APP.location, APP.domain, function (error) {
|
||||
expect(error).to.be(null);
|
||||
expect(awsScope.isDone()).to.be.ok();
|
||||
done();
|
||||
|
||||
@@ -92,14 +92,17 @@ function createBackup(callback) {
|
||||
|
||||
describe('backups', function () {
|
||||
before(function (done) {
|
||||
const BACKUP_DIR = path.join(os.tmpdir(), 'cloudron-backup-test');
|
||||
|
||||
async.series([
|
||||
mkdirp.bind(null, BACKUP_DIR),
|
||||
database.initialize,
|
||||
database._clear,
|
||||
settings.initialize,
|
||||
settings.setBackupConfig.bind(null, {
|
||||
provider: 'filesystem',
|
||||
key: 'enckey',
|
||||
backupFolder: '/var/backups',
|
||||
backupFolder: BACKUP_DIR,
|
||||
retentionSecs: 1,
|
||||
format: 'tgz'
|
||||
})
|
||||
@@ -121,7 +124,7 @@ describe('backups', function () {
|
||||
version: '1.0.0',
|
||||
type: backupdb.BACKUP_TYPE_BOX,
|
||||
dependsOn: [ 'backup-app-00', 'backup-app-01' ],
|
||||
restoreConfig: null,
|
||||
manifest: null,
|
||||
format: 'tgz'
|
||||
};
|
||||
|
||||
@@ -130,7 +133,7 @@ describe('backups', function () {
|
||||
version: '1.0.0',
|
||||
type: backupdb.BACKUP_TYPE_APP,
|
||||
dependsOn: [],
|
||||
restoreConfig: null,
|
||||
manifest: null,
|
||||
format: 'tgz'
|
||||
};
|
||||
|
||||
@@ -139,7 +142,7 @@ describe('backups', function () {
|
||||
version: '1.0.0',
|
||||
type: backupdb.BACKUP_TYPE_APP,
|
||||
dependsOn: [],
|
||||
restoreConfig: null,
|
||||
manifest: null,
|
||||
format: 'tgz'
|
||||
};
|
||||
|
||||
@@ -148,7 +151,7 @@ describe('backups', function () {
|
||||
version: '1.0.0',
|
||||
type: backupdb.BACKUP_TYPE_BOX,
|
||||
dependsOn: [ 'backup-app-10', 'backup-app-11' ],
|
||||
restoreConfig: null,
|
||||
manifest: null,
|
||||
format: 'tgz'
|
||||
};
|
||||
|
||||
@@ -157,7 +160,7 @@ describe('backups', function () {
|
||||
version: '1.0.0',
|
||||
type: backupdb.BACKUP_TYPE_APP,
|
||||
dependsOn: [],
|
||||
restoreConfig: null,
|
||||
manifest: null,
|
||||
format: 'tgz'
|
||||
};
|
||||
|
||||
@@ -166,7 +169,7 @@ describe('backups', function () {
|
||||
version: '1.0.0',
|
||||
type: backupdb.BACKUP_TYPE_APP,
|
||||
dependsOn: [],
|
||||
restoreConfig: null,
|
||||
manifest: null,
|
||||
format: 'tgz'
|
||||
};
|
||||
|
||||
|
||||
@@ -22,7 +22,10 @@ function setup(done) {
|
||||
}
|
||||
|
||||
function cleanup(done) {
|
||||
database._clear(done);
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
}
|
||||
|
||||
describe('Certificates', function () {
|
||||
|
||||
@@ -13,13 +13,16 @@ var async = require('async'),
|
||||
|
||||
function setup(done) {
|
||||
async.series([
|
||||
database.initialize.bind(null),
|
||||
database._clear.bind(null)
|
||||
database.initialize,
|
||||
database._clear
|
||||
], done);
|
||||
}
|
||||
|
||||
function cleanup(done) {
|
||||
database._clear(done);
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
}
|
||||
|
||||
describe('Cloudron', function () {
|
||||
|
||||
+11
-12
@@ -6,7 +6,6 @@
|
||||
'use strict';
|
||||
|
||||
var config = require('../config.js'),
|
||||
constants = require('../constants.js'),
|
||||
expect = require('expect.js'),
|
||||
fs = require('fs'),
|
||||
path = require('path');
|
||||
@@ -25,11 +24,6 @@ describe('config', function () {
|
||||
done();
|
||||
});
|
||||
|
||||
it('cloudron.conf generated automatically', function (done) {
|
||||
expect(fs.existsSync(path.join(config.baseDir(), 'configs/cloudron.conf'))).to.be.ok();
|
||||
done();
|
||||
});
|
||||
|
||||
it('can get and set version', function (done) {
|
||||
config.setVersion('1.2.3');
|
||||
expect(config.version()).to.be('1.2.3');
|
||||
@@ -38,15 +32,20 @@ describe('config', function () {
|
||||
|
||||
it('did set default values', function () {
|
||||
expect(config.isCustomDomain()).to.equal(true);
|
||||
expect(config.fqdn()).to.equal('localhost');
|
||||
expect(config.adminOrigin()).to.equal('https://my.localhost');
|
||||
expect(config.appFqdn('app')).to.equal('app.localhost');
|
||||
expect(config.fqdn()).to.equal('');
|
||||
expect(config.zoneName()).to.equal('');
|
||||
expect(config.adminLocation()).to.equal('my');
|
||||
});
|
||||
|
||||
it('set saves value in file', function (done) {
|
||||
config.set('fqdn', 'example.com');
|
||||
expect(JSON.parse(fs.readFileSync(path.join(config.baseDir(), 'configs/cloudron.conf'))).fqdn).to.eql('example.com');
|
||||
done();
|
||||
});
|
||||
|
||||
it('set does not save custom values in file', function (done) {
|
||||
config.set('foobar', 'somevalue');
|
||||
expect(JSON.parse(fs.readFileSync(path.join(config.baseDir(), 'configs/cloudron.conf'))).foobar).to.eql('somevalue');
|
||||
expect(JSON.parse(fs.readFileSync(path.join(config.baseDir(), 'configs/cloudron.conf'))).foobar).to.not.be.ok();
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -69,7 +68,7 @@ describe('config', function () {
|
||||
expect(config.isCustomDomain()).to.equal(true);
|
||||
expect(config.fqdn()).to.equal('example.com');
|
||||
expect(config.adminOrigin()).to.equal('https://my.example.com');
|
||||
expect(config.appFqdn('app')).to.equal('app.example.com');
|
||||
expect(config.appFqdn({ location: 'app', domain: config.fqdn() })).to.equal('app.example.com');
|
||||
expect(config.zoneName()).to.equal('example.com');
|
||||
});
|
||||
|
||||
@@ -80,7 +79,7 @@ describe('config', function () {
|
||||
expect(config.isCustomDomain()).to.equal(false);
|
||||
expect(config.fqdn()).to.equal('test.example.com');
|
||||
expect(config.adminOrigin()).to.equal('https://my-test.example.com');
|
||||
expect(config.appFqdn('app')).to.equal('app-test.example.com');
|
||||
expect(config.appFqdn({ location: 'app', domain: config.fqdn() })).to.equal('app-test.example.com');
|
||||
expect(config.zoneName()).to.equal('example.com');
|
||||
});
|
||||
|
||||
|
||||
+254
-37
@@ -10,13 +10,16 @@ var appdb = require('../appdb.js'),
|
||||
authcodedb = require('../authcodedb.js'),
|
||||
backupdb = require('../backupdb.js'),
|
||||
clientdb = require('../clientdb.js'),
|
||||
config = require('../config.js'),
|
||||
database = require('../database'),
|
||||
DatabaseError = require('../databaseerror.js'),
|
||||
domaindb = require('../domaindb'),
|
||||
eventlogdb = require('../eventlogdb.js'),
|
||||
expect = require('expect.js'),
|
||||
groupdb = require('../groupdb.js'),
|
||||
hat = require('hat'),
|
||||
mailboxdb = require('../mailboxdb.js'),
|
||||
path = require('path'),
|
||||
settingsdb = require('../settingsdb.js'),
|
||||
tokendb = require('../tokendb.js'),
|
||||
userdb = require('../userdb.js'),
|
||||
@@ -58,8 +61,17 @@ var USER_2 = {
|
||||
displayName: 'Herbert 2'
|
||||
};
|
||||
|
||||
const TEST_DOMAIN = {
|
||||
domain: 'example.com',
|
||||
zoneName: 'example.com',
|
||||
config: {}
|
||||
};
|
||||
|
||||
describe('database', function () {
|
||||
before(function (done) {
|
||||
config._reset();
|
||||
config.setFqdn(TEST_DOMAIN.domain);
|
||||
|
||||
async.series([
|
||||
database.initialize,
|
||||
database._clear
|
||||
@@ -67,7 +79,169 @@ describe('database', function () {
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
database._clear(done);
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
});
|
||||
|
||||
describe('domains', function () {
|
||||
const DOMAIN_0 = {
|
||||
domain: 'foobar.com',
|
||||
zoneName: 'foobar.com',
|
||||
config: { provider: 'digitalocean', token: 'abcd' }
|
||||
};
|
||||
|
||||
const DOMAIN_1 = {
|
||||
domain: 'foo.cloudron.io',
|
||||
zoneName: 'cloudron.io',
|
||||
config: null
|
||||
};
|
||||
|
||||
it('can add domain', function (done) {
|
||||
domaindb.add(DOMAIN_0.domain, DOMAIN_0.zoneName, DOMAIN_0.config, done);
|
||||
});
|
||||
|
||||
it('can add another domain', function (done) {
|
||||
domaindb.add(DOMAIN_1.domain, DOMAIN_1.zoneName, DOMAIN_1.config, done);
|
||||
});
|
||||
|
||||
it('cannot add same domain twice', function (done) {
|
||||
domaindb.add(DOMAIN_0.domain, DOMAIN_0.zoneName, DOMAIN_0.config, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
expect(error.reason).to.be(DatabaseError.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 get domain without provider set', function (done) {
|
||||
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.config).to.eql(DOMAIN_1.config);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can update domain', function (done) {
|
||||
const newConfig = { provider: 'manual' };
|
||||
|
||||
domaindb.update(DOMAIN_1.domain, newConfig, 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.config).to.eql(newConfig);
|
||||
|
||||
DOMAIN_1.config = newConfig;
|
||||
|
||||
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(3); // includes the TEST_DOMAIN
|
||||
|
||||
// sorted by domain
|
||||
expect(result[0].domain).to.equal(TEST_DOMAIN.domain);
|
||||
expect(result[0].zoneName).to.equal(TEST_DOMAIN.zoneName);
|
||||
expect(result[0].config).to.eql(TEST_DOMAIN.config);
|
||||
|
||||
expect(result[1].domain).to.equal(DOMAIN_1.domain);
|
||||
expect(result[1].zoneName).to.equal(DOMAIN_1.zoneName);
|
||||
expect(result[1].config).to.eql(DOMAIN_1.config);
|
||||
|
||||
expect(result[2].domain).to.equal(DOMAIN_0.domain);
|
||||
expect(result[2].zoneName).to.equal(DOMAIN_0.zoneName);
|
||||
expect(result[2].config).to.eql(DOMAIN_0.config);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot delete non-existing domain', function (done) {
|
||||
domaindb.del('not.exists', function (error) {
|
||||
expect(error).to.be.a(DatabaseError);
|
||||
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
var APP_0 = {
|
||||
id: 'appid-0',
|
||||
appStoreId: 'appStoreId-0',
|
||||
dnsRecordId: null,
|
||||
installationState: appdb.ISTATE_PENDING_INSTALL,
|
||||
installationProgress: null,
|
||||
runState: null,
|
||||
location: 'some-location-0',
|
||||
domain: DOMAIN_0.domain,
|
||||
manifest: { version: '0.1', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0' },
|
||||
httpPort: null,
|
||||
containerId: null,
|
||||
portBindings: { port: 5678 },
|
||||
health: null,
|
||||
accessRestriction: null,
|
||||
lastBackupId: null,
|
||||
oldConfig: null,
|
||||
newConfig: null,
|
||||
memoryLimit: 4294967296,
|
||||
altDomain: null,
|
||||
xFrameOptions: 'DENY',
|
||||
sso: true,
|
||||
debugMode: null,
|
||||
robotsTxt: null,
|
||||
enableBackup: true
|
||||
};
|
||||
|
||||
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(DatabaseError);
|
||||
expect(error.reason).to.equal(DatabaseError.IN_USE);
|
||||
|
||||
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(DatabaseError);
|
||||
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('user', function () {
|
||||
@@ -530,15 +704,16 @@ describe('database', function () {
|
||||
installationProgress: null,
|
||||
runState: null,
|
||||
location: 'some-location-0',
|
||||
domain: 'example.com',
|
||||
manifest: { version: '0.1', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0' },
|
||||
httpPort: null,
|
||||
containerId: null,
|
||||
portBindings: { port: 5678 },
|
||||
health: null,
|
||||
accessRestriction: null,
|
||||
lastBackupId: null,
|
||||
restoreConfig: null,
|
||||
oldConfig: null,
|
||||
newConfig: null,
|
||||
updateConfig: null,
|
||||
memoryLimit: 4294967296,
|
||||
altDomain: null,
|
||||
xFrameOptions: 'DENY',
|
||||
@@ -555,15 +730,16 @@ describe('database', function () {
|
||||
installationProgress: null,
|
||||
runState: null,
|
||||
location: 'some-location-1',
|
||||
domain: 'example.com',
|
||||
manifest: { version: '0.2', dockerImage: 'docker/app1', healthCheckPath: '/', httpPort: 80, title: 'app1' },
|
||||
httpPort: null,
|
||||
containerId: null,
|
||||
portBindings: { },
|
||||
health: null,
|
||||
accessRestriction: { users: [ 'foobar' ] },
|
||||
lastBackupId: null,
|
||||
restoreConfig: null,
|
||||
oldConfig: null,
|
||||
newConfig: null,
|
||||
updateConfig: null,
|
||||
memoryLimit: 0,
|
||||
altDomain: null,
|
||||
xFrameOptions: 'SAMEORIGIN',
|
||||
@@ -587,7 +763,7 @@ describe('database', function () {
|
||||
});
|
||||
|
||||
it('add succeeds', function (done) {
|
||||
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.portBindings, APP_0, function (error) {
|
||||
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);
|
||||
done();
|
||||
});
|
||||
@@ -611,7 +787,7 @@ describe('database', function () {
|
||||
});
|
||||
|
||||
it('add of same app fails', function (done) {
|
||||
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, [ ], APP_0, function (error) {
|
||||
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, [], APP_0, function (error) {
|
||||
expect(error).to.be.a(DatabaseError);
|
||||
expect(error.reason).to.be(DatabaseError.ALREADY_EXISTS);
|
||||
done();
|
||||
@@ -622,7 +798,7 @@ describe('database', function () {
|
||||
appdb.get(APP_0.id, function (error, result) {
|
||||
expect(error).to.be(null);
|
||||
expect(result).to.be.an('object');
|
||||
expect(result).to.be.eql(APP_0);
|
||||
expect(_.omit(result, ['creationTime', 'updateTime'])).to.be.eql(APP_0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -659,7 +835,7 @@ describe('database', function () {
|
||||
appdb.get(APP_0.id, function (error, result) {
|
||||
expect(error).to.be(null);
|
||||
expect(result).to.be.an('object');
|
||||
expect(result).to.be.eql(APP_0);
|
||||
expect(_.omit(result, ['creationTime', 'updateTime'])).to.be.eql(APP_0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -669,7 +845,7 @@ describe('database', function () {
|
||||
appdb.getByHttpPort(APP_0.httpPort, function (error, result) {
|
||||
expect(error).to.be(null);
|
||||
expect(result).to.be.an('object');
|
||||
expect(result).to.be.eql(APP_0);
|
||||
expect(_.omit(result, ['creationTime', 'updateTime'])).to.be.eql(APP_0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -683,7 +859,7 @@ describe('database', function () {
|
||||
});
|
||||
|
||||
it('add second app succeeds', function (done) {
|
||||
appdb.add(APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, [ ], APP_1, function (error) {
|
||||
appdb.add(APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, APP_1.domain, [], APP_1, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
@@ -694,8 +870,8 @@ describe('database', function () {
|
||||
expect(error).to.be(null);
|
||||
expect(result).to.be.an(Array);
|
||||
expect(result.length).to.be(2);
|
||||
expect(result[0]).to.be.eql(APP_0);
|
||||
expect(result[1]).to.be.eql(APP_1);
|
||||
expect(_.omit(result[0], ['creationTime', 'updateTime'])).to.be.eql(APP_0);
|
||||
expect(_.omit(result[1], ['creationTime', 'updateTime'])).to.be.eql(APP_1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -1027,7 +1203,7 @@ describe('database', function () {
|
||||
version: '1.0.0',
|
||||
type: backupdb.BACKUP_TYPE_BOX,
|
||||
dependsOn: [ 'dep1' ],
|
||||
restoreConfig: null,
|
||||
manifest: null,
|
||||
format: 'tgz'
|
||||
};
|
||||
|
||||
@@ -1044,7 +1220,7 @@ describe('database', function () {
|
||||
expect(result.type).to.be(backupdb.BACKUP_TYPE_BOX);
|
||||
expect(result.creationTime).to.be.a(Date);
|
||||
expect(result.dependsOn).to.eql(['dep1']);
|
||||
expect(result.restoreConfig).to.eql(null);
|
||||
expect(result.manifest).to.eql(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -1067,7 +1243,7 @@ describe('database', function () {
|
||||
expect(results[0].id).to.be('backup-box');
|
||||
expect(results[0].version).to.be('1.0.0');
|
||||
expect(results[0].dependsOn).to.eql(['dep1']);
|
||||
expect(results[0].restoreConfig).to.eql(null);
|
||||
expect(results[0].manifest).to.eql(null);
|
||||
|
||||
done();
|
||||
});
|
||||
@@ -1093,7 +1269,7 @@ describe('database', function () {
|
||||
version: '1.0.0',
|
||||
type: backupdb.BACKUP_TYPE_APP,
|
||||
dependsOn: [ ],
|
||||
restoreConfig: { manifest: { foo: 'bar' } },
|
||||
manifest: { foo: 'bar' },
|
||||
format: 'tgz'
|
||||
};
|
||||
|
||||
@@ -1110,7 +1286,7 @@ describe('database', function () {
|
||||
expect(result.type).to.be(backupdb.BACKUP_TYPE_APP);
|
||||
expect(result.creationTime).to.be.a(Date);
|
||||
expect(result.dependsOn).to.eql([]);
|
||||
expect(result.restoreConfig).to.eql({ manifest: { foo: 'bar' } });
|
||||
expect(result.manifest).to.eql({ foo: 'bar' });
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -1124,7 +1300,7 @@ describe('database', function () {
|
||||
expect(results[0].id).to.be('app_appid_123');
|
||||
expect(results[0].version).to.be('1.0.0');
|
||||
expect(results[0].dependsOn).to.eql([]);
|
||||
expect(results[0].restoreConfig).to.eql({ manifest: { foo: 'bar' } });
|
||||
expect(results[0].manifest).to.eql({ foo: 'bar' });
|
||||
|
||||
done();
|
||||
});
|
||||
@@ -1250,6 +1426,9 @@ describe('database', function () {
|
||||
|
||||
describe('groups', function () {
|
||||
before(function (done) {
|
||||
config._reset();
|
||||
config.setFqdn(TEST_DOMAIN.domain);
|
||||
|
||||
async.series([
|
||||
database.initialize,
|
||||
database._clear,
|
||||
@@ -1368,8 +1547,45 @@ describe('database', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('importFromFile', function () {
|
||||
before(function (done) {
|
||||
config._reset();
|
||||
config.setFqdn(TEST_DOMAIN.domain);
|
||||
|
||||
async.series([
|
||||
database.initialize,
|
||||
database._clear
|
||||
], done);
|
||||
});
|
||||
|
||||
it('cannot import from non-existent file', function (done) {
|
||||
database.importFromFile('/does/not/exist', function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can export to file', function (done) {
|
||||
database.exportToFile('/tmp/box.mysqldump', function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can import from file', function (done) {
|
||||
database.importFromFile('/tmp/box.mysqldump', function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('mailboxes', function () {
|
||||
before(function (done) {
|
||||
config._reset();
|
||||
config.setFqdn(TEST_DOMAIN.domain);
|
||||
|
||||
async.series([
|
||||
database.initialize,
|
||||
database._clear
|
||||
@@ -1377,31 +1593,32 @@ describe('database', function () {
|
||||
});
|
||||
|
||||
it('add user mailbox succeeds', function (done) {
|
||||
mailboxdb.add('girish', 'uid-0', mailboxdb.TYPE_USER, function (error, mailbox) {
|
||||
mailboxdb.add('girish', TEST_DOMAIN.domain, 'uid-0', mailboxdb.TYPE_USER, function (error, mailbox) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot add dup entry', function (done) {
|
||||
mailboxdb.add('girish', 'uid-1', mailboxdb.TYPE_APP, function (error, mailbox) {
|
||||
mailboxdb.add('girish', TEST_DOMAIN.domain, 'uid-1', mailboxdb.TYPE_APP, function (error, mailbox) {
|
||||
expect(error.reason).to.be(DatabaseError.ALREADY_EXISTS);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('add app mailbox succeeds', function (done) {
|
||||
mailboxdb.add('support', 'osticket', mailboxdb.TYPE_APP, function (error, mailbox) {
|
||||
mailboxdb.add('support', TEST_DOMAIN.domain, 'osticket', mailboxdb.TYPE_APP, function (error, mailbox) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get succeeds', function (done) {
|
||||
mailboxdb.getMailbox('support', function (error, mailbox) {
|
||||
mailboxdb.getMailbox('support', TEST_DOMAIN.domain, function (error, mailbox) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailbox.name).to.be('support');
|
||||
expect(mailbox.ownerId).to.be('osticket');
|
||||
expect(mailbox.name).to.equal('support');
|
||||
expect(mailbox.ownerId).to.equal('osticket');
|
||||
expect(mailbox.domain).to.equal(TEST_DOMAIN.domain);
|
||||
expect(mailbox.creationTime).to.be.a(Date);
|
||||
|
||||
done();
|
||||
@@ -1409,7 +1626,7 @@ describe('database', function () {
|
||||
});
|
||||
|
||||
it('list mailboxes succeeds', function (done) {
|
||||
mailboxdb.listMailboxes(function (error, mailboxes) {
|
||||
mailboxdb.listMailboxes(TEST_DOMAIN.domain, function (error, mailboxes) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailboxes.length).to.be(2);
|
||||
expect(mailboxes[0].name).to.be('girish');
|
||||
@@ -1421,14 +1638,14 @@ describe('database', function () {
|
||||
});
|
||||
|
||||
it('can set alias', function (done) {
|
||||
mailboxdb.setAliasesForName('support', [ 'support2', 'help' ], function (error) {
|
||||
mailboxdb.setAliasesForName('support', TEST_DOMAIN.domain, [ 'support2', 'help' ], function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can get aliases of name', function (done) {
|
||||
mailboxdb.getAliasesForName('support', function (error, results) {
|
||||
mailboxdb.getAliasesForName('support', TEST_DOMAIN.domain, function (error, results) {
|
||||
expect(error).to.be(null);
|
||||
expect(results.length).to.be(2);
|
||||
expect(results[0]).to.be('help');
|
||||
@@ -1438,7 +1655,7 @@ describe('database', function () {
|
||||
});
|
||||
|
||||
it('can get alias', function (done) {
|
||||
mailboxdb.getAlias('support2', function (error, result) {
|
||||
mailboxdb.getAlias('support2', TEST_DOMAIN.domain, function (error, result) {
|
||||
expect(error).to.be(null);
|
||||
expect(result.name).to.be('support2');
|
||||
expect(result.aliasTarget).to.be('support');
|
||||
@@ -1447,7 +1664,7 @@ describe('database', function () {
|
||||
});
|
||||
|
||||
it('can list aliases', function (done) {
|
||||
mailboxdb.listAliases(function (error, results) {
|
||||
mailboxdb.listAliases(TEST_DOMAIN.domain, function (error, results) {
|
||||
expect(error).to.be(null);
|
||||
expect(results.length).to.be(2);
|
||||
expect(results[0].name).to.be('help');
|
||||
@@ -1469,22 +1686,22 @@ describe('database', function () {
|
||||
});
|
||||
|
||||
it('cannot get non-existing group', function (done) {
|
||||
mailboxdb.getGroup('random', function (error) {
|
||||
mailboxdb.getGroup('random', TEST_DOMAIN.domain, function (error) {
|
||||
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can change name', function (done) {
|
||||
mailboxdb.updateName('support', 'support3', function (error) {
|
||||
mailboxdb.updateName('support', TEST_DOMAIN.domain, 'support3', TEST_DOMAIN.domain, function (error) {
|
||||
expect(error).to.be(null);
|
||||
|
||||
mailboxdb.updateName('support3', 'support', done);
|
||||
mailboxdb.updateName('support3', TEST_DOMAIN.domain, 'support', TEST_DOMAIN.domain, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot change name to existing one', function (done) {
|
||||
mailboxdb.updateName('support', 'support2', function (error) {
|
||||
mailboxdb.updateName('support', TEST_DOMAIN.domain, 'support2', TEST_DOMAIN.domain, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
expect(error.reason).to.eql(DatabaseError.ALREADY_EXISTS);
|
||||
|
||||
@@ -1493,10 +1710,10 @@ describe('database', function () {
|
||||
});
|
||||
|
||||
it('unset aliases', function (done) {
|
||||
mailboxdb.setAliasesForName('support', [ ], function (error) {
|
||||
mailboxdb.setAliasesForName('support', TEST_DOMAIN.domain, [], function (error) {
|
||||
expect(error).to.be(null);
|
||||
|
||||
mailboxdb.getAliasesForName('support', function (error, results) {
|
||||
mailboxdb.getAliasesForName('support', TEST_DOMAIN.domain, function (error, results) {
|
||||
expect(error).to.be(null);
|
||||
expect(results.length).to.be(0);
|
||||
done();
|
||||
@@ -1505,7 +1722,7 @@ describe('database', function () {
|
||||
});
|
||||
|
||||
it('del succeeds', function (done) {
|
||||
mailboxdb.del('girish', function (error) {
|
||||
mailboxdb.del('girish', TEST_DOMAIN.domain, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
|
||||
+26
-32
@@ -9,10 +9,10 @@ var async = require('async'),
|
||||
config = require('../config.js'),
|
||||
database = require('../database.js'),
|
||||
digest = require('../digest.js'),
|
||||
domaindb = require('../domaindb.js'),
|
||||
eventlog = require('../eventlog.js'),
|
||||
expect = require('expect.js'),
|
||||
mailer = require('../mailer.js'),
|
||||
nock = require('nock'),
|
||||
paths = require('../paths.js'),
|
||||
safe = require('safetydance'),
|
||||
settings = require('../settings.js'),
|
||||
@@ -28,6 +28,12 @@ var USER_0 = {
|
||||
displayName: 'User 0'
|
||||
};
|
||||
|
||||
const DOMAIN_0 = {
|
||||
domain: 'example.com',
|
||||
zoneName: 'example.com',
|
||||
config: { provider: 'manual' }
|
||||
};
|
||||
|
||||
var AUDIT_SOURCE = {
|
||||
ip: '1.2.3.4'
|
||||
};
|
||||
@@ -37,8 +43,8 @@ function checkMails(number, email, done) {
|
||||
setTimeout(function () {
|
||||
expect(mailer._getMailQueue().length).to.equal(number);
|
||||
|
||||
if (number && email) {
|
||||
expect(mailer._getMailQueue()[0].to.indexOf(email)).to.not.equal(-1);
|
||||
if (number) {
|
||||
expect(mailer._getMailQueue()[0].to).to.equal(email);
|
||||
}
|
||||
|
||||
mailer._clearMailQueue();
|
||||
@@ -47,21 +53,12 @@ function checkMails(number, email, done) {
|
||||
}
|
||||
|
||||
describe('digest', function () {
|
||||
function cleanup(done) {
|
||||
mailer._clearMailQueue();
|
||||
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
|
||||
|
||||
async.series([
|
||||
settings.uninitialize,
|
||||
database._clear
|
||||
], done);
|
||||
}
|
||||
|
||||
before(function (done) {
|
||||
config._reset();
|
||||
config.set('version', '1.0.0');
|
||||
config.set('fqdn', 'domain.com');
|
||||
config.set('apiServerOrigin', 'http://localhost:4444');
|
||||
config.set('provider', 'notcaas');
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
|
||||
|
||||
async.series([
|
||||
@@ -70,12 +67,21 @@ describe('digest', function () {
|
||||
settings.initialize,
|
||||
user.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE),
|
||||
eventlog.add.bind(null, eventlog.ACTION_UPDATE, AUDIT_SOURCE, { boxUpdateInfo: { sourceTarballUrl: 'xx', version: '1.2.3', changelog: [ 'good stuff' ] } }),
|
||||
mailer.start,
|
||||
settingsdb.set.bind(null, settings.MAIL_CONFIG_KEY, JSON.stringify({ enabled: true })),
|
||||
mailer._clearMailQueue
|
||||
], done);
|
||||
});
|
||||
|
||||
after(cleanup);
|
||||
after(function (done) {
|
||||
mailer._clearMailQueue();
|
||||
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
|
||||
|
||||
async.series([
|
||||
settings.uninitialize,
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
});
|
||||
|
||||
describe('disabled', function () {
|
||||
before(function (done) {
|
||||
@@ -85,7 +91,7 @@ describe('digest', function () {
|
||||
it('does not send mail with digest disabled', function (done) {
|
||||
digest.maybeSend(function (error) {
|
||||
if (error) return done(error);
|
||||
checkMails(0, '', done);
|
||||
checkMails(0, null, done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -100,7 +106,7 @@ describe('digest', function () {
|
||||
digest.maybeSend(function (error) {
|
||||
if (error) return done(error);
|
||||
|
||||
checkMails(1, '', done);
|
||||
checkMails(1, `${USER_0.email}, ${USER_0.username}@${config.fqdn()}`, done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -110,19 +116,11 @@ describe('digest', function () {
|
||||
digest.maybeSend(function (error) {
|
||||
if (error) return done(error);
|
||||
|
||||
checkMails(1, '', done);
|
||||
checkMails(1, `${USER_0.email}, ${USER_0.username}@${config.fqdn()}`, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('sends mail for pending update to owner account email', function (done) {
|
||||
var subscription = {
|
||||
id: 'caas',
|
||||
created: 0,
|
||||
canceled_at: 0,
|
||||
status: 'active',
|
||||
plan: { id: 'caas' }
|
||||
};
|
||||
|
||||
updatechecker._setUpdateInfo({ box: null, apps: { 'appid': { manifest: { version: '1.2.5', changelog: 'noop\nreally' } } } });
|
||||
|
||||
settingsdb.set(settings.MAIL_CONFIG_KEY, JSON.stringify({ enabled: true }), function (error) {
|
||||
@@ -131,11 +129,7 @@ describe('digest', function () {
|
||||
digest.maybeSend(function (error) {
|
||||
if (error) return done(error);
|
||||
|
||||
checkMails(1, [ 'user0@email.com, username0@localhost' ], function (error) {
|
||||
if (error) return done(error);
|
||||
|
||||
done();
|
||||
});
|
||||
checkMails(1, `${USER_0.email}, ${USER_0.username}@${DOMAIN_0.domain}`, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+70
-68
@@ -11,40 +11,48 @@ var async = require('async'),
|
||||
GCDNS = require('@google-cloud/dns'),
|
||||
config = require('../config.js'),
|
||||
database = require('../database.js'),
|
||||
domains = require('../domains.js'),
|
||||
expect = require('expect.js'),
|
||||
nock = require('nock'),
|
||||
settings = require('../settings.js'),
|
||||
subdomains = require('../subdomains.js'),
|
||||
util = require('util');
|
||||
|
||||
var DOMAIN_0 = {
|
||||
domain: 'example-dns-test.com',
|
||||
zoneName: 'example-dns-test.com',
|
||||
config: {}
|
||||
};
|
||||
|
||||
describe('dns provider', function () {
|
||||
before(function (done) {
|
||||
config._reset();
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
|
||||
async.series([
|
||||
database.initialize,
|
||||
settings.initialize
|
||||
settings.initialize,
|
||||
database._clear
|
||||
], done);
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
database._clear(done);
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
});
|
||||
|
||||
describe('noop', function () {
|
||||
before(function (done) {
|
||||
var data = {
|
||||
DOMAIN_0.config = {
|
||||
provider: 'noop'
|
||||
};
|
||||
|
||||
config.setFqdn('example.com');
|
||||
config.setZoneName('example.com');
|
||||
|
||||
settings.setDnsConfig(data, config.fqdn(), config.zoneName(), done);
|
||||
domains.update(DOMAIN_0.domain, DOMAIN_0.config, null, done);
|
||||
});
|
||||
|
||||
it('upsert succeeds', function (done) {
|
||||
subdomains.upsert('test', 'A', [ '1.2.3.4' ], function (error, result) {
|
||||
domains.upsertDNSRecords('test', DOMAIN_0.domain, 'A', [ '1.2.3.4' ], function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.eql('noop-record-id');
|
||||
|
||||
@@ -53,7 +61,7 @@ describe('dns provider', function () {
|
||||
});
|
||||
|
||||
it('get succeeds', function (done) {
|
||||
subdomains.get('test', 'A', function (error, result) {
|
||||
domains.getDNSRecords('test', DOMAIN_0.domain, 'A', function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.be.an(Array);
|
||||
expect(result.length).to.eql(0);
|
||||
@@ -63,7 +71,7 @@ describe('dns provider', function () {
|
||||
});
|
||||
|
||||
it('del succeeds', function (done) {
|
||||
subdomains.remove('test', 'A', [ '1.2.3.4' ], function (error) {
|
||||
domains.removeDNSRecords('test', DOMAIN_0.domain, 'A', [ '1.2.3.4' ], function (error) {
|
||||
expect(error).to.eql(null);
|
||||
|
||||
done();
|
||||
@@ -76,15 +84,12 @@ describe('dns provider', function () {
|
||||
var DIGITALOCEAN_ENDPOINT = 'https://api.digitalocean.com';
|
||||
|
||||
before(function (done) {
|
||||
var data = {
|
||||
DOMAIN_0.config = {
|
||||
provider: 'digitalocean',
|
||||
token: TOKEN
|
||||
};
|
||||
|
||||
config.setFqdn('example.com');
|
||||
config.setZoneName('example.com');
|
||||
|
||||
settings.setDnsConfig(data, config.fqdn(), config.zoneName(), done);
|
||||
domains.update(DOMAIN_0.domain, DOMAIN_0.config, null, done);
|
||||
});
|
||||
|
||||
it('upsert non-existing record succeeds', function (done) {
|
||||
@@ -107,7 +112,7 @@ describe('dns provider', function () {
|
||||
.post('/v2/domains/' + config.zoneName() + '/records')
|
||||
.reply(201, { domain_record: DOMAIN_RECORD_0 });
|
||||
|
||||
subdomains.upsert('test', 'A', [ '1.2.3.4' ], function (error, result) {
|
||||
domains.upsertDNSRecords('test', DOMAIN_0.domain, 'A', [ '1.2.3.4' ], function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.eql('3352892');
|
||||
expect(req1.isDone()).to.be.ok();
|
||||
@@ -157,7 +162,7 @@ describe('dns provider', function () {
|
||||
.put('/v2/domains/' + config.zoneName() + '/records/' + DOMAIN_RECORD_1.id)
|
||||
.reply(200, { domain_record: DOMAIN_RECORD_1_NEW });
|
||||
|
||||
subdomains.upsert('test', 'A', [ DOMAIN_RECORD_1_NEW.data ], function (error, result) {
|
||||
domains.upsertDNSRecords('test', DOMAIN_0.domain, 'A', [ DOMAIN_RECORD_1_NEW.data ], function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.eql('3352893');
|
||||
expect(req1.isDone()).to.be.ok();
|
||||
@@ -243,7 +248,7 @@ describe('dns provider', function () {
|
||||
.post('/v2/domains/' + config.zoneName() + '/records')
|
||||
.reply(201, { domain_record: DOMAIN_RECORD_2_NEW });
|
||||
|
||||
subdomains.upsert('', 'TXT', [ DOMAIN_RECORD_2_NEW.data, DOMAIN_RECORD_1_NEW.data, DOMAIN_RECORD_3_NEW.data ], function (error, result) {
|
||||
domains.upsertDNSRecords('', config.fqdn(), 'TXT', [ DOMAIN_RECORD_2_NEW.data, DOMAIN_RECORD_1_NEW.data, DOMAIN_RECORD_3_NEW.data ], function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.eql('3352893');
|
||||
expect(req1.isDone()).to.be.ok();
|
||||
@@ -282,7 +287,7 @@ describe('dns provider', function () {
|
||||
.get('/v2/domains/' + config.zoneName() + '/records')
|
||||
.reply(200, { domain_records: [ DOMAIN_RECORD_0, DOMAIN_RECORD_1 ] });
|
||||
|
||||
subdomains.get('test', 'A', function (error, result) {
|
||||
domains.getDNSRecords('test', DOMAIN_0.domain, 'A', function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.be.an(Array);
|
||||
expect(result.length).to.eql(1);
|
||||
@@ -323,7 +328,7 @@ describe('dns provider', function () {
|
||||
.delete('/v2/domains/' + config.zoneName() + '/records/' + DOMAIN_RECORD_1.id)
|
||||
.reply(204, {});
|
||||
|
||||
subdomains.remove('test', 'A', ['1.2.3.4'], function (error) {
|
||||
domains.removeDNSRecords('test', DOMAIN_0.domain, 'A', ['1.2.3.4'], function (error) {
|
||||
expect(error).to.eql(null);
|
||||
expect(req1.isDone()).to.be.ok();
|
||||
expect(req2.isDone()).to.be.ok();
|
||||
@@ -334,44 +339,43 @@ describe('dns provider', function () {
|
||||
});
|
||||
|
||||
describe('route53', function () {
|
||||
config.setFqdn('example.com');
|
||||
config.setZoneName('example.com');
|
||||
|
||||
// do not clear this with [] but .length = 0 so we don't loose the reference in mockery
|
||||
var awsAnswerQueue = [];
|
||||
|
||||
var AWS_HOSTED_ZONES = {
|
||||
HostedZones: [{
|
||||
Id: '/hostedzone/Z34G16B38TNZ9L',
|
||||
Name: config.zoneName() + '.',
|
||||
CallerReference: '305AFD59-9D73-4502-B020-F4E6F889CB30',
|
||||
ResourceRecordSetCount: 2,
|
||||
ChangeInfo: {
|
||||
Id: '/change/CKRTFJA0ANHXB',
|
||||
Status: 'INSYNC'
|
||||
}
|
||||
}, {
|
||||
Id: '/hostedzone/Z3OFC3B6E8YTA7',
|
||||
Name: 'cloudron.us.',
|
||||
CallerReference: '0B37F2DE-21A4-E678-BA32-3FC8AF0CF635',
|
||||
Config: {},
|
||||
ResourceRecordSetCount: 2,
|
||||
ChangeInfo: {
|
||||
Id: '/change/C2682N5HXP0BZ5',
|
||||
Status: 'INSYNC'
|
||||
}
|
||||
}],
|
||||
IsTruncated: false,
|
||||
MaxItems: '100'
|
||||
};
|
||||
var AWS_HOSTED_ZONES = null;
|
||||
|
||||
before(function (done) {
|
||||
var data = {
|
||||
DOMAIN_0.config = {
|
||||
provider: 'route53',
|
||||
accessKeyId: 'unused',
|
||||
secretAccessKey: 'unused'
|
||||
};
|
||||
|
||||
AWS_HOSTED_ZONES = {
|
||||
HostedZones: [{
|
||||
Id: '/hostedzone/Z34G16B38TNZ9L',
|
||||
Name: config.zoneName() + '.',
|
||||
CallerReference: '305AFD59-9D73-4502-B020-F4E6F889CB30',
|
||||
ResourceRecordSetCount: 2,
|
||||
ChangeInfo: {
|
||||
Id: '/change/CKRTFJA0ANHXB',
|
||||
Status: 'INSYNC'
|
||||
}
|
||||
}, {
|
||||
Id: '/hostedzone/Z3OFC3B6E8YTA7',
|
||||
Name: 'cloudron.us.',
|
||||
CallerReference: '0B37F2DE-21A4-E678-BA32-3FC8AF0CF635',
|
||||
Config: {},
|
||||
ResourceRecordSetCount: 2,
|
||||
ChangeInfo: {
|
||||
Id: '/change/C2682N5HXP0BZ5',
|
||||
Status: 'INSYNC'
|
||||
}
|
||||
}],
|
||||
IsTruncated: false,
|
||||
MaxItems: '100'
|
||||
};
|
||||
|
||||
function mockery (queue) {
|
||||
return function(options, callback) {
|
||||
expect(options).to.be.an(Object);
|
||||
@@ -396,8 +400,8 @@ describe('dns provider', function () {
|
||||
|
||||
function Route53Mock(cfg) {
|
||||
expect(cfg).to.eql({
|
||||
accessKeyId: data.accessKeyId,
|
||||
secretAccessKey: data.secretAccessKey,
|
||||
accessKeyId: DOMAIN_0.config.accessKeyId,
|
||||
secretAccessKey: DOMAIN_0.config.secretAccessKey,
|
||||
region: 'us-east-1'
|
||||
});
|
||||
}
|
||||
@@ -412,7 +416,7 @@ describe('dns provider', function () {
|
||||
AWS._originalRoute53 = AWS.Route53;
|
||||
AWS.Route53 = Route53Mock;
|
||||
|
||||
settings.setDnsConfig(data, config.fqdn(), config.zoneName(), done);
|
||||
domains.update(DOMAIN_0.domain, DOMAIN_0.config, null, done);
|
||||
});
|
||||
|
||||
after(function () {
|
||||
@@ -430,7 +434,7 @@ describe('dns provider', function () {
|
||||
}
|
||||
}]);
|
||||
|
||||
subdomains.upsert('test', 'A', [ '1.2.3.4' ], function (error, result) {
|
||||
domains.upsertDNSRecords('test', DOMAIN_0.domain, 'A', [ '1.2.3.4' ], function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.eql('/change/C2QLKQIWEI0BZF');
|
||||
expect(awsAnswerQueue.length).to.eql(0);
|
||||
@@ -449,7 +453,7 @@ describe('dns provider', function () {
|
||||
}
|
||||
}]);
|
||||
|
||||
subdomains.upsert('test', 'A', [ '1.2.3.4' ], function (error, result) {
|
||||
domains.upsertDNSRecords('test', DOMAIN_0.domain, 'A', [ '1.2.3.4' ], function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.eql('/change/C2QLKQIWEI0BZF');
|
||||
expect(awsAnswerQueue.length).to.eql(0);
|
||||
@@ -468,7 +472,7 @@ describe('dns provider', function () {
|
||||
}
|
||||
}]);
|
||||
|
||||
subdomains.upsert('', 'TXT', [ 'first', 'second', 'third' ], function (error, result) {
|
||||
domains.upsertDNSRecords('', config.fqdn(), 'TXT', [ 'first', 'second', 'third' ], function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.eql('/change/C2QLKQIWEI0BZF');
|
||||
expect(awsAnswerQueue.length).to.eql(0);
|
||||
@@ -489,7 +493,7 @@ describe('dns provider', function () {
|
||||
}]
|
||||
}]);
|
||||
|
||||
subdomains.get('test', 'A', function (error, result) {
|
||||
domains.getDNSRecords('test', DOMAIN_0.domain, 'A', function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.be.an(Array);
|
||||
expect(result.length).to.eql(1);
|
||||
@@ -510,7 +514,7 @@ describe('dns provider', function () {
|
||||
}
|
||||
}]);
|
||||
|
||||
subdomains.remove('test', 'A', ['1.2.3.4'], function (error) {
|
||||
domains.removeDNSRecords('test', DOMAIN_0.domain, 'A', ['1.2.3.4'], function (error) {
|
||||
expect(error).to.eql(null);
|
||||
expect(awsAnswerQueue.length).to.eql(0);
|
||||
|
||||
@@ -525,10 +529,7 @@ describe('dns provider', function () {
|
||||
var _OriginalGCDNS;
|
||||
|
||||
before(function (done) {
|
||||
var domain = 'example.com';
|
||||
config.setFqdn(domain);
|
||||
config.setZoneName(domain);
|
||||
var dnsConfig = {
|
||||
DOMAIN_0.config = {
|
||||
provider: 'gcdns',
|
||||
projectId: 'my-dns-proj',
|
||||
keyFilename: __dirname + '/syn-im-1ec6f9f870bf.json'
|
||||
@@ -566,12 +567,12 @@ describe('dns provider', function () {
|
||||
zone.deleteRecords = mockery(recordQueue || zoneQueue);
|
||||
return zone;
|
||||
}
|
||||
HOSTED_ZONES = [fakeZone(domain), fakeZone('cloudron.us')];
|
||||
HOSTED_ZONES = [ fakeZone(DOMAIN_0.domain), fakeZone('cloudron.us') ];
|
||||
|
||||
_OriginalGCDNS = GCDNS.prototype.getZones;
|
||||
GCDNS.prototype.getZones = mockery(zoneQueue);
|
||||
|
||||
settings.setDnsConfig(dnsConfig, config.fqdn(), config.zoneName(), done);
|
||||
domains.update(DOMAIN_0.domain, DOMAIN_0.config, null, done);
|
||||
});
|
||||
|
||||
after(function () {
|
||||
@@ -583,7 +584,8 @@ describe('dns provider', function () {
|
||||
zoneQueue.push([null, HOSTED_ZONES]); // getZone
|
||||
zoneQueue.push([null, [ ]]); // getRecords
|
||||
zoneQueue.push([null, {id: '1'}]);
|
||||
subdomains.upsert('test', 'A', [ '1.2.3.4' ], function (error, result) {
|
||||
|
||||
domains.upsertDNSRecords('test', DOMAIN_0.domain, 'A', [ '1.2.3.4' ], function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.eql('1');
|
||||
expect(zoneQueue.length).to.eql(0);
|
||||
@@ -597,7 +599,7 @@ describe('dns provider', function () {
|
||||
zoneQueue.push([null, [GCDNS().zone('test').record('A', {'name': 'test', data:['5.6.7.8'], ttl: 1})]]);
|
||||
zoneQueue.push([null, {id: '2'}]);
|
||||
|
||||
subdomains.upsert('test', 'A', [ '1.2.3.4' ], function (error, result) {
|
||||
domains.upsertDNSRecords('test', DOMAIN_0.domain, 'A', [ '1.2.3.4' ], function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.eql('2');
|
||||
expect(zoneQueue.length).to.eql(0);
|
||||
@@ -611,7 +613,7 @@ describe('dns provider', function () {
|
||||
zoneQueue.push([null, [ ]]); // getRecords
|
||||
zoneQueue.push([null, {id: '3'}]);
|
||||
|
||||
subdomains.upsert('', 'TXT', [ 'first', 'second', 'third' ], function (error, result) {
|
||||
domains.upsertDNSRecords('', config.fqdn(), 'TXT', [ 'first', 'second', 'third' ], function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.eql('3');
|
||||
expect(zoneQueue.length).to.eql(0);
|
||||
@@ -624,7 +626,7 @@ describe('dns provider', function () {
|
||||
zoneQueue.push([null, HOSTED_ZONES]);
|
||||
zoneQueue.push([null, [GCDNS().zone('test').record('A', {'name': 'test', data:['1.2.3.4', '5.6.7.8'], ttl: 1})]]);
|
||||
|
||||
subdomains.get('test', 'A', function (error, result) {
|
||||
domains.getDNSRecords('test', DOMAIN_0.domain, 'A', function (error, result) {
|
||||
expect(error).to.eql(null);
|
||||
expect(result).to.be.an(Array);
|
||||
expect(result.length).to.eql(2);
|
||||
@@ -640,7 +642,7 @@ describe('dns provider', function () {
|
||||
zoneQueue.push([null, [GCDNS().zone('test').record('A', {'name': 'test', data:['5.6.7.8'], ttl: 1})]]);
|
||||
zoneQueue.push([null, {id: '5'}]);
|
||||
|
||||
subdomains.remove('test', 'A', ['1.2.3.4'], function (error) {
|
||||
domains.removeDNSRecords('test', DOMAIN_0.domain, 'A', ['1.2.3.4'], function (error) {
|
||||
expect(error).to.eql(null);
|
||||
expect(zoneQueue.length).to.eql(0);
|
||||
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var database = require('../database.js'),
|
||||
expect = require('expect.js'),
|
||||
var async = require('async'),
|
||||
database = require('../database.js'),
|
||||
eventlog = require('../eventlog.js'),
|
||||
EventLogError = eventlog.EventLogError;
|
||||
EventLogError = eventlog.EventLogError,
|
||||
expect = require('expect.js');
|
||||
|
||||
function setup(done) {
|
||||
// ensure data/config/mount paths
|
||||
@@ -20,7 +21,10 @@ function setup(done) {
|
||||
}
|
||||
|
||||
function cleanup(done) {
|
||||
database._clear(done);
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
}
|
||||
|
||||
describe('Eventlog', function () {
|
||||
|
||||
+20
-9
@@ -7,6 +7,7 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
config = require('../config.js'),
|
||||
constants = require('../constants.js'),
|
||||
database = require('../database.js'),
|
||||
DatabaseError = require('../databaseerror.js'),
|
||||
@@ -23,6 +24,12 @@ var GROUP0_NAME = 'administrators',
|
||||
var GROUP1_NAME = 'externs',
|
||||
group1Object;
|
||||
|
||||
const DOMAIN_0 = {
|
||||
domain: 'example.com',
|
||||
zoneName: 'example.com',
|
||||
config: { provider: 'manual' }
|
||||
};
|
||||
|
||||
var USER_0 = {
|
||||
id: 'uuid213',
|
||||
username: 'uuid213',
|
||||
@@ -50,16 +57,20 @@ var USER_1 = { // this user has not signed up yet
|
||||
};
|
||||
|
||||
function setup(done) {
|
||||
// ensure data/config/mount paths
|
||||
database.initialize(function (error) {
|
||||
expect(error).to.be(null);
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
|
||||
database._clear(done);
|
||||
});
|
||||
// ensure data/config/mount paths
|
||||
async.series([
|
||||
database.initialize,
|
||||
database._clear
|
||||
], done);
|
||||
}
|
||||
|
||||
function cleanup(done) {
|
||||
database._clear(done);
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
}
|
||||
|
||||
describe('Groups', function () {
|
||||
@@ -118,7 +129,7 @@ describe('Groups', function () {
|
||||
});
|
||||
|
||||
it('did create mailbox', function (done) {
|
||||
mailboxdb.getGroup(GROUP0_NAME.toLowerCase(), function (error, mailbox) {
|
||||
mailboxdb.getGroup(GROUP0_NAME.toLowerCase(), DOMAIN_0.domain, function (error, mailbox) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailbox.ownerType).to.be(mailboxdb.TYPE_GROUP);
|
||||
done();
|
||||
@@ -162,7 +173,7 @@ describe('Groups', function () {
|
||||
});
|
||||
|
||||
it('did delete mailbox', function (done) {
|
||||
mailboxdb.getGroup(GROUP0_NAME.toLowerCase(), function (error) {
|
||||
mailboxdb.getGroup(GROUP0_NAME.toLowerCase(), DOMAIN_0.domain, function (error) {
|
||||
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
|
||||
done();
|
||||
});
|
||||
@@ -241,7 +252,7 @@ describe('Group membership', function () {
|
||||
});
|
||||
|
||||
it('can get list members', function (done) {
|
||||
mailboxdb.getGroup(GROUP0_NAME.toLowerCase(), function (error, result) {
|
||||
mailboxdb.getGroup(GROUP0_NAME.toLowerCase(), DOMAIN_0.domain, function (error, result) {
|
||||
expect(error).to.be(null);
|
||||
expect(result.name).to.be(GROUP0_NAME.toLowerCase());
|
||||
expect(result.ownerType).to.be(mailboxdb.TYPE_GROUP);
|
||||
|
||||
@@ -55,7 +55,10 @@ describe('janitor', function () {
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
database._clear(done);
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
});
|
||||
|
||||
it('can cleanupTokens', function (done) {
|
||||
|
||||
+84
-52
@@ -1,6 +1,6 @@
|
||||
/* jslint node:true */
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global xdescribe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
|
||||
@@ -60,13 +60,14 @@ var APP_0 = {
|
||||
installationProgress: null,
|
||||
runState: appdb.RSTATE_RUNNING,
|
||||
location: 'some-location-0',
|
||||
domain: 'example.com',
|
||||
manifest: { version: '0.1', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0' },
|
||||
httpPort: null,
|
||||
containerId: 'someContainerId',
|
||||
portBindings: { port: 5678 },
|
||||
health: null,
|
||||
accessRestriction: null,
|
||||
lastBackupId: null,
|
||||
restoreConfig: null,
|
||||
oldConfig: null,
|
||||
memoryLimit: 4294967296
|
||||
};
|
||||
@@ -81,15 +82,18 @@ function startDockerProxy(interceptor, callback) {
|
||||
}
|
||||
|
||||
function setup(done) {
|
||||
config._reset();
|
||||
config.set('fqdn', 'example.com');
|
||||
|
||||
async.series([
|
||||
database.initialize.bind(null),
|
||||
database._clear.bind(null),
|
||||
ldapServer.start.bind(null),
|
||||
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.portBindings, APP_0),
|
||||
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0),
|
||||
appdb.update.bind(null, APP_0.id, { containerId: APP_0.containerId }),
|
||||
appdb.setAddonConfig.bind(null, APP_0.id, 'sendmail', [{ name: 'MAIL_SMTP_PASSWORD', value : 'sendmailpassword' }]),
|
||||
appdb.setAddonConfig.bind(null, APP_0.id, 'recvmail', [{ name: 'MAIL_IMAP_PASSWORD', value : 'recvmailpassword' }]),
|
||||
mailboxdb.add.bind(null, APP_0.location + '.app', APP_0.id, mailboxdb.TYPE_APP),
|
||||
mailboxdb.add.bind(null, APP_0.location + '.app', APP_0.domain, APP_0.id, mailboxdb.TYPE_APP),
|
||||
|
||||
function (callback) {
|
||||
user.createOwner(USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE, function (error, result) {
|
||||
@@ -143,28 +147,28 @@ function setup(done) {
|
||||
|
||||
if (req.method === 'GET' && req.url === '/networks/cloudron') {
|
||||
answer = {
|
||||
Name: "cloudron",
|
||||
Id: "f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566",
|
||||
Scope: "local",
|
||||
Driver: "bridge",
|
||||
Name: 'cloudron',
|
||||
Id: 'f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566',
|
||||
Scope: 'local',
|
||||
Driver: 'bridge',
|
||||
IPAM: {
|
||||
Driver: "default",
|
||||
Driver: 'default',
|
||||
Config: [{
|
||||
Subnet: "172.18.0.0/16"
|
||||
Subnet: '172.18.0.0/16'
|
||||
}]
|
||||
},
|
||||
"Containers": {
|
||||
'Containers': {
|
||||
someOtherContainerId: {
|
||||
"EndpointID": "ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda",
|
||||
"MacAddress": "02:42:ac:11:00:02",
|
||||
"IPv4Address": "127.0.0.2/16",
|
||||
"IPv6Address": ""
|
||||
'EndpointID': 'ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda',
|
||||
'MacAddress': '02:42:ac:11:00:02',
|
||||
'IPv4Address': '127.0.0.2/16',
|
||||
'IPv6Address': ''
|
||||
},
|
||||
someContainerId: {
|
||||
"EndpointID": "ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda",
|
||||
"MacAddress": "02:42:ac:11:00:02",
|
||||
"IPv4Address": "127.0.0.1/16",
|
||||
"IPv6Address": ""
|
||||
'EndpointID': 'ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda',
|
||||
'MacAddress': '02:42:ac:11:00:02',
|
||||
'IPv4Address': '127.0.0.1/16',
|
||||
'IPv6Address': ''
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -181,7 +185,8 @@ function setup(done) {
|
||||
function cleanup(done) {
|
||||
async.series([
|
||||
ldapServer.stop,
|
||||
database._clear
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], function () {
|
||||
dockerProxy.close(function () { done(); }); // some strange error
|
||||
});
|
||||
@@ -199,7 +204,7 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('cn=doesnotexist,ou=users,dc=cloudron', 'password', function (error) {
|
||||
expect(error).to.be.a(ldap.NoSuchObjectError);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -208,7 +213,7 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('cn=' + USER_0.id + ',ou=users,dc=cloudron', 'wrongpassword', function (error) {
|
||||
expect(error).to.be.a(ldap.InvalidCredentialsError);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -217,7 +222,7 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('cn=' + USER_0.id + ',ou=users,dc=cloudron', USER_0.password, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -226,7 +231,7 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('cn=' + USER_0.username + ',ou=users,dc=cloudron', USER_0.password, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -235,7 +240,7 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('cn=' + USER_0.email + ',ou=users,dc=cloudron', USER_0.password, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -249,6 +254,8 @@ describe('Ldap', function () {
|
||||
client.bind('cn=' + USER_0.username.toLowerCase() + '@' + config.fqdn() + ',ou=users,dc=cloudron', USER_0.password, function (error) {
|
||||
expect(error).to.be(null);
|
||||
|
||||
client.unbind();
|
||||
|
||||
settingsdb.set(settings.MAIL_CONFIG_KEY, JSON.stringify({ enabled: false }), done);
|
||||
});
|
||||
});
|
||||
@@ -259,19 +266,19 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('mail=' + USER_0.username + ',ou=users,dc=cloudron', USER_0.password, function (error) {
|
||||
expect(error).to.be.a(ldap.NoSuchObjectError);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('fails with accessRestriction denied', function (done) {
|
||||
var client = ldap.createClient({ url: 'ldap://127.0.0.1:' + config.get('ldapPort') });
|
||||
|
||||
appdb.update(APP_0.id, { accessRestriction: { users: [ USER_1.id ], groups: [] }}, function (error) {
|
||||
appdb.update(APP_0.id, { accessRestriction: { users: [ USER_0.id ], groups: [] }}, function (error) {
|
||||
expect(error).to.eql(null);
|
||||
|
||||
client.bind('cn=' + USER_0.id + ',ou=users,dc=cloudron', USER_0.password, function (error) {
|
||||
client.bind('cn=' + USER_1.id + ',ou=users,dc=cloudron', USER_1.password, function (error) {
|
||||
expect(error).to.be.a(ldap.NoSuchObjectError);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -284,7 +291,7 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('cn=' + USER_0.id + ',ou=users,dc=cloudron', USER_0.password, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -304,7 +311,7 @@ describe('Ldap', function () {
|
||||
|
||||
result.on('error', function (error) {
|
||||
expect(error).to.be.a(ldap.NoSuchObjectError);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
result.on('end', function (result) {
|
||||
done(new Error('Should not succeed. Status ' + result.status));
|
||||
@@ -335,7 +342,7 @@ describe('Ldap', function () {
|
||||
expect(entries[0].mail).to.equal(USER_0.email.toLowerCase());
|
||||
expect(entries[1].username).to.equal(USER_1.username.toLowerCase());
|
||||
expect(entries[1].mail).to.equal(USER_1.email.toLowerCase());
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -364,7 +371,7 @@ describe('Ldap', function () {
|
||||
expect(entries[0].mail).to.equal(USER_0.email.toLowerCase());
|
||||
expect(entries[1].username).to.equal(USER_1.username.toLowerCase());
|
||||
expect(entries[1].mail).to.equal(USER_1.email.toLowerCase());
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -400,6 +407,8 @@ describe('Ldap', function () {
|
||||
expect(entries[1].mailAlternateAddress).to.equal(USER_1.email.toLowerCase());
|
||||
expect(entries[1].mail).to.equal(USER_1.username.toLowerCase() + '@' + config.fqdn());
|
||||
|
||||
client.unbind();
|
||||
|
||||
settingsdb.set(settings.MAIL_CONFIG_KEY, JSON.stringify({ enabled: false }), done);
|
||||
});
|
||||
});
|
||||
@@ -427,7 +436,7 @@ describe('Ldap', function () {
|
||||
entries.sort(function (a, b) { return a.username > b.username; });
|
||||
expect(entries[0].username).to.equal(USER_0.username.toLowerCase());
|
||||
expect(entries[1].username).to.equal(USER_1.username.toLowerCase());
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -452,12 +461,12 @@ describe('Ldap', function () {
|
||||
expect(entries.length).to.equal(1);
|
||||
expect(entries[0].username).to.equal(USER_0.username.toLowerCase());
|
||||
expect(entries[0].memberof.length).to.equal(2);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it ('does not list users who have no access', function (done) {
|
||||
it ('always lists admins', function (done) {
|
||||
appdb.update(APP_0.id, { accessRestriction: { users: [], groups: [] } }, function (error) {
|
||||
expect(error).to.be(null);
|
||||
|
||||
@@ -477,7 +486,11 @@ describe('Ldap', function () {
|
||||
result.on('error', done);
|
||||
result.on('end', function (result) {
|
||||
expect(result.status).to.equal(0);
|
||||
expect(entries.length).to.equal(0);
|
||||
expect(entries.length).to.equal(1);
|
||||
expect(entries[0].username).to.equal(USER_0.username.toLowerCase());
|
||||
expect(entries[0].memberof.length).to.equal(2);
|
||||
|
||||
client.unbind();
|
||||
|
||||
appdb.update(APP_0.id, { accessRestriction: null }, done);
|
||||
});
|
||||
@@ -511,6 +524,8 @@ describe('Ldap', function () {
|
||||
expect(entries[0].username).to.equal(USER_0.username.toLowerCase());
|
||||
expect(entries[1].username).to.equal(USER_1.username.toLowerCase());
|
||||
|
||||
client.unbind();
|
||||
|
||||
appdb.update(APP_0.id, { accessRestriction: null }, done);
|
||||
});
|
||||
});
|
||||
@@ -549,7 +564,7 @@ describe('Ldap', function () {
|
||||
expect(entries[1].cn).to.equal('admins');
|
||||
// if only one entry, the array becomes a string :-/
|
||||
expect(entries[1].memberuid).to.equal(USER_0.id);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -580,7 +595,7 @@ describe('Ldap', function () {
|
||||
expect(entries[1].cn).to.equal('admins');
|
||||
// if only one entry, the array becomes a string :-/
|
||||
expect(entries[1].memberuid).to.equal(USER_0.id);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -605,7 +620,7 @@ describe('Ldap', function () {
|
||||
expect(entries.length).to.equal(1);
|
||||
expect(entries[0].cn).to.equal('users');
|
||||
expect(entries[0].memberuid.length).to.equal(3);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -639,6 +654,8 @@ describe('Ldap', function () {
|
||||
// if only one entry, the array becomes a string :-/
|
||||
expect(entries[1].memberuid).to.equal(USER_0.id);
|
||||
|
||||
client.unbind();
|
||||
|
||||
appdb.update(APP_0.id, { accessRestriction: null }, done);
|
||||
});
|
||||
});
|
||||
@@ -676,7 +693,7 @@ describe('Ldap', function () {
|
||||
expect(entries[1].cn).to.equal('admins');
|
||||
// if only one entry, the array becomes a string :-/
|
||||
expect(entries[1].memberuid).to.equal(USER_0.id);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -690,6 +707,12 @@ describe('Ldap', function () {
|
||||
paged: true
|
||||
};
|
||||
|
||||
function done(error, entries) {
|
||||
client.unbind(function () {
|
||||
callback(error, entries);
|
||||
});
|
||||
}
|
||||
|
||||
client.search(dn, opts, function (error, result) {
|
||||
expect(error).to.be(null);
|
||||
expect(result).to.be.an(EventEmitter);
|
||||
@@ -697,10 +720,10 @@ describe('Ldap', function () {
|
||||
var entries = [];
|
||||
|
||||
result.on('searchEntry', function (entry) { entries.push(entry.object); });
|
||||
result.on('error', callback);
|
||||
result.on('error', done);
|
||||
result.on('end', function (result) {
|
||||
expect(result.status).to.equal(0);
|
||||
callback(null, entries);
|
||||
done(null, entries);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -725,7 +748,7 @@ describe('Ldap', function () {
|
||||
});
|
||||
|
||||
it('cannot get alias as a mailbox', function (done) {
|
||||
ldapSearch('cn=' + USER_0_ALIAS + ',ou=mailboxes,dc=cloudron', 'objectclass=mailbox', function (error, entries) {
|
||||
ldapSearch('cn=' + USER_0_ALIAS + ',ou=mailboxes,dc=cloudron', 'objectclass=mailbox', function (error) {
|
||||
expect(error).to.be.a(ldap.NoSuchObjectError);
|
||||
done();
|
||||
});
|
||||
@@ -751,7 +774,7 @@ describe('Ldap', function () {
|
||||
});
|
||||
|
||||
it('cannot get mailbox as alias', function (done) {
|
||||
ldapSearch('cn=' + USER_0.username + ',ou=mailaliases,dc=cloudron', 'objectclass=nismailalias', function (error, entries) {
|
||||
ldapSearch('cn=' + USER_0.username + ',ou=mailaliases,dc=cloudron', 'objectclass=nismailalias', function (error) {
|
||||
expect(error).to.be.a(ldap.NoSuchObjectError);
|
||||
done();
|
||||
});
|
||||
@@ -809,7 +832,7 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('cn=' + USER_0.username + ',ou=sendmail,dc=cloudron', USER_0.password + 'nope', function (error) {
|
||||
expect(error).to.be.a(ldap.InvalidCredentialsError);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -817,6 +840,7 @@ describe('Ldap', function () {
|
||||
var client = ldap.createClient({ url: 'ldap://127.0.0.1:' + config.get('ldapPort') });
|
||||
|
||||
client.bind('cn=' + USER_0.username + ',ou=sendmail,dc=cloudron', USER_0.password, function (error) {
|
||||
client.unbind();
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
@@ -831,6 +855,8 @@ describe('Ldap', function () {
|
||||
client.bind('cn=' + USER_0.username + '@' + config.fqdn() + ',ou=sendmail,dc=cloudron', USER_0.password, function (error) {
|
||||
expect(error).not.to.be.ok();
|
||||
|
||||
client.unbind();
|
||||
|
||||
settingsdb.set(settings.MAIL_CONFIG_KEY, JSON.stringify({ enabled: false }), done);
|
||||
});
|
||||
});
|
||||
@@ -843,7 +869,7 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('cn=hacker.app,ou=sendmail,dc=cloudron', 'nope', function (error) {
|
||||
expect(error).to.be.a(ldap.NoSuchObjectError);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -852,7 +878,7 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('cn=' + APP_0.location + '.app,ou=sendmail,dc=cloudron', 'nope', function (error) {
|
||||
expect(error).to.be.a(ldap.InvalidCredentialsError);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -860,6 +886,7 @@ describe('Ldap', function () {
|
||||
var client = ldap.createClient({ url: 'ldap://127.0.0.1:' + config.get('ldapPort') });
|
||||
|
||||
client.bind('cn=' + APP_0.location + '.app,ou=sendmail,dc=cloudron', 'sendmailpassword', function (error) {
|
||||
client.unbind();
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
@@ -871,7 +898,7 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('cn=' + USER_0.username + ',ou=recvmail,dc=cloudron', USER_0.password + 'nope', function (error) {
|
||||
expect(error).to.be.a(ldap.InvalidCredentialsError);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -879,6 +906,8 @@ describe('Ldap', function () {
|
||||
var client = ldap.createClient({ url: 'ldap://127.0.0.1:' + config.get('ldapPort') });
|
||||
|
||||
client.bind('cn=' + USER_0.username + ',ou=recvmail,dc=cloudron', USER_0.password, function (error) {
|
||||
client.unbind();
|
||||
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
@@ -893,6 +922,8 @@ describe('Ldap', function () {
|
||||
client.bind('cn=' + USER_0.username + '@' + config.fqdn() + ',ou=recvmail,dc=cloudron', USER_0.password, function (error) {
|
||||
expect(error).not.to.be.ok();
|
||||
|
||||
client.unbind();
|
||||
|
||||
settingsdb.set(settings.MAIL_CONFIG_KEY, JSON.stringify({ enabled: false }), done);
|
||||
});
|
||||
});
|
||||
@@ -905,7 +936,7 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('cn=hacker.app,ou=recvmail,dc=cloudron', 'nope', function (error) {
|
||||
expect(error).to.be.a(ldap.NoSuchObjectError);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -914,7 +945,7 @@ describe('Ldap', function () {
|
||||
|
||||
client.bind('cn=' + APP_0.location + '.app,ou=recvmail,dc=cloudron', 'nope', function (error) {
|
||||
expect(error).to.be.a(ldap.InvalidCredentialsError);
|
||||
done();
|
||||
client.unbind(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -922,9 +953,10 @@ describe('Ldap', function () {
|
||||
var client = ldap.createClient({ url: 'ldap://127.0.0.1:' + config.get('ldapPort') });
|
||||
|
||||
client.bind('cn=' + APP_0.location + '.app,ou=recvmail,dc=cloudron', 'recvmailpassword', function (error) {
|
||||
client.unbind();
|
||||
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
+20
-18
@@ -24,7 +24,9 @@ describe('Server', function () {
|
||||
this.timeout(5000);
|
||||
|
||||
before(function () {
|
||||
config.set('version', '0.5.0');
|
||||
config._reset();
|
||||
config.setFqdn('example-server-test.com');
|
||||
config.set('provider', 'notcaas'); // otherwise, cron sets a caas timer for heartbeat causing the test to not quit
|
||||
});
|
||||
|
||||
after(cleanup);
|
||||
@@ -91,22 +93,22 @@ describe('Server', function () {
|
||||
superagent.get(SERVER_URL + '/api/v1/cloudron/status', function (err, res) {
|
||||
expect(err).to.not.be.ok();
|
||||
expect(res.statusCode).to.equal(200);
|
||||
expect(res.body.version).to.equal('0.5.0');
|
||||
expect(res.body.version).to.equal('1.1.1-test');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('status route is GET', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/cloudron/status')
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(404);
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(404);
|
||||
|
||||
superagent.get(SERVER_URL + '/api/v1/cloudron/status')
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
done();
|
||||
superagent.get(SERVER_URL + '/api/v1/cloudron/status')
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -227,21 +229,21 @@ describe('Server', function () {
|
||||
.set('Access-Control-Request-Headers', 'accept, origin, x-superagented-with')
|
||||
.set('Origin', 'http://localhost')
|
||||
.end(function (error, res) {
|
||||
expect(res.headers['access-control-allow-methods']).to.be('GET, PUT, DELETE, POST, OPTIONS');
|
||||
expect(res.headers['access-control-allow-credentials']).to.be('false');
|
||||
expect(res.headers['access-control-allow-headers']).to.be('accept, origin, x-superagented-with'); // mirrored from superagent
|
||||
expect(res.headers['access-control-allow-origin']).to.be('http://localhost'); // mirrors from superagent
|
||||
done();
|
||||
});
|
||||
expect(res.headers['access-control-allow-methods']).to.be('GET, PUT, DELETE, POST, OPTIONS');
|
||||
expect(res.headers['access-control-allow-credentials']).to.be('false');
|
||||
expect(res.headers['access-control-allow-headers']).to.be('accept, origin, x-superagented-with'); // mirrored from superagent
|
||||
expect(res.headers['access-control-allow-origin']).to.be('http://localhost'); // mirrors from superagent
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('does not crash for malformed origin', function (done) {
|
||||
superagent('OPTIONS', SERVER_URL + '/api/v1/cloudron/status')
|
||||
.set('Origin', 'foobar')
|
||||
.end(function (error, res) {
|
||||
expect(res.statusCode).to.be(405);
|
||||
done();
|
||||
});
|
||||
expect(res.statusCode).to.be(405);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
|
||||
@@ -19,6 +19,8 @@ var async = require('async'),
|
||||
settingsdb = require('../settingsdb.js');
|
||||
|
||||
function setup(done) {
|
||||
config._reset();
|
||||
config.set('fqdn', 'example.com');
|
||||
config.set('provider', 'caas');
|
||||
nock.cleanAll();
|
||||
|
||||
@@ -45,7 +47,8 @@ function cleanup(done) {
|
||||
|
||||
async.series([
|
||||
settings.uninitialize,
|
||||
database._clear
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
}
|
||||
|
||||
@@ -86,47 +89,6 @@ describe('Settings', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('can get default developer mode', function (done) {
|
||||
settings.getDeveloperMode(function (error, enabled) {
|
||||
expect(error).to.be(null);
|
||||
expect(enabled).to.equal(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can set developer mode', function (done) {
|
||||
settings.setDeveloperMode(true, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can get developer mode', function (done) {
|
||||
settings.getDeveloperMode(function (error, enabled) {
|
||||
expect(error).to.be(null);
|
||||
expect(enabled).to.equal(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can set dns config', function (done) {
|
||||
settings.setDnsConfig({ provider: 'route53', accessKeyId: 'accessKeyId', secretAccessKey: 'secretAccessKey' }, config.fqdn(), config.zoneName(), function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can get dns config', function (done) {
|
||||
settings.getDnsConfig(function (error, dnsConfig) {
|
||||
expect(error).to.be(null);
|
||||
expect(dnsConfig.provider).to.be('route53');
|
||||
expect(dnsConfig.accessKeyId).to.be('accessKeyId');
|
||||
expect(dnsConfig.secretAccessKey).to.be('secretAccessKey');
|
||||
expect(dnsConfig.region).to.be('us-east-1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can set tls config', function (done) {
|
||||
settings.setTlsConfig({ provider: 'caas' }, function (error) {
|
||||
expect(error).to.be(null);
|
||||
@@ -147,7 +109,7 @@ describe('Settings', function () {
|
||||
.post('/api/v1/boxes/' + config.fqdn() + '/awscredentials?token=TOKEN')
|
||||
.reply(201, { credentials: { AccessKeyId: 'accessKeyId', SecretAccessKey: 'secretAccessKey', SessionToken: 'sessionToken' } });
|
||||
|
||||
settings.setBackupConfig({ provider: 'caas', token: 'TOKEN', format: 'tgz', prefix: 'boxid', bucket: 'bucket' }, function (error) {
|
||||
settings.setBackupConfig({ provider: 'caas', fqdn: config.fqdn(), token: 'TOKEN', format: 'tgz', prefix: 'boxid', bucket: 'bucket' }, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -28,6 +28,12 @@ var USER_0 = {
|
||||
displayName: 'User 0'
|
||||
};
|
||||
|
||||
const DOMAIN_0 = {
|
||||
domain: 'example.com',
|
||||
zoneName: 'example.com',
|
||||
config: { provider: 'manual' }
|
||||
};
|
||||
|
||||
var AUDIT_SOURCE = {
|
||||
ip: '1.2.3.4'
|
||||
};
|
||||
@@ -47,14 +53,15 @@ function cleanup(done) {
|
||||
|
||||
async.series([
|
||||
settings.uninitialize,
|
||||
database._clear
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
}
|
||||
|
||||
describe('updatechecker - box - manual (email)', function () {
|
||||
before(function (done) {
|
||||
config._reset();
|
||||
config.set('version', '1.0.0');
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
config.set('apiServerOrigin', 'http://localhost:4444');
|
||||
config.set('provider', 'notcaas');
|
||||
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
|
||||
@@ -66,8 +73,7 @@ describe('updatechecker - box - manual (email)', function () {
|
||||
user.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE),
|
||||
settings.setAutoupdatePattern.bind(null, constants.AUTOUPDATE_PATTERN_NEVER),
|
||||
settingsdb.set.bind(null, settings.APPSTORE_CONFIG_KEY, JSON.stringify({ userId: 'uid', cloudronId: 'cid', token: 'token' })),
|
||||
mailer._clearMailQueue,
|
||||
mailer.start
|
||||
mailer._clearMailQueue
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -157,14 +163,14 @@ describe('updatechecker - box - manual (email)', function () {
|
||||
|
||||
describe('updatechecker - box - automatic (no email)', function () {
|
||||
before(function (done) {
|
||||
config.set('version', '1.0.0');
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
config.set('apiServerOrigin', 'http://localhost:4444');
|
||||
config.set('provider', 'notcaas');
|
||||
|
||||
async.series([
|
||||
database.initialize,
|
||||
settings.initialize,
|
||||
mailer._clearMailQueue,
|
||||
mailer.start,
|
||||
user.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE),
|
||||
settingsdb.set.bind(null, settings.APPSTORE_CONFIG_KEY, JSON.stringify({ userId: 'uid', cloudronId: 'cid', token: 'token' }))
|
||||
], done);
|
||||
@@ -198,9 +204,11 @@ describe('updatechecker - box - automatic (no email)', function () {
|
||||
|
||||
describe('updatechecker - box - automatic free (email)', function () {
|
||||
before(function (done) {
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
config.set('version', '1.0.0');
|
||||
config.set('apiServerOrigin', 'http://localhost:4444');
|
||||
config.set('provider', 'notcaas');
|
||||
|
||||
async.series([
|
||||
database.initialize,
|
||||
settings.initialize,
|
||||
@@ -244,6 +252,7 @@ describe('updatechecker - app - manual (email)', function () {
|
||||
installationProgress: null,
|
||||
runState: null,
|
||||
location: 'some-location-0',
|
||||
domain: DOMAIN_0.domain,
|
||||
manifest: {
|
||||
version: '1.0.0', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0',
|
||||
tcpPorts: {
|
||||
@@ -262,6 +271,7 @@ describe('updatechecker - app - manual (email)', function () {
|
||||
};
|
||||
|
||||
before(function (done) {
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
config.set('version', '1.0.0');
|
||||
config.set('apiServerOrigin', 'http://localhost:4444');
|
||||
config.set('provider', 'notcaas');
|
||||
@@ -271,7 +281,7 @@ describe('updatechecker - app - manual (email)', function () {
|
||||
database._clear,
|
||||
settings.initialize,
|
||||
mailer._clearMailQueue,
|
||||
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.portBindings, APP_0),
|
||||
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0),
|
||||
user.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE),
|
||||
settings.setAutoupdatePattern.bind(null, constants.AUTOUPDATE_PATTERN_NEVER),
|
||||
settingsdb.set.bind(null, settings.APPSTORE_CONFIG_KEY, JSON.stringify({ userId: 'uid', cloudronId: 'cid', token: 'token' }))
|
||||
@@ -356,6 +366,7 @@ describe('updatechecker - app - automatic (no email)', function () {
|
||||
installationProgress: null,
|
||||
runState: null,
|
||||
location: 'some-location-0',
|
||||
domain: DOMAIN_0.domain,
|
||||
manifest: {
|
||||
version: '1.0.0', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0',
|
||||
tcpPorts: {
|
||||
@@ -374,6 +385,7 @@ describe('updatechecker - app - automatic (no email)', function () {
|
||||
};
|
||||
|
||||
before(function (done) {
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
config.set('version', '1.0.0');
|
||||
config.set('apiServerOrigin', 'http://localhost:4444');
|
||||
config.set('provider', 'notcaas');
|
||||
@@ -383,7 +395,7 @@ describe('updatechecker - app - automatic (no email)', function () {
|
||||
database._clear,
|
||||
settings.initialize,
|
||||
mailer._clearMailQueue,
|
||||
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.portBindings, APP_0),
|
||||
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0),
|
||||
user.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE),
|
||||
settingsdb.set.bind(null, settings.APPSTORE_CONFIG_KEY, JSON.stringify({ userId: 'uid', cloudronId: 'cid', token: 'token' }))
|
||||
], done);
|
||||
@@ -417,6 +429,7 @@ describe('updatechecker - app - automatic free (email)', function () {
|
||||
installationProgress: null,
|
||||
runState: null,
|
||||
location: 'some-location-0',
|
||||
domain: DOMAIN_0.domain,
|
||||
manifest: {
|
||||
version: '1.0.0', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0',
|
||||
tcpPorts: {
|
||||
@@ -435,6 +448,7 @@ describe('updatechecker - app - automatic free (email)', function () {
|
||||
};
|
||||
|
||||
before(function (done) {
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
config.set('version', '1.0.0');
|
||||
config.set('apiServerOrigin', 'http://localhost:4444');
|
||||
config.set('provider', 'notcaas');
|
||||
@@ -444,7 +458,7 @@ describe('updatechecker - app - automatic free (email)', function () {
|
||||
database._clear,
|
||||
settings.initialize,
|
||||
mailer._clearMailQueue,
|
||||
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.portBindings, APP_0),
|
||||
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0),
|
||||
user.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE),
|
||||
settingsdb.set.bind(null, settings.APPSTORE_CONFIG_KEY, JSON.stringify({ userId: 'uid', cloudronId: 'cid', token: 'token' }))
|
||||
], done);
|
||||
|
||||
+19
-7
@@ -39,6 +39,12 @@ var EMAIL_1 = 'second@user.com';
|
||||
var PASSWORD_1 = 'Sup2345$@strong';
|
||||
var DISPLAY_NAME_1 = 'Second User';
|
||||
|
||||
const DOMAIN_0 = {
|
||||
domain: 'example.com',
|
||||
zoneName: 'example.com',
|
||||
config: { provider: 'manual' }
|
||||
};
|
||||
|
||||
function cleanupUsers(done) {
|
||||
async.series([
|
||||
groupdb._clear,
|
||||
@@ -62,6 +68,9 @@ function createOwner(done) {
|
||||
}
|
||||
|
||||
function setup(done) {
|
||||
config._reset();
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
|
||||
async.series([
|
||||
database.initialize,
|
||||
database._clear,
|
||||
@@ -72,7 +81,10 @@ function setup(done) {
|
||||
function cleanup(done) {
|
||||
mailer._clearMailQueue();
|
||||
|
||||
database._clear(done);
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
}
|
||||
|
||||
function checkMails(number, options, callback) {
|
||||
@@ -205,7 +217,7 @@ describe('User', function () {
|
||||
});
|
||||
|
||||
it('did create mailbox', function (done) {
|
||||
mailboxdb.getMailbox(USERNAME.toLowerCase(), function (error, mailbox) {
|
||||
mailboxdb.getMailbox(USERNAME.toLowerCase(), DOMAIN_0.domain, function (error, mailbox) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailbox.ownerType).to.be(mailboxdb.TYPE_USER);
|
||||
done();
|
||||
@@ -712,10 +724,10 @@ describe('User', function () {
|
||||
});
|
||||
|
||||
it('updated the mailbox', function (done) {
|
||||
mailboxdb.getMailbox(USERNAME, function (error) {
|
||||
mailboxdb.getMailbox(USERNAME, DOMAIN_0.domain, function (error) {
|
||||
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
|
||||
|
||||
mailboxdb.getMailbox(USERNAME_NEW.toLowerCase(), function (error, mailbox) {
|
||||
mailboxdb.getMailbox(USERNAME_NEW.toLowerCase(), DOMAIN_0.domain, function (error, mailbox) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailbox.ownerId).to.be(userObject.id);
|
||||
done();
|
||||
@@ -998,7 +1010,7 @@ describe('User', function () {
|
||||
user.setAliases(userObject.id, [ 'everything', 'is', 'awesome' ], function (error) {
|
||||
expect(error).to.be(null);
|
||||
|
||||
mailboxdb.getAliasesForName(USERNAME.toLowerCase(), function (error, results) {
|
||||
mailboxdb.getAliasesForName(USERNAME.toLowerCase(), DOMAIN_0.domain, function (error, results) {
|
||||
expect(error).to.be(null);
|
||||
expect(results.length).to.be(3);
|
||||
done();
|
||||
@@ -1014,10 +1026,10 @@ describe('User', function () {
|
||||
});
|
||||
|
||||
it('did delete mailbox and aliases', function (done) {
|
||||
mailboxdb.getMailbox(userObject.username.toLowerCase(), function (error, mailbox) {
|
||||
mailboxdb.getMailbox(userObject.username.toLowerCase(), DOMAIN_0.domain, function (error, mailbox) {
|
||||
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
|
||||
|
||||
mailboxdb.getAliasesForName(USERNAME.toLowerCase(), function (error, results) {
|
||||
mailboxdb.getAliasesForName(USERNAME.toLowerCase(), DOMAIN_0.domain, function (error, results) {
|
||||
expect(error).to.be(null);
|
||||
expect(results.length).to.be(0);
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user