|
|
@ -7,15 +7,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
require('../../require-main');
|
|
|
|
require('../../require-main');
|
|
|
|
|
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
const path = require('path');
|
|
|
|
var path = require('path');
|
|
|
|
const nconf = require('nconf');
|
|
|
|
var nconf = require('nconf');
|
|
|
|
const url = require('url');
|
|
|
|
var url = require('url');
|
|
|
|
const util = require('util');
|
|
|
|
|
|
|
|
|
|
|
|
global.env = process.env.TEST_ENV || 'production';
|
|
|
|
global.env = process.env.TEST_ENV || 'production';
|
|
|
|
|
|
|
|
|
|
|
|
var winston = require('winston');
|
|
|
|
const winston = require('winston');
|
|
|
|
var packageInfo = require('../../package');
|
|
|
|
const packageInfo = require('../../package');
|
|
|
|
|
|
|
|
|
|
|
|
winston.add(new winston.transports.Console({
|
|
|
|
winston.add(new winston.transports.Console({
|
|
|
|
format: winston.format.combine(
|
|
|
|
format: winston.format.combine(
|
|
|
@ -33,8 +33,8 @@ nconf.defaults({
|
|
|
|
relative_path: '',
|
|
|
|
relative_path: '',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var urlObject = url.parse(nconf.get('url'));
|
|
|
|
const urlObject = url.parse(nconf.get('url'));
|
|
|
|
var relativePath = urlObject.pathname !== '/' ? urlObject.pathname : '';
|
|
|
|
const relativePath = urlObject.pathname !== '/' ? urlObject.pathname : '';
|
|
|
|
nconf.set('relative_path', relativePath);
|
|
|
|
nconf.set('relative_path', relativePath);
|
|
|
|
|
|
|
|
|
|
|
|
if (!nconf.get('isCluster')) {
|
|
|
|
if (!nconf.get('isCluster')) {
|
|
|
@ -42,9 +42,9 @@ if (!nconf.get('isCluster')) {
|
|
|
|
nconf.set('isCluster', 'true');
|
|
|
|
nconf.set('isCluster', 'true');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var dbType = nconf.get('database');
|
|
|
|
const dbType = nconf.get('database');
|
|
|
|
var testDbConfig = nconf.get('test_database');
|
|
|
|
const testDbConfig = nconf.get('test_database');
|
|
|
|
var productionDbConfig = nconf.get(dbType);
|
|
|
|
const productionDbConfig = nconf.get(dbType);
|
|
|
|
|
|
|
|
|
|
|
|
if (!testDbConfig) {
|
|
|
|
if (!testDbConfig) {
|
|
|
|
const errorText = 'test_database is not defined';
|
|
|
|
const errorText = 'test_database is not defined';
|
|
|
@ -100,161 +100,127 @@ nconf.set(dbType, testDbConfig);
|
|
|
|
winston.info('database config %s', dbType, testDbConfig);
|
|
|
|
winston.info('database config %s', dbType, testDbConfig);
|
|
|
|
winston.info('environment ' + global.env);
|
|
|
|
winston.info('environment ' + global.env);
|
|
|
|
|
|
|
|
|
|
|
|
var db = require('../../src/database');
|
|
|
|
const db = require('../../src/database');
|
|
|
|
module.exports = db;
|
|
|
|
module.exports = db;
|
|
|
|
|
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000);
|
|
|
|
this.timeout(30000);
|
|
|
|
async.series([
|
|
|
|
await db.init();
|
|
|
|
function (next) {
|
|
|
|
await db.createIndices();
|
|
|
|
db.init(next);
|
|
|
|
await setupMockDefaults();
|
|
|
|
},
|
|
|
|
await db.initSessionStore();
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
db.createIndices(next);
|
|
|
|
const meta = require('../../src/meta');
|
|
|
|
},
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
// nconf defaults, if not set in config
|
|
|
|
setupMockDefaults(next);
|
|
|
|
if (!nconf.get('sessionKey')) {
|
|
|
|
},
|
|
|
|
nconf.set('sessionKey', 'express.sid');
|
|
|
|
function (next) {
|
|
|
|
}
|
|
|
|
db.initSessionStore(next);
|
|
|
|
// Parse out the relative_url and other goodies from the configured URL
|
|
|
|
},
|
|
|
|
const urlObject = url.parse(nconf.get('url'));
|
|
|
|
function (next) {
|
|
|
|
const relativePath = urlObject.pathname !== '/' ? urlObject.pathname : '';
|
|
|
|
var meta = require('../../src/meta');
|
|
|
|
nconf.set('base_url', urlObject.protocol + '//' + urlObject.host);
|
|
|
|
|
|
|
|
nconf.set('secure', urlObject.protocol === 'https:');
|
|
|
|
// nconf defaults, if not set in config
|
|
|
|
nconf.set('use_port', !!urlObject.port);
|
|
|
|
if (!nconf.get('sessionKey')) {
|
|
|
|
nconf.set('relative_path', relativePath);
|
|
|
|
nconf.set('sessionKey', 'express.sid');
|
|
|
|
nconf.set('port', urlObject.port || nconf.get('port') || (nconf.get('PORT_ENV_VAR') ? nconf.get(nconf.get('PORT_ENV_VAR')) : false) || 4567);
|
|
|
|
}
|
|
|
|
nconf.set('upload_path', path.join(nconf.get('base_dir'), nconf.get('upload_path')));
|
|
|
|
// Parse out the relative_url and other goodies from the configured URL
|
|
|
|
nconf.set('upload_url', '/assets/uploads');
|
|
|
|
var urlObject = url.parse(nconf.get('url'));
|
|
|
|
|
|
|
|
var relativePath = urlObject.pathname !== '/' ? urlObject.pathname : '';
|
|
|
|
nconf.set('core_templates_path', path.join(__dirname, '../../src/views'));
|
|
|
|
nconf.set('base_url', urlObject.protocol + '//' + urlObject.host);
|
|
|
|
nconf.set('base_templates_path', path.join(nconf.get('themes_path'), 'nodebb-theme-persona/templates'));
|
|
|
|
nconf.set('secure', urlObject.protocol === 'https:');
|
|
|
|
nconf.set('theme_templates_path', meta.config['theme:templates'] ? path.join(nconf.get('themes_path'), meta.config['theme:id'], meta.config['theme:templates']) : nconf.get('base_templates_path'));
|
|
|
|
nconf.set('use_port', !!urlObject.port);
|
|
|
|
nconf.set('theme_config', path.join(nconf.get('themes_path'), 'nodebb-theme-persona', 'theme.json'));
|
|
|
|
nconf.set('relative_path', relativePath);
|
|
|
|
nconf.set('bcrypt_rounds', 1);
|
|
|
|
nconf.set('port', urlObject.port || nconf.get('port') || (nconf.get('PORT_ENV_VAR') ? nconf.get(nconf.get('PORT_ENV_VAR')) : false) || 4567);
|
|
|
|
|
|
|
|
nconf.set('upload_path', path.join(nconf.get('base_dir'), nconf.get('upload_path')));
|
|
|
|
nconf.set('version', packageInfo.version);
|
|
|
|
nconf.set('upload_url', '/assets/uploads');
|
|
|
|
|
|
|
|
|
|
|
|
await meta.dependencies.check();
|
|
|
|
nconf.set('core_templates_path', path.join(__dirname, '../../src/views'));
|
|
|
|
|
|
|
|
nconf.set('base_templates_path', path.join(nconf.get('themes_path'), 'nodebb-theme-persona/templates'));
|
|
|
|
const webserver = require('../../src/webserver');
|
|
|
|
nconf.set('theme_templates_path', meta.config['theme:templates'] ? path.join(nconf.get('themes_path'), meta.config['theme:id'], meta.config['theme:templates']) : nconf.get('base_templates_path'));
|
|
|
|
const sockets = require('../../src/socket.io');
|
|
|
|
nconf.set('theme_config', path.join(nconf.get('themes_path'), 'nodebb-theme-persona', 'theme.json'));
|
|
|
|
sockets.init(webserver.server);
|
|
|
|
nconf.set('bcrypt_rounds', 1);
|
|
|
|
|
|
|
|
|
|
|
|
require('../../src/notifications').startJobs();
|
|
|
|
nconf.set('version', packageInfo.version);
|
|
|
|
require('../../src/user').startJobs();
|
|
|
|
|
|
|
|
|
|
|
|
meta.dependencies.check(next);
|
|
|
|
await webserver.listen();
|
|
|
|
},
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
var webserver = require('../../src/webserver');
|
|
|
|
|
|
|
|
var sockets = require('../../src/socket.io');
|
|
|
|
|
|
|
|
sockets.init(webserver.server);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require('../../src/notifications').startJobs();
|
|
|
|
|
|
|
|
require('../../src/user').startJobs();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
webserver.listen(next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
], done);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Iterate over all of the test suites/contexts
|
|
|
|
// Iterate over all of the test suites/contexts
|
|
|
|
this.test.parent.suites.forEach(function (suite) {
|
|
|
|
this.test.parent.suites.forEach(function (suite) {
|
|
|
|
// Attach an afterAll listener that resets the defaults
|
|
|
|
// Attach an afterAll listener that resets the defaults
|
|
|
|
suite.afterAll(function (done) {
|
|
|
|
suite.afterAll(async function () {
|
|
|
|
setupMockDefaults(done);
|
|
|
|
await setupMockDefaults();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function setupMockDefaults(callback) {
|
|
|
|
async function setupMockDefaults() {
|
|
|
|
var meta = require('../../src/meta');
|
|
|
|
const meta = require('../../src/meta');
|
|
|
|
|
|
|
|
await db.emptydb();
|
|
|
|
async.series([
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
require('../../src/groups').resetCache();
|
|
|
|
db.emptydb(next);
|
|
|
|
require('../../src/posts/cache').reset();
|
|
|
|
},
|
|
|
|
require('../../src/cache').reset();
|
|
|
|
function (next) {
|
|
|
|
winston.info('test_database flushed');
|
|
|
|
var groups = require('../../src/groups');
|
|
|
|
await setupDefaultConfigs(meta);
|
|
|
|
groups.resetCache();
|
|
|
|
await giveDefaultGlobalPrivileges();
|
|
|
|
var postCache = require('../../src/posts/cache');
|
|
|
|
await meta.configs.init();
|
|
|
|
postCache.reset();
|
|
|
|
meta.config.postDelay = 0;
|
|
|
|
var localCache = require('../../src/cache');
|
|
|
|
meta.config.initialPostDelay = 0;
|
|
|
|
localCache.reset();
|
|
|
|
meta.config.newbiePostDelay = 0;
|
|
|
|
next();
|
|
|
|
|
|
|
|
},
|
|
|
|
await enableDefaultPlugins();
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
winston.info('test_database flushed');
|
|
|
|
await meta.themes.set({
|
|
|
|
setupDefaultConfigs(meta, next);
|
|
|
|
type: 'local',
|
|
|
|
},
|
|
|
|
id: 'nodebb-theme-persona',
|
|
|
|
function (next) {
|
|
|
|
});
|
|
|
|
giveDefaultGlobalPrivileges(next);
|
|
|
|
|
|
|
|
},
|
|
|
|
const rimraf = util.promisify(require('rimraf'));
|
|
|
|
function (next) {
|
|
|
|
await rimraf('test/uploads');
|
|
|
|
meta.configs.init(next);
|
|
|
|
|
|
|
|
},
|
|
|
|
const mkdirp = util.promisify(require('mkdirp'));
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
meta.config.postDelay = 0;
|
|
|
|
const folders = [
|
|
|
|
meta.config.initialPostDelay = 0;
|
|
|
|
'test/uploads',
|
|
|
|
meta.config.newbiePostDelay = 0;
|
|
|
|
'test/uploads/category',
|
|
|
|
|
|
|
|
'test/uploads/files',
|
|
|
|
enableDefaultPlugins(next);
|
|
|
|
'test/uploads/system',
|
|
|
|
},
|
|
|
|
'test/uploads/sounds',
|
|
|
|
function (next) {
|
|
|
|
'test/uploads/profile',
|
|
|
|
meta.themes.set({
|
|
|
|
];
|
|
|
|
type: 'local',
|
|
|
|
for (const folder of folders) {
|
|
|
|
id: 'nodebb-theme-persona',
|
|
|
|
/* eslint-disable no-await-in-loop */
|
|
|
|
}, next);
|
|
|
|
await mkdirp(folder);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
var rimraf = require('rimraf');
|
|
|
|
|
|
|
|
rimraf('test/uploads', next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
var mkdirp = require('mkdirp');
|
|
|
|
|
|
|
|
async.eachSeries([
|
|
|
|
|
|
|
|
'test/uploads',
|
|
|
|
|
|
|
|
'test/uploads/category',
|
|
|
|
|
|
|
|
'test/uploads/files',
|
|
|
|
|
|
|
|
'test/uploads/system',
|
|
|
|
|
|
|
|
'test/uploads/sounds',
|
|
|
|
|
|
|
|
'test/uploads/profile',
|
|
|
|
|
|
|
|
], mkdirp, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
], callback);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
db.setupMockDefaults = setupMockDefaults;
|
|
|
|
db.setupMockDefaults = setupMockDefaults;
|
|
|
|
|
|
|
|
|
|
|
|
function setupDefaultConfigs(meta, next) {
|
|
|
|
async function setupDefaultConfigs(meta) {
|
|
|
|
winston.info('Populating database with default configs, if not already set...\n');
|
|
|
|
winston.info('Populating database with default configs, if not already set...\n');
|
|
|
|
|
|
|
|
|
|
|
|
var defaults = require(path.join(nconf.get('base_dir'), 'install/data/defaults.json'));
|
|
|
|
const defaults = require(path.join(nconf.get('base_dir'), 'install/data/defaults.json'));
|
|
|
|
defaults.eventLoopCheckEnabled = 0;
|
|
|
|
defaults.eventLoopCheckEnabled = 0;
|
|
|
|
defaults.minimumPasswordStrength = 0;
|
|
|
|
defaults.minimumPasswordStrength = 0;
|
|
|
|
meta.configs.setOnEmpty(defaults, next);
|
|
|
|
await meta.configs.setOnEmpty(defaults);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function giveDefaultGlobalPrivileges(next) {
|
|
|
|
async function giveDefaultGlobalPrivileges() {
|
|
|
|
var privileges = require('../../src/privileges');
|
|
|
|
const privileges = require('../../src/privileges');
|
|
|
|
async.waterfall([
|
|
|
|
await privileges.global.give([
|
|
|
|
function (next) {
|
|
|
|
'chat', 'upload:post:image', 'signature', 'search:content',
|
|
|
|
privileges.global.give([
|
|
|
|
'search:users', 'search:tags', 'local:login', 'view:users', 'view:tags', 'view:groups',
|
|
|
|
'chat', 'upload:post:image', 'signature', 'search:content',
|
|
|
|
], 'registered-users');
|
|
|
|
'search:users', 'search:tags', 'local:login', 'view:users', 'view:tags', 'view:groups',
|
|
|
|
await privileges.global.give([
|
|
|
|
], 'registered-users', next);
|
|
|
|
'view:users', 'view:tags', 'view:groups',
|
|
|
|
},
|
|
|
|
], 'guests');
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
privileges.global.give([
|
|
|
|
|
|
|
|
'view:users', 'view:tags', 'view:groups',
|
|
|
|
|
|
|
|
], 'guests', next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
], next);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function enableDefaultPlugins(callback) {
|
|
|
|
async function enableDefaultPlugins() {
|
|
|
|
winston.info('Enabling default plugins\n');
|
|
|
|
winston.info('Enabling default plugins\n');
|
|
|
|
|
|
|
|
|
|
|
|
var defaultEnabled = [
|
|
|
|
const defaultEnabled = [
|
|
|
|
'nodebb-plugin-dbsearch',
|
|
|
|
'nodebb-plugin-dbsearch',
|
|
|
|
'nodebb-plugin-soundpack-default',
|
|
|
|
'nodebb-plugin-soundpack-default',
|
|
|
|
'nodebb-widget-essentials',
|
|
|
|
'nodebb-widget-essentials',
|
|
|
@ -262,9 +228,5 @@ function enableDefaultPlugins(callback) {
|
|
|
|
|
|
|
|
|
|
|
|
winston.info('[install/enableDefaultPlugins] activating default plugins', defaultEnabled);
|
|
|
|
winston.info('[install/enableDefaultPlugins] activating default plugins', defaultEnabled);
|
|
|
|
|
|
|
|
|
|
|
|
db.sortedSetAdd('plugins:active', Object.keys(defaultEnabled), defaultEnabled, callback);
|
|
|
|
await db.sortedSetAdd('plugins:active', Object.keys(defaultEnabled), defaultEnabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.activatePlugin = function (id, callback) {
|
|
|
|
|
|
|
|
db.sortedSetAdd('plugins:active', Date.now(), id, callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|