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'),
|
|
|
|
|
database = require('../database.js'),
|
|
|
|
|
domains = require('../domains.js'),
|
|
|
|
|
fs = require('fs'),
|
|
|
|
|
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'),
|
|
|
|
|
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',
|
|
|
|
|
provider: 'route53',
|
|
|
|
|
config: {
|
|
|
|
|
accessKeyId: 'accessKeyId',
|
|
|
|
|
secretAccessKey: 'secretAccessKey',
|
|
|
|
|
endpoint: 'http://localhost:5353'
|
|
|
|
|
},
|
|
|
|
|
fallbackCertificate: null,
|
|
|
|
|
tlsConfig: { provider: 'letsencrypt-staging' },
|
|
|
|
|
wellKnown: null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const AUDIT_SOURCE = { ip: '1.2.3.4' };
|
|
|
|
|
|
|
|
|
|
const ADMIN = {
|
|
|
|
|
id: 'admin123',
|
|
|
|
|
username: 'admin123',
|
|
|
|
|
password: 'secret123',
|
|
|
|
|
email: 'admin@me.com',
|
|
|
|
|
fallbackEmail: 'admin@me.com',
|
|
|
|
|
salt: 'morton',
|
|
|
|
|
createdAt: 'sometime back',
|
|
|
|
|
resetToken: '',
|
|
|
|
|
displayName: '',
|
|
|
|
|
role: 'owner',
|
|
|
|
|
source: ''
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
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,
|
|
|
|
|
APPSTORE_TOKEN: 'atoken'
|
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-06-03 12:20:44 -07:00
|
|
|
function setup(done) {
|
|
|
|
|
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),
|
|
|
|
|
users.createOwner.bind(null, ADMIN.username, ADMIN.password, ADMIN.email, ADMIN.displayName, AUDIT_SOURCE),
|
|
|
|
|
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
|
|
|
|
|
], done);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cleanup(done) {
|
|
|
|
|
nock.cleanAll();
|
|
|
|
|
mailer._mailQueue = [];
|
|
|
|
|
|
|
|
|
|
async.series([
|
|
|
|
|
database._clear,
|
|
|
|
|
database.uninitialize
|
|
|
|
|
], done);
|
|
|
|
|
}
|