2013-12-28 21:53:05 +04:00
|
|
|
var should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
2014-08-17 10:17:23 +04:00
|
|
|
Promise = require('bluebird'),
|
2016-06-20 15:47:53 +03:00
|
|
|
moment = require('moment'),
|
2013-12-28 21:53:05 +04:00
|
|
|
path = require('path'),
|
2014-08-23 20:19:13 +04:00
|
|
|
fs = require('fs'),
|
2014-02-05 12:40:30 +04:00
|
|
|
_ = require('lodash'),
|
2013-12-28 21:53:05 +04:00
|
|
|
|
2014-01-03 04:37:21 +04:00
|
|
|
testUtils = require('../utils'),
|
2016-06-10 11:59:38 +03:00
|
|
|
i18n = require('../../server/i18n'),
|
2016-09-09 13:23:47 +03:00
|
|
|
utils = require('../../server/utils'),
|
2016-06-10 11:59:38 +03:00
|
|
|
/*jshint unused:false*/
|
|
|
|
db = require('../../server/data/db/connection'),
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2013-12-28 21:53:05 +04:00
|
|
|
// Thing we are testing
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils = require('../utils/configUtils'),
|
|
|
|
config = configUtils.config,
|
2014-09-20 22:14:16 +04:00
|
|
|
// storing current environment
|
|
|
|
currentEnv = process.env.NODE_ENV;
|
2016-06-10 11:59:38 +03:00
|
|
|
|
2015-11-12 15:29:45 +03:00
|
|
|
i18n.init();
|
2014-06-05 01:26:03 +04:00
|
|
|
|
2013-12-26 16:15:10 +04:00
|
|
|
describe('Config', function () {
|
2016-04-13 19:10:40 +03:00
|
|
|
before(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
});
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
2014-12-14 14:31:00 +03:00
|
|
|
});
|
|
|
|
|
2013-12-26 16:15:10 +04:00
|
|
|
describe('Theme', function () {
|
2014-09-03 07:15:15 +04:00
|
|
|
beforeEach(function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({
|
2014-09-03 07:15:15 +04:00
|
|
|
url: 'http://my-ghost-blog.com',
|
|
|
|
theme: {
|
|
|
|
title: 'casper',
|
|
|
|
description: 'casper',
|
|
|
|
logo: 'casper',
|
2016-08-22 18:56:35 +03:00
|
|
|
cover: 'casper',
|
|
|
|
timezone: 'Etc/UTC'
|
2014-09-03 07:15:15 +04:00
|
|
|
}
|
2013-12-26 16:15:10 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-28 20:01:08 +04:00
|
|
|
it('should have exactly the right keys', function () {
|
2014-09-03 07:15:15 +04:00
|
|
|
var themeConfig = config.theme;
|
2013-12-26 16:15:10 +04:00
|
|
|
|
|
|
|
// This will fail if there are any extra keys
|
2016-06-13 14:21:30 +03:00
|
|
|
themeConfig.should.have.keys('url', 'title', 'description', 'logo', 'cover', 'timezone');
|
2013-12-28 20:01:08 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should have the correct values for each key', function () {
|
2014-09-03 07:15:15 +04:00
|
|
|
var themeConfig = config.theme;
|
2013-12-26 16:15:10 +04:00
|
|
|
|
|
|
|
// Check values are as we expect
|
|
|
|
themeConfig.should.have.property('url', 'http://my-ghost-blog.com');
|
|
|
|
themeConfig.should.have.property('title', 'casper');
|
|
|
|
themeConfig.should.have.property('description', 'casper');
|
|
|
|
themeConfig.should.have.property('logo', 'casper');
|
|
|
|
themeConfig.should.have.property('cover', 'casper');
|
2016-08-22 18:56:35 +03:00
|
|
|
themeConfig.should.have.property('timezone', 'Etc/UTC');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Timezone default', function () {
|
|
|
|
it('should use timezone from settings when set', function () {
|
|
|
|
var themeConfig = config.theme;
|
|
|
|
|
|
|
|
// Check values are as we expect
|
|
|
|
themeConfig.should.have.property('timezone', 'Etc/UTC');
|
|
|
|
themeConfig.should.have.property('url');
|
|
|
|
|
|
|
|
configUtils.set({
|
|
|
|
theme: {
|
|
|
|
timezone: 'Africa/Cairo'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
config.theme.should.have.property('timezone', 'Africa/Cairo');
|
|
|
|
config.theme.should.have.property('url');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set theme object with timezone by default', function () {
|
|
|
|
var themeConfig = configUtils.defaultConfig;
|
|
|
|
|
|
|
|
// Check values are as we expect
|
|
|
|
themeConfig.should.have.property('theme');
|
|
|
|
themeConfig.theme.should.have.property('timezone', 'Etc/UTC');
|
|
|
|
themeConfig.theme.should.have.property('url');
|
2013-12-26 16:15:10 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-05 10:40:53 +04:00
|
|
|
describe('Index', function () {
|
2013-12-28 20:01:08 +04:00
|
|
|
it('should have exactly the right keys', function () {
|
2014-07-17 18:33:21 +04:00
|
|
|
var pathConfig = config.paths;
|
2013-12-28 20:01:08 +04:00
|
|
|
|
|
|
|
// This will fail if there are any extra keys
|
|
|
|
pathConfig.should.have.keys(
|
|
|
|
'appRoot',
|
|
|
|
'config',
|
|
|
|
'configExample',
|
2016-08-22 20:55:28 +03:00
|
|
|
'storagePath',
|
2013-12-28 20:01:08 +04:00
|
|
|
'contentPath',
|
|
|
|
'corePath',
|
|
|
|
'themePath',
|
2014-01-21 12:45:27 +04:00
|
|
|
'appPath',
|
2016-04-14 20:32:43 +03:00
|
|
|
'internalAppPath',
|
2013-12-28 20:01:08 +04:00
|
|
|
'imagesPath',
|
|
|
|
'imagesRelPath',
|
|
|
|
'adminViews',
|
|
|
|
'helperTemplates',
|
2015-03-08 20:09:57 +03:00
|
|
|
'clientAssets'
|
2013-12-28 20:01:08 +04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have the correct values for each key', function () {
|
2014-07-17 18:33:21 +04:00
|
|
|
var pathConfig = config.paths,
|
2013-12-28 20:01:08 +04:00
|
|
|
appRoot = path.resolve(__dirname, '../../../');
|
|
|
|
|
|
|
|
pathConfig.should.have.property('appRoot', appRoot);
|
2016-01-11 14:37:59 +03:00
|
|
|
});
|
|
|
|
|
2014-02-08 19:41:15 +04:00
|
|
|
it('should allow specific properties to be user defined', function () {
|
2014-07-17 18:33:21 +04:00
|
|
|
var contentPath = path.join(config.paths.appRoot, 'otherContent', '/'),
|
2014-02-08 19:41:15 +04:00
|
|
|
configFile = 'configFileDanceParty.js';
|
2014-01-05 10:40:53 +04:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({
|
2014-02-08 19:41:15 +04:00
|
|
|
config: configFile,
|
2014-01-05 10:40:53 +04:00
|
|
|
paths: {
|
|
|
|
contentPath: contentPath
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-17 18:33:21 +04:00
|
|
|
config.should.have.property('config', configFile);
|
|
|
|
config.paths.should.have.property('contentPath', contentPath);
|
|
|
|
config.paths.should.have.property('themePath', contentPath + 'themes');
|
|
|
|
config.paths.should.have.property('appPath', contentPath + 'apps');
|
|
|
|
config.paths.should.have.property('imagesPath', contentPath + 'images');
|
2013-12-28 20:01:08 +04:00
|
|
|
});
|
|
|
|
});
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-01-18 06:54:56 +03:00
|
|
|
describe('Storage', function () {
|
|
|
|
it('should default to local-file-store', function () {
|
2016-08-22 20:55:28 +03:00
|
|
|
config.paths.should.have.property('storagePath', {
|
|
|
|
default: path.join(config.paths.corePath, '/server/storage/'),
|
|
|
|
custom: path.join(config.paths.contentPath, 'storage/')
|
|
|
|
});
|
2015-01-18 06:54:56 +03:00
|
|
|
|
2016-08-22 20:55:28 +03:00
|
|
|
config.storage.should.have.property('active', {
|
|
|
|
images: 'local-file-store',
|
|
|
|
themes: 'local-file-store'
|
|
|
|
});
|
2015-01-18 06:54:56 +03:00
|
|
|
});
|
|
|
|
|
2016-08-22 20:55:28 +03:00
|
|
|
it('should allow setting a custom active storage as string', function () {
|
2015-01-18 06:54:56 +03:00
|
|
|
var storagePath = path.join(config.paths.contentPath, 'storage', 's3');
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({
|
2015-01-18 06:54:56 +03:00
|
|
|
storage: {
|
|
|
|
active: 's3',
|
|
|
|
s3: {}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-22 20:55:28 +03:00
|
|
|
config.storage.should.have.property('active', {
|
|
|
|
images: 's3',
|
|
|
|
themes: 'local-file-store'
|
|
|
|
});
|
|
|
|
|
2015-01-18 06:54:56 +03:00
|
|
|
config.storage.should.have.property('s3', {});
|
|
|
|
});
|
2016-08-22 20:55:28 +03:00
|
|
|
|
2016-08-23 15:07:25 +03:00
|
|
|
it('should use default theme adapter when passing an object', function () {
|
2016-08-22 20:55:28 +03:00
|
|
|
var storagePath = path.join(config.paths.contentPath, 'storage', 's3');
|
|
|
|
|
|
|
|
configUtils.set({
|
|
|
|
storage: {
|
|
|
|
active: {
|
|
|
|
themes: 's3'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
config.storage.should.have.property('active', {
|
|
|
|
images: 'local-file-store',
|
2016-08-23 15:07:25 +03:00
|
|
|
themes: 'local-file-store'
|
2016-08-22 20:55:28 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow setting a custom active storage as object', function () {
|
|
|
|
var storagePath = path.join(config.paths.contentPath, 'storage', 's3');
|
|
|
|
|
|
|
|
configUtils.set({
|
|
|
|
storage: {
|
|
|
|
active: {
|
|
|
|
images: 's2',
|
2016-08-23 15:07:25 +03:00
|
|
|
themes: 'local-file-store'
|
2016-08-22 20:55:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
config.storage.should.have.property('active', {
|
|
|
|
images: 's2',
|
2016-08-23 15:07:25 +03:00
|
|
|
themes: 'local-file-store'
|
2016-08-22 20:55:28 +03:00
|
|
|
});
|
|
|
|
});
|
2015-01-18 06:54:56 +03:00
|
|
|
});
|
|
|
|
|
2014-08-23 20:19:13 +04:00
|
|
|
describe('File', function () {
|
|
|
|
var sandbox,
|
|
|
|
readFileStub,
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig,
|
2014-08-23 20:19:13 +04:00
|
|
|
expectedError = new Error('expected bootstrap() to throw error but none thrown');
|
|
|
|
|
|
|
|
before(function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
// Create a function to override what reading the config file returns
|
|
|
|
overrideReadFileConfig = function (newConfig) {
|
|
|
|
readFileStub.returns(
|
|
|
|
_.extend({}, configUtils.defaultConfig, newConfig)
|
|
|
|
);
|
|
|
|
};
|
2014-08-23 20:19:13 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
readFileStub = sandbox.stub(config, 'readFile');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the config file if one exists', function (done) {
|
|
|
|
// We actually want the real method here.
|
|
|
|
readFileStub.restore();
|
|
|
|
|
|
|
|
// the test infrastructure is setup so that there is always config present,
|
|
|
|
// but we want to overwrite the test to actually load config.example.js, so that any local changes
|
|
|
|
// don't break the tests
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({
|
2014-08-23 20:19:13 +04:00
|
|
|
paths: {
|
2015-12-14 23:05:11 +03:00
|
|
|
appRoot: path.join(configUtils.defaultConfig.paths.appRoot, 'config.example.js')
|
2014-08-23 20:19:13 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
config.load().then(function (config) {
|
2015-12-14 23:05:11 +03:00
|
|
|
config.url.should.equal(configUtils.defaultConfig.url);
|
|
|
|
config.database.client.should.equal(configUtils.defaultConfig.database.client);
|
2016-06-10 11:59:38 +03:00
|
|
|
|
|
|
|
if (config.database.client === 'sqlite3') {
|
|
|
|
config.database.connection.filename.should.eql(configUtils.defaultConfig.database.connection.filename);
|
|
|
|
} else {
|
|
|
|
config.database.connection.charset.should.eql(configUtils.defaultConfig.database.connection.charset);
|
|
|
|
config.database.connection.database.should.eql(configUtils.defaultConfig.database.connection.database);
|
|
|
|
config.database.connection.host.should.eql(configUtils.defaultConfig.database.connection.host);
|
|
|
|
config.database.connection.password.should.eql(configUtils.defaultConfig.database.connection.password);
|
|
|
|
config.database.connection.user.should.eql(configUtils.defaultConfig.database.connection.user);
|
|
|
|
}
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
config.server.host.should.equal(configUtils.defaultConfig.server.host);
|
|
|
|
config.server.port.should.equal(configUtils.defaultConfig.server.port);
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uses the passed in config file location', function (done) {
|
|
|
|
// We actually want the real method here.
|
|
|
|
readFileStub.restore();
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
config.load(path.join(configUtils.defaultConfig.paths.appRoot, 'config.example.js')).then(function (config) {
|
|
|
|
config.url.should.equal(configUtils.defaultConfig.url);
|
|
|
|
config.database.client.should.equal(configUtils.defaultConfig.database.client);
|
2016-06-10 11:59:38 +03:00
|
|
|
|
|
|
|
if (config.database.client === 'sqlite3') {
|
|
|
|
config.database.connection.filename.should.eql(configUtils.defaultConfig.database.connection.filename);
|
|
|
|
} else {
|
|
|
|
config.database.connection.charset.should.eql(configUtils.defaultConfig.database.connection.charset);
|
|
|
|
config.database.connection.database.should.eql(configUtils.defaultConfig.database.connection.database);
|
|
|
|
config.database.connection.host.should.eql(configUtils.defaultConfig.database.connection.host);
|
|
|
|
config.database.connection.password.should.eql(configUtils.defaultConfig.database.connection.password);
|
|
|
|
config.database.connection.user.should.eql(configUtils.defaultConfig.database.connection.user);
|
|
|
|
}
|
2015-12-14 23:05:11 +03:00
|
|
|
config.server.host.should.equal(configUtils.defaultConfig.server.host);
|
|
|
|
config.server.port.should.equal(configUtils.defaultConfig.server.port);
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates the config file if one does not exist', function (done) {
|
2015-05-01 00:14:19 +03:00
|
|
|
// trick bootstrap into thinking that the config file doesn't exist yet
|
2015-03-12 23:12:56 +03:00
|
|
|
var existsStub = sandbox.stub(fs, 'stat', function (file, cb) { return cb(true); }),
|
2014-08-23 20:19:13 +04:00
|
|
|
// ensure that the file creation is a stub, the tests shouldn't really create a file
|
|
|
|
writeFileStub = sandbox.stub(config, 'writeFile').returns(Promise.resolve()),
|
|
|
|
validateStub = sandbox.stub(config, 'validate').returns(Promise.resolve());
|
|
|
|
|
|
|
|
config.load().then(function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
existsStub.calledOnce.should.be.true();
|
|
|
|
writeFileStub.calledOnce.should.be.true();
|
|
|
|
validateStub.calledOnce.should.be.true();
|
2014-08-23 20:19:13 +04:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('accepts urls with a valid scheme', function (done) {
|
|
|
|
// replace the config file with invalid data
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({url: 'http://testurl.com'});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function (localConfig) {
|
|
|
|
localConfig.url.should.equal('http://testurl.com');
|
|
|
|
|
|
|
|
// Next test
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({url: 'https://testurl.com'});
|
2014-08-23 20:19:13 +04:00
|
|
|
return config.load();
|
|
|
|
}).then(function (localConfig) {
|
|
|
|
localConfig.url.should.equal('https://testurl.com');
|
|
|
|
|
2015-05-01 00:14:19 +03:00
|
|
|
// Next test
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({url: 'http://testurl.com/blog/'});
|
2014-08-23 20:19:13 +04:00
|
|
|
return config.load();
|
|
|
|
}).then(function (localConfig) {
|
|
|
|
localConfig.url.should.equal('http://testurl.com/blog/');
|
|
|
|
|
2015-05-01 00:14:19 +03:00
|
|
|
// Next test
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({url: 'http://testurl.com/ghostly/'});
|
2014-08-23 20:19:13 +04:00
|
|
|
return config.load();
|
|
|
|
}).then(function (localConfig) {
|
|
|
|
localConfig.url.should.equal('http://testurl.com/ghostly/');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('rejects a fqdn without a scheme', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({url: 'example.com'});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('rejects a hostname without a scheme', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({url: 'example'});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('rejects a hostname with a scheme', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({url: 'https://example'});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('rejects a url with an unsupported scheme', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({url: 'ftp://example.com'});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('rejects a url with a protocol relative scheme', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({url: '//example.com'});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not permit the word ghost as a url path', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({url: 'http://example.com/ghost/'});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not permit the word ghost to be a component in a url path', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({url: 'http://example.com/blog/ghost/'});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not permit the word ghost to be a component in a url path', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({url: 'http://example.com/ghost/blog/'});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not permit database config to be falsy', function (done) {
|
|
|
|
// replace the config file with invalid data
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({database: false});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not permit database config to be empty', function (done) {
|
|
|
|
// replace the config file with invalid data
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({database: {}});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('requires server to be present', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({server: false});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function (localConfig) {
|
|
|
|
/*jshint unused:false*/
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('allows server to use a socket', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({server: {socket: 'test'}});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
2014-12-31 18:23:46 +03:00
|
|
|
config.load().then(function () {
|
|
|
|
var socketConfig = config.getSocket();
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
socketConfig.should.be.an.Object();
|
2014-12-31 18:23:46 +03:00
|
|
|
socketConfig.path.should.equal('test');
|
|
|
|
socketConfig.permissions.should.equal('660');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('allows server to use a socket and user-defined permissions', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({
|
2014-12-31 18:23:46 +03:00
|
|
|
server: {
|
|
|
|
socket: {
|
|
|
|
path: 'test',
|
|
|
|
permissions: '666'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
var socketConfig = config.getSocket();
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
socketConfig.should.be.an.Object();
|
2014-12-31 18:23:46 +03:00
|
|
|
socketConfig.path.should.equal('test');
|
|
|
|
socketConfig.permissions.should.equal('666');
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('allows server to have a host and a port', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({server: {host: '127.0.0.1', port: '2368'}});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function (localConfig) {
|
|
|
|
should.exist(localConfig);
|
|
|
|
localConfig.server.host.should.equal('127.0.0.1');
|
|
|
|
localConfig.server.port.should.equal('2368');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('rejects server if there is a host but no port', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({server: {host: '127.0.0.1'}});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('rejects server if there is a port but no host', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({server: {port: '2368'}});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('rejects server if configuration is empty', function (done) {
|
2015-12-14 23:05:11 +03:00
|
|
|
overrideReadFileConfig({server: {}});
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
config.load().then(function () {
|
|
|
|
done(expectedError);
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
err.should.be.an.Error();
|
2014-08-23 20:19:13 +04:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
2014-09-20 22:14:16 +04:00
|
|
|
|
2014-09-21 01:11:30 +04:00
|
|
|
describe('Check for deprecation messages:', function () {
|
2014-09-20 22:14:16 +04:00
|
|
|
var logStub,
|
|
|
|
// Can't use afterEach here, because mocha uses console.log to output the checkboxes
|
|
|
|
// which we've just stubbed, so we need to restore it before the test ends to see ticks.
|
|
|
|
resetEnvironment = function () {
|
|
|
|
process.env.NODE_ENV = currentEnv;
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
logStub = sinon.spy(console, 'log');
|
2014-09-20 22:14:16 +04:00
|
|
|
process.env.NODE_ENV = 'development';
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
2014-09-21 01:11:30 +04:00
|
|
|
logStub.restore();
|
2015-12-14 23:05:11 +03:00
|
|
|
resetEnvironment();
|
2014-09-20 22:14:16 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('doesn\'t display warning when deprecated options not set', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.config.checkDeprecated();
|
2016-02-08 00:27:01 +03:00
|
|
|
logStub.calledOnce.should.be.false();
|
2014-09-20 22:14:16 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays warning when updateCheck exists and is truthy', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({
|
2014-09-20 22:14:16 +04:00
|
|
|
updateCheck: 'foo'
|
|
|
|
});
|
|
|
|
// Run the test code
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.config.checkDeprecated();
|
2014-09-20 22:14:16 +04:00
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
logStub.calledOnce.should.be.true();
|
2014-09-21 01:11:30 +04:00
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
logStub.calledWithMatch('updateCheck').should.be.true();
|
2014-09-20 22:14:16 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays warning when updateCheck exists and is falsy', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({
|
2015-07-18 03:26:15 +03:00
|
|
|
updateCheck: false
|
2014-09-20 22:14:16 +04:00
|
|
|
});
|
|
|
|
// Run the test code
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.config.checkDeprecated();
|
2014-09-20 22:14:16 +04:00
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
logStub.calledOnce.should.be.true();
|
2014-09-21 01:11:30 +04:00
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
logStub.calledWithMatch('updateCheck').should.be.true();
|
2014-09-21 01:11:30 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays warning when mail.fromaddress exists and is truthy', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({
|
2014-09-21 01:11:30 +04:00
|
|
|
mail: {
|
|
|
|
fromaddress: 'foo'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Run the test code
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.config.checkDeprecated();
|
2014-09-21 01:11:30 +04:00
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
logStub.calledOnce.should.be.true();
|
2014-09-21 01:11:30 +04:00
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
logStub.calledWithMatch('mail.fromaddress').should.be.true();
|
2014-09-21 01:11:30 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays warning when mail.fromaddress exists and is falsy', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({
|
2014-09-21 01:11:30 +04:00
|
|
|
mail: {
|
2015-07-18 03:26:15 +03:00
|
|
|
fromaddress: false
|
2014-09-21 01:11:30 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
// Run the test code
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.config.checkDeprecated();
|
2014-09-21 01:11:30 +04:00
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
logStub.calledOnce.should.be.true();
|
2015-07-18 03:26:15 +03:00
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
logStub.calledWithMatch('mail.fromaddress').should.be.true();
|
2014-09-21 01:11:30 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('doesn\'t display warning when only part of a deprecated option is set', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({
|
2014-09-21 01:11:30 +04:00
|
|
|
mail: {
|
|
|
|
notfromaddress: 'foo'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.config.checkDeprecated();
|
2016-02-08 00:27:01 +03:00
|
|
|
logStub.calledOnce.should.be.false();
|
2014-09-20 22:14:16 +04:00
|
|
|
});
|
2014-10-12 22:46:53 +04:00
|
|
|
|
|
|
|
it('can not modify the deprecatedItems on the config object', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({
|
2014-10-12 22:46:53 +04:00
|
|
|
deprecatedItems: ['foo']
|
|
|
|
});
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.config.deprecatedItems.should.not.equal(['foo']);
|
2014-10-12 22:46:53 +04:00
|
|
|
});
|
2014-09-20 22:14:16 +04:00
|
|
|
});
|
2014-09-10 08:06:24 +04:00
|
|
|
});
|