2017-09-29 09:56:01 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
2021-06-03 12:20:44 -07:00
|
|
|
const appdb = require('../appdb.js'),
|
|
|
|
|
apps = require('../apps.js'),
|
|
|
|
|
async = require('async'),
|
|
|
|
|
blobs = require('../blobs.js'),
|
2021-07-09 17:09:10 +02:00
|
|
|
constants = require('../constants.js'),
|
2021-06-03 12:20:44 -07:00
|
|
|
database = require('../database.js'),
|
|
|
|
|
domains = require('../domains.js'),
|
|
|
|
|
fs = require('fs'),
|
2021-06-28 15:15:28 -07:00
|
|
|
hat = require('../hat.js'),
|
2021-07-07 12:59:17 -07:00
|
|
|
mail = require('../mail.js'),
|
|
|
|
|
mailboxdb = require('../mailboxdb.js'),
|
2021-06-03 12:20:44 -07:00
|
|
|
mailer = require('../mailer.js'),
|
|
|
|
|
nock = require('nock'),
|
2017-09-29 09:56:01 -07:00
|
|
|
path = require('path'),
|
2021-06-03 12:20:44 -07:00
|
|
|
rimraf = require('rimraf'),
|
|
|
|
|
settings = require('../settings.js'),
|
|
|
|
|
settingsdb = require('../settingsdb.js'),
|
2021-07-14 19:03:12 -07:00
|
|
|
tasks = require('../tasks.js'),
|
2021-06-03 12:20:44 -07:00
|
|
|
users = require('../users.js');
|
|
|
|
|
|
|
|
|
|
const MANIFEST = {
|
|
|
|
|
'id': 'io.cloudron.test',
|
|
|
|
|
'author': 'The Presidents Of the United States Of America',
|
|
|
|
|
'title': 'test title',
|
|
|
|
|
'description': 'test description',
|
|
|
|
|
'tagline': 'test rocks',
|
|
|
|
|
'website': 'http://test.cloudron.io',
|
|
|
|
|
'contactEmail': 'test@cloudron.io',
|
|
|
|
|
'version': '0.1.0',
|
|
|
|
|
'manifestVersion': 1,
|
|
|
|
|
'dockerImage': 'cloudron/test:25.2.0',
|
|
|
|
|
'healthCheckPath': '/',
|
|
|
|
|
'httpPort': 7777,
|
|
|
|
|
'tcpPorts': {
|
|
|
|
|
'ECHO_SERVER_PORT': {
|
|
|
|
|
'title': 'Echo Server Port',
|
|
|
|
|
'description': 'Echo server',
|
|
|
|
|
'containerPort': 7778
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'addons': {
|
|
|
|
|
'oauth': { },
|
|
|
|
|
'redis': { },
|
|
|
|
|
'mysql': { },
|
|
|
|
|
'postgresql': { }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const DOMAIN = {
|
|
|
|
|
domain: 'example.com',
|
|
|
|
|
zoneName: 'example.com',
|
2021-06-03 16:16:04 -07:00
|
|
|
provider: 'noop',
|
|
|
|
|
config: {},
|
2021-06-03 12:20:44 -07:00
|
|
|
fallbackCertificate: null,
|
2021-06-03 16:16:04 -07:00
|
|
|
tlsConfig: { provider: 'fallback' },
|
2021-06-03 12:20:44 -07:00
|
|
|
wellKnown: null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const AUDIT_SOURCE = { ip: '1.2.3.4' };
|
|
|
|
|
|
|
|
|
|
const ADMIN = {
|
2021-06-28 15:15:28 -07:00
|
|
|
id: null,
|
2021-06-03 12:20:44 -07:00
|
|
|
username: 'admin123',
|
|
|
|
|
password: 'secret123',
|
|
|
|
|
email: 'admin@me.com',
|
|
|
|
|
fallbackEmail: 'admin@me.com',
|
|
|
|
|
salt: 'morton',
|
|
|
|
|
createdAt: 'sometime back',
|
|
|
|
|
resetToken: '',
|
|
|
|
|
displayName: '',
|
2021-07-09 17:09:10 +02:00
|
|
|
groupIds: [],
|
2021-06-03 12:20:44 -07:00
|
|
|
role: 'owner',
|
2021-07-09 17:09:10 +02:00
|
|
|
source: '',
|
2021-07-19 12:43:30 -07:00
|
|
|
avatar: constants.AVATAR_GRAVATAR,
|
|
|
|
|
active: true,
|
2021-06-03 12:20:44 -07:00
|
|
|
};
|
|
|
|
|
|
2021-06-28 15:15:28 -07:00
|
|
|
const USER = {
|
2021-07-07 12:59:17 -07:00
|
|
|
id: 'uid-userid', // ldap logic relies on uid prefix
|
2021-06-28 15:15:28 -07:00
|
|
|
username: 'uuid213',
|
2021-07-07 12:59:17 -07:00
|
|
|
password: '123secret',
|
2021-06-28 15:15:28 -07:00
|
|
|
email: 'safe@me.com',
|
|
|
|
|
fallbackEmail: 'safefallback@me.com',
|
|
|
|
|
role: 'user',
|
|
|
|
|
salt: 'morton',
|
|
|
|
|
createdAt: 'sometime back',
|
|
|
|
|
resetToken: hat(256),
|
2021-07-09 17:09:10 +02:00
|
|
|
groupIds: [],
|
2021-06-28 15:15:28 -07:00
|
|
|
displayName: '',
|
|
|
|
|
source: '',
|
2021-07-07 12:59:17 -07:00
|
|
|
permissions: null,
|
2021-07-19 12:43:30 -07:00
|
|
|
avatar: constants.AVATAR_NONE,
|
|
|
|
|
active: true,
|
2021-06-28 15:15:28 -07:00
|
|
|
};
|
|
|
|
|
|
2021-06-03 12:20:44 -07:00
|
|
|
const APP = {
|
|
|
|
|
id: 'appid',
|
|
|
|
|
appStoreId: 'appStoreId',
|
|
|
|
|
installationState: apps.ISTATE_PENDING_INSTALL,
|
|
|
|
|
runState: 'running',
|
|
|
|
|
location: 'applocation',
|
|
|
|
|
domain: DOMAIN.domain,
|
|
|
|
|
fqdn: DOMAIN.domain + '.' + 'applocation',
|
|
|
|
|
manifest: MANIFEST,
|
|
|
|
|
containerId: 'someid',
|
|
|
|
|
portBindings: null,
|
|
|
|
|
accessRestriction: null,
|
|
|
|
|
memoryLimit: 0,
|
|
|
|
|
mailboxDomain: DOMAIN.domain,
|
|
|
|
|
alternateDomains: [],
|
|
|
|
|
aliasDomains: []
|
|
|
|
|
};
|
2017-09-29 09:56:01 -07:00
|
|
|
|
|
|
|
|
exports = module.exports = {
|
2021-06-03 12:20:44 -07:00
|
|
|
createTree,
|
2021-07-19 12:43:30 -07:00
|
|
|
domainSetup,
|
2021-06-03 12:20:44 -07:00
|
|
|
setup,
|
|
|
|
|
cleanup,
|
|
|
|
|
|
|
|
|
|
MOCK_API_SERVER_ORIGIN: 'http://localhost:6060',
|
|
|
|
|
DASHBOARD_DOMAIN: 'test.example.com',
|
|
|
|
|
DASHBOARD_FQDN: 'my.test.example.com',
|
|
|
|
|
|
|
|
|
|
APP,
|
|
|
|
|
ADMIN,
|
|
|
|
|
AUDIT_SOURCE,
|
|
|
|
|
DOMAIN,
|
|
|
|
|
MANIFEST,
|
2021-06-28 15:15:28 -07:00
|
|
|
USER,
|
2021-07-07 12:59:17 -07:00
|
|
|
APPSTORE_TOKEN: 'atoken',
|
|
|
|
|
|
|
|
|
|
MAILBOX_NAME: 'support',
|
|
|
|
|
MAILBOX: `support@${DOMAIN.domain}`,
|
|
|
|
|
ALIAS_NAME: 'alsosupport',
|
|
|
|
|
ALIAS: `alsosupport@${DOMAIN.domain}`
|
2017-09-29 09:56:01 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function createTree(root, obj) {
|
|
|
|
|
rimraf.sync(root);
|
2020-06-11 08:27:48 -07:00
|
|
|
fs.mkdirSync(root, { recursive: true });
|
2017-09-29 09:56:01 -07:00
|
|
|
|
|
|
|
|
function createSubTree(tree, curpath) {
|
|
|
|
|
for (var key in tree) {
|
|
|
|
|
if (typeof tree[key] === 'string') {
|
|
|
|
|
if (key.startsWith('link:')) {
|
|
|
|
|
fs.symlinkSync(tree[key], path.join(curpath, key.slice(5)));
|
|
|
|
|
} else {
|
|
|
|
|
fs.writeFileSync(path.join(curpath, key), tree[key], 'utf8');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
fs.mkdirSync(path.join(curpath, key));
|
|
|
|
|
createSubTree(tree[key], path.join(curpath, key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createSubTree(obj, root);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 12:43:30 -07:00
|
|
|
function domainSetup(done) {
|
2021-06-03 12:20:44 -07:00
|
|
|
nock.cleanAll();
|
|
|
|
|
|
|
|
|
|
async.series([
|
|
|
|
|
database.initialize,
|
|
|
|
|
database._clear,
|
|
|
|
|
settings._setApiServerOrigin.bind(null, exports.MOCK_API_SERVER_ORIGIN),
|
|
|
|
|
settings.setDashboardLocation.bind(null, exports.DASHBOARD_DOMAIN, exports.DASHBOARD_FQDN),
|
|
|
|
|
settings.initCache,
|
|
|
|
|
blobs.initSecrets,
|
|
|
|
|
domains.add.bind(null, DOMAIN.domain, DOMAIN, AUDIT_SOURCE),
|
2021-07-19 12:43:30 -07:00
|
|
|
], done);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setup(done) {
|
|
|
|
|
async.series([
|
|
|
|
|
domainSetup,
|
2021-07-15 09:50:11 -07:00
|
|
|
async function createOwner() {
|
|
|
|
|
const result = await users.createOwner(ADMIN.email, ADMIN.username, ADMIN.password, ADMIN.displayName, AUDIT_SOURCE);
|
|
|
|
|
ADMIN.id = result.id;
|
2021-06-25 22:11:17 -07:00
|
|
|
},
|
2021-06-03 12:20:44 -07:00
|
|
|
appdb.add.bind(null, APP.id, APP.appStoreId, APP.manifest, APP.location, APP.domain, APP.portBindings, APP),
|
|
|
|
|
settingsdb.set.bind(null, settings.CLOUDRON_TOKEN_KEY, exports.APPSTORE_TOKEN), // appstore token
|
2021-07-15 09:50:11 -07:00
|
|
|
async function createUser() {
|
|
|
|
|
const result = await users.add(USER.email, USER, AUDIT_SOURCE);
|
|
|
|
|
USER.id = result.id;
|
|
|
|
|
},
|
2021-07-07 12:59:17 -07:00
|
|
|
(done) => mailboxdb.addMailbox(exports.MAILBOX_NAME, DOMAIN.domain, { ownerId: USER.id, ownerType: mail.OWNERTYPE_USER, active: true }, done),
|
|
|
|
|
(done) => mailboxdb.setAliasesForName(exports.MAILBOX_NAME, DOMAIN.domain, [ { name: exports.ALIAS_NAME, domain: DOMAIN.domain} ], done),
|
|
|
|
|
|
2021-07-14 19:03:12 -07:00
|
|
|
tasks.stopAllTasks,
|
2021-06-03 12:20:44 -07:00
|
|
|
], done);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cleanup(done) {
|
|
|
|
|
nock.cleanAll();
|
|
|
|
|
mailer._mailQueue = [];
|
|
|
|
|
|
|
|
|
|
async.series([
|
|
|
|
|
database._clear,
|
|
|
|
|
database.uninitialize
|
|
|
|
|
], done);
|
|
|
|
|
}
|
2021-07-19 12:43:30 -07:00
|
|
|
|