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'),
|
|
|
|
/*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',
|
|
|
|
cover: 'casper'
|
|
|
|
}
|
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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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',
|
|
|
|
'subdir',
|
|
|
|
'config',
|
|
|
|
'configExample',
|
2015-01-18 06:54:56 +03:00
|
|
|
'storage',
|
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',
|
|
|
|
'availableThemes',
|
2014-01-26 20:11:02 +04:00
|
|
|
'availableApps',
|
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);
|
|
|
|
pathConfig.should.have.property('subdir', '');
|
|
|
|
});
|
|
|
|
|
2014-01-05 10:40:53 +04:00
|
|
|
it('should not return a slash for subdir', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
2014-07-17 18:33:21 +04:00
|
|
|
config.paths.should.have.property('subdir', '');
|
2013-12-28 20:01:08 +04:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/'});
|
2014-07-17 18:33:21 +04:00
|
|
|
config.paths.should.have.property('subdir', '');
|
2013-12-28 20:01:08 +04:00
|
|
|
});
|
|
|
|
|
2014-01-05 10:40:53 +04:00
|
|
|
it('should handle subdirectories properly', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
|
2014-07-17 18:33:21 +04:00
|
|
|
config.paths.should.have.property('subdir', '/blog');
|
2013-12-28 20:01:08 +04:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog/'});
|
2014-07-17 18:33:21 +04:00
|
|
|
config.paths.should.have.property('subdir', '/blog');
|
2013-12-28 20:01:08 +04:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/my/blog'});
|
2014-07-17 18:33:21 +04:00
|
|
|
config.paths.should.have.property('subdir', '/my/blog');
|
2013-12-28 20:01:08 +04:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/my/blog/'});
|
2014-07-17 18:33:21 +04:00
|
|
|
config.paths.should.have.property('subdir', '/my/blog');
|
2014-01-05 10:40:53 +04:00
|
|
|
});
|
2013-12-28 20:01:08 +04:00
|
|
|
|
2016-01-11 14:37:59 +03:00
|
|
|
it('should add subdir to list of protected slugs', function () {
|
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
|
|
|
|
config.slugs.protected.should.containEql('blog');
|
|
|
|
|
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/my/blog'});
|
|
|
|
config.slugs.protected.should.containEql('blog');
|
|
|
|
});
|
|
|
|
|
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 () {
|
|
|
|
var storagePath = path.join(config.paths.corePath, '/server/storage/', 'local-file-store');
|
|
|
|
|
|
|
|
config.paths.should.have.property('storage', storagePath);
|
|
|
|
config.storage.should.have.property('active', 'local-file-store');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow setting a custom active storage', function () {
|
|
|
|
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: {}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
config.paths.should.have.property('storage', storagePath);
|
|
|
|
config.storage.should.have.property('active', 's3');
|
|
|
|
config.storage.should.have.property('s3', {});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-04-10 18:59:38 +03:00
|
|
|
describe('Url', function () {
|
|
|
|
describe('urlJoin', function () {
|
|
|
|
it('should deduplicate slashes', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlJoin('/', '/my/', '/blog/').should.equal('/my/blog/');
|
|
|
|
config.urlJoin('/', '//my/', '/blog/').should.equal('/my/blog/');
|
|
|
|
config.urlJoin('/', '/', '/').should.equal('/');
|
|
|
|
});
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-04-10 18:59:38 +03:00
|
|
|
it('should not deduplicate slashes in protocol', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlJoin('http://myurl.com', '/rss').should.equal('http://myurl.com/rss');
|
|
|
|
config.urlJoin('https://myurl.com/', '/rss').should.equal('https://myurl.com/rss');
|
|
|
|
});
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-04-10 18:59:38 +03:00
|
|
|
it('should permit schemeless protocol', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlJoin('/', '/').should.equal('/');
|
|
|
|
config.urlJoin('//myurl.com', '/rss').should.equal('//myurl.com/rss');
|
|
|
|
config.urlJoin('//myurl.com/', '/rss').should.equal('//myurl.com/rss');
|
|
|
|
config.urlJoin('//myurl.com//', 'rss').should.equal('//myurl.com/rss');
|
|
|
|
config.urlJoin('', '//myurl.com', 'rss').should.equal('//myurl.com/rss');
|
|
|
|
});
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-04-10 18:59:38 +03:00
|
|
|
it('should deduplicate subdir', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlJoin('blog', 'blog/about').should.equal('blog/about');
|
|
|
|
config.urlJoin('blog/', 'blog/about').should.equal('blog/about');
|
|
|
|
});
|
2014-01-03 04:37:21 +04:00
|
|
|
});
|
|
|
|
|
2015-04-10 18:59:38 +03:00
|
|
|
describe('urlFor', function () {
|
|
|
|
it('should return the home url with no options', function () {
|
|
|
|
config.urlFor().should.equal('/');
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor().should.equal('/blog/');
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog/'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor().should.equal('/blog/');
|
|
|
|
});
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-04-10 18:59:38 +03:00
|
|
|
it('should return home url when asked for', function () {
|
|
|
|
var testContext = 'home';
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext).should.equal('/');
|
|
|
|
config.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/');
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext).should.equal('/');
|
|
|
|
config.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/');
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext).should.equal('/blog/');
|
|
|
|
config.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/');
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog/'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext).should.equal('/blog/');
|
|
|
|
config.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/');
|
|
|
|
});
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-04-10 18:59:38 +03:00
|
|
|
it('should return rss url when asked for', function () {
|
|
|
|
var testContext = 'rss';
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext).should.equal('/rss/');
|
|
|
|
config.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/rss/');
|
2014-02-13 20:15:29 +04:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext).should.equal('/blog/rss/');
|
|
|
|
config.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/rss/');
|
|
|
|
});
|
2014-02-13 20:15:29 +04:00
|
|
|
|
2015-04-10 18:59:38 +03:00
|
|
|
it('should return url for a random path when asked for', function () {
|
|
|
|
var testContext = {relativeUrl: '/about/'};
|
2015-03-20 06:00:32 +03:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext).should.equal('/about/');
|
|
|
|
config.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/about/');
|
2015-03-20 06:00:32 +03:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext).should.equal('/blog/about/');
|
|
|
|
config.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/about/');
|
|
|
|
});
|
2015-03-20 06:00:32 +03:00
|
|
|
|
2015-04-10 18:59:38 +03:00
|
|
|
it('should deduplicate subdirectories in paths', function () {
|
|
|
|
var testContext = {relativeUrl: '/blog/about/'};
|
2015-03-20 06:00:32 +03:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext).should.equal('/blog/about/');
|
|
|
|
config.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/about/');
|
2015-03-20 06:00:32 +03:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext).should.equal('/blog/about/');
|
|
|
|
config.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/about/');
|
2015-03-20 06:00:32 +03:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog/'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext).should.equal('/blog/about/');
|
|
|
|
config.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/about/');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return url for a post from post object', function () {
|
|
|
|
var testContext = 'post',
|
2016-04-03 01:16:20 +03:00
|
|
|
testData = {post: _.cloneDeep(testUtils.DataGenerator.Content.posts[2])};
|
2015-04-10 18:59:38 +03:00
|
|
|
|
|
|
|
// url is now provided on the postmodel, permalinkSetting tests are in the model_post_spec.js test
|
|
|
|
testData.post.url = '/short-and-sweet/';
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext, testData).should.equal('/short-and-sweet/');
|
|
|
|
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/short-and-sweet/');
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext, testData).should.equal('/blog/short-and-sweet/');
|
|
|
|
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/blog/short-and-sweet/');
|
2016-01-11 14:37:59 +03:00
|
|
|
|
|
|
|
testData.post.url = '/blog-one/';
|
|
|
|
config.urlFor(testContext, testData).should.equal('/blog/blog-one/');
|
|
|
|
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/blog/blog-one/');
|
2015-04-10 18:59:38 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return url for a tag when asked for', function () {
|
|
|
|
var testContext = 'tag',
|
|
|
|
testData = {tag: testUtils.DataGenerator.Content.tags[0]};
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext, testData).should.equal('/tag/kitchen-sink/');
|
|
|
|
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/tag/kitchen-sink/');
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext, testData).should.equal('/blog/tag/kitchen-sink/');
|
|
|
|
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/blog/tag/kitchen-sink/');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return url for an author when asked for', function () {
|
|
|
|
var testContext = 'author',
|
|
|
|
testData = {author: testUtils.DataGenerator.Content.users[0]};
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext, testData).should.equal('/author/joe-bloggs/');
|
|
|
|
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/author/joe-bloggs/');
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor(testContext, testData).should.equal('/blog/author/joe-bloggs/');
|
|
|
|
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/blog/author/joe-bloggs/');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return url for an image when asked for', function () {
|
|
|
|
var testContext = 'image',
|
|
|
|
testData;
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
2015-04-10 18:59:38 +03:00
|
|
|
|
|
|
|
testData = {image: '/content/images/my-image.jpg'};
|
|
|
|
config.urlFor(testContext, testData).should.equal('/content/images/my-image.jpg');
|
|
|
|
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/content/images/my-image.jpg');
|
|
|
|
|
|
|
|
testData = {image: 'http://placekitten.com/500/200'};
|
|
|
|
config.urlFor(testContext, testData).should.equal('http://placekitten.com/500/200');
|
|
|
|
config.urlFor(testContext, testData, true).should.equal('http://placekitten.com/500/200');
|
|
|
|
|
|
|
|
testData = {image: '/blog/content/images/my-image2.jpg'};
|
|
|
|
config.urlFor(testContext, testData).should.equal('/blog/content/images/my-image2.jpg');
|
|
|
|
// We don't make image urls absolute if they don't look like images relative to the image path
|
|
|
|
config.urlFor(testContext, testData, true).should.equal('/blog/content/images/my-image2.jpg');
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog/'});
|
2015-04-10 18:59:38 +03:00
|
|
|
|
|
|
|
testData = {image: '/content/images/my-image3.jpg'};
|
|
|
|
config.urlFor(testContext, testData).should.equal('/content/images/my-image3.jpg');
|
|
|
|
// We don't make image urls absolute if they don't look like images relative to the image path
|
|
|
|
config.urlFor(testContext, testData, true).should.equal('/content/images/my-image3.jpg');
|
|
|
|
|
|
|
|
testData = {image: '/blog/content/images/my-image4.jpg'};
|
|
|
|
config.urlFor(testContext, testData).should.equal('/blog/content/images/my-image4.jpg');
|
|
|
|
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/blog/content/images/my-image4.jpg');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return a url for a nav item when asked for it', function () {
|
|
|
|
var testContext = 'nav',
|
|
|
|
testData;
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com', urlSSL: 'https://my-ghost-blog.com'});
|
2015-04-10 18:59:38 +03:00
|
|
|
|
|
|
|
testData = {nav: {url: 'http://my-ghost-blog.com/short-and-sweet/'}};
|
|
|
|
config.urlFor(testContext, testData).should.equal('http://my-ghost-blog.com/short-and-sweet/');
|
|
|
|
|
|
|
|
testData = {nav: {url: 'http://my-ghost-blog.com/short-and-sweet/'}, secure: true};
|
|
|
|
config.urlFor(testContext, testData).should.equal('https://my-ghost-blog.com/short-and-sweet/');
|
|
|
|
|
|
|
|
testData = {nav: {url: 'http://sub.my-ghost-blog.com/'}};
|
|
|
|
config.urlFor(testContext, testData).should.equal('http://sub.my-ghost-blog.com/');
|
|
|
|
|
2015-09-26 00:31:54 +03:00
|
|
|
testData = {nav: {url: '//sub.my-ghost-blog.com/'}};
|
|
|
|
config.urlFor(testContext, testData).should.equal('//sub.my-ghost-blog.com/');
|
|
|
|
|
|
|
|
testData = {nav: {url: 'mailto:sub@my-ghost-blog.com/'}};
|
|
|
|
config.urlFor(testContext, testData).should.equal('mailto:sub@my-ghost-blog.com/');
|
|
|
|
|
|
|
|
testData = {nav: {url: '#this-anchor'}};
|
|
|
|
config.urlFor(testContext, testData).should.equal('#this-anchor');
|
|
|
|
|
2016-06-09 01:16:42 +03:00
|
|
|
testData = {nav: {url: 'http://some-external-page.com/my-ghost-blog.com'}};
|
|
|
|
config.urlFor(testContext, testData).should.equal('http://some-external-page.com/my-ghost-blog.com');
|
|
|
|
|
|
|
|
testData = {nav: {url: 'http://some-external-page.com/stuff-my-ghost-blog.com-around'}};
|
|
|
|
config.urlFor(testContext, testData).should.equal('http://some-external-page.com/stuff-my-ghost-blog.com-around');
|
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
|
2015-04-10 18:59:38 +03:00
|
|
|
testData = {nav: {url: 'http://my-ghost-blog.com/blog/short-and-sweet/'}};
|
|
|
|
config.urlFor(testContext, testData).should.equal('http://my-ghost-blog.com/blog/short-and-sweet/');
|
2015-07-18 04:45:06 +03:00
|
|
|
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com/'});
|
2015-07-18 04:45:06 +03:00
|
|
|
testData = {nav: {url: 'mailto:marshmallow@my-ghost-blog.com'}};
|
|
|
|
config.urlFor(testContext, testData).should.equal('mailto:marshmallow@my-ghost-blog.com');
|
2015-04-10 18:59:38 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return other known paths when requested', function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
2015-04-10 18:59:38 +03:00
|
|
|
config.urlFor('sitemap_xsl').should.equal('/sitemap.xsl');
|
|
|
|
config.urlFor('sitemap_xsl', true).should.equal('http://my-ghost-blog.com/sitemap.xsl');
|
|
|
|
|
|
|
|
config.urlFor('api').should.equal('/ghost/api/v0.1');
|
|
|
|
config.urlFor('api', true).should.equal('http://my-ghost-blog.com/ghost/api/v0.1');
|
|
|
|
});
|
2015-03-20 06:00:32 +03:00
|
|
|
});
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-04-10 18:59:38 +03:00
|
|
|
describe('urlPathForPost', function () {
|
2016-06-13 14:21:30 +03:00
|
|
|
it('permalink is /:slug/, timezone is default', function () {
|
|
|
|
config.theme.permalinks = '/:slug/';
|
2015-12-02 13:06:44 +03:00
|
|
|
|
|
|
|
var testData = testUtils.DataGenerator.Content.posts[2],
|
2015-04-10 18:59:38 +03:00
|
|
|
postLink = '/short-and-sweet/';
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2015-12-02 13:06:44 +03:00
|
|
|
config.urlPathForPost(testData).should.equal(postLink);
|
2015-04-10 18:59:38 +03:00
|
|
|
});
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2016-05-18 17:27:54 +03:00
|
|
|
it('permalink is /:year/:month/:day/:slug, blog timezone is Los Angeles', function () {
|
2016-06-13 14:21:30 +03:00
|
|
|
config.theme.timezone = 'America/Los_Angeles';
|
|
|
|
config.theme.permalinks = '/:year/:month/:day/:slug/';
|
|
|
|
|
2015-12-02 13:06:44 +03:00
|
|
|
var testData = testUtils.DataGenerator.Content.posts[2],
|
2016-05-18 17:27:54 +03:00
|
|
|
postLink = '/2016/05/17/short-and-sweet/';
|
2015-12-02 13:06:44 +03:00
|
|
|
|
2016-05-18 17:27:54 +03:00
|
|
|
testData.published_at = new Date('2016-05-18T06:30:00.000Z');
|
2015-12-02 13:06:44 +03:00
|
|
|
config.urlPathForPost(testData).should.equal(postLink);
|
2015-04-10 18:59:38 +03:00
|
|
|
});
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2016-06-13 21:40:58 +03:00
|
|
|
it('permalink is /:year/:month/:day/:slug, blog timezone is Asia Tokyo', function () {
|
|
|
|
config.theme.timezone = 'Asia/Tokyo';
|
|
|
|
config.theme.permalinks = '/:year/:month/:day/:slug/';
|
|
|
|
|
|
|
|
var testData = testUtils.DataGenerator.Content.posts[2],
|
|
|
|
postLink = '/2016/05/18/short-and-sweet/';
|
|
|
|
|
|
|
|
testData.published_at = new Date('2016-05-18T06:30:00.000Z');
|
|
|
|
config.urlPathForPost(testData).should.equal(postLink);
|
|
|
|
});
|
|
|
|
|
2016-05-18 17:27:54 +03:00
|
|
|
it('post is page, no permalink usage allowed at all', function () {
|
2016-06-13 14:21:30 +03:00
|
|
|
config.theme.timezone = 'America/Los_Angeles';
|
|
|
|
config.theme.permalinks = '/:year/:month/:day/:slug/';
|
2015-12-02 13:06:44 +03:00
|
|
|
|
|
|
|
var testData = testUtils.DataGenerator.Content.posts[5],
|
2015-04-10 18:59:38 +03:00
|
|
|
postLink = '/static-page-test/';
|
2015-12-02 13:06:44 +03:00
|
|
|
|
|
|
|
config.urlPathForPost(testData).should.equal(postLink);
|
2015-04-10 18:59:38 +03:00
|
|
|
});
|
|
|
|
|
2016-05-18 17:27:54 +03:00
|
|
|
it('permalink is /:year/:id:/:author', function () {
|
2016-06-13 14:21:30 +03:00
|
|
|
config.theme.timezone = 'America/Los_Angeles';
|
|
|
|
config.theme.permalinks = '/:year/:id/:author/';
|
2015-12-02 13:06:44 +03:00
|
|
|
|
2016-05-18 17:27:54 +03:00
|
|
|
var testData = _.merge(testUtils.DataGenerator.Content.posts[2], {id: 3}, {author: {slug: 'joe-blog'}}),
|
|
|
|
postLink = '/2015/3/joe-blog/';
|
2015-12-02 13:06:44 +03:00
|
|
|
|
2016-05-18 17:27:54 +03:00
|
|
|
testData.published_at = new Date('2016-01-01T00:00:00.000Z');
|
|
|
|
config.urlPathForPost(testData).should.equal(postLink);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('permalink is /:year/:id:/:author', function () {
|
2016-06-13 14:21:30 +03:00
|
|
|
config.theme.timezone = 'Europe/Berlin';
|
|
|
|
config.theme.permalinks = '/:year/:id/:author/';
|
2016-05-18 17:27:54 +03:00
|
|
|
|
|
|
|
var testData = _.merge(testUtils.DataGenerator.Content.posts[2], {id: 3}, {author: {slug: 'joe-blog'}}),
|
|
|
|
postLink = '/2016/3/joe-blog/';
|
|
|
|
|
|
|
|
testData.published_at = new Date('2016-01-01T00:00:00.000Z');
|
2015-12-02 13:06:44 +03:00
|
|
|
config.urlPathForPost(testData).should.equal(postLink);
|
2015-04-10 18:59:38 +03:00
|
|
|
});
|
2016-06-20 15:47:53 +03:00
|
|
|
|
|
|
|
it('post is not published yet', function () {
|
|
|
|
config.theme.permalinks = '/:year/:month/:day/:slug/';
|
|
|
|
|
|
|
|
var testData = _.merge(testUtils.DataGenerator.Content.posts[2], {id: 3, published_at: null}),
|
|
|
|
nowMoment = moment(),
|
|
|
|
postLink = '/YYYY/MM/DD/short-and-sweet/';
|
|
|
|
|
|
|
|
postLink = postLink.replace('YYYY', nowMoment.format('YYYY'));
|
|
|
|
postLink = postLink.replace('MM', nowMoment.format('MM'));
|
|
|
|
postLink = postLink.replace('DD', nowMoment.format('DD'));
|
|
|
|
|
|
|
|
config.urlPathForPost(testData).should.equal(postLink);
|
|
|
|
});
|
2014-01-03 04:37:21 +04:00
|
|
|
});
|
2015-12-15 13:41:53 +03:00
|
|
|
|
|
|
|
describe('apiUrl', function () {
|
|
|
|
it('should return https config.url if forceAdminSSL set', function () {
|
|
|
|
configUtils.set({
|
|
|
|
url: 'http://my-ghost-blog.com',
|
|
|
|
forceAdminSSL: true
|
|
|
|
});
|
|
|
|
|
|
|
|
config.apiUrl().should.eql('https://my-ghost-blog.com/ghost/api/v0.1/');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return https config.urlSSL if forceAdminSSL set and urlSSL is misconfigured', function () {
|
|
|
|
configUtils.set({
|
|
|
|
url: 'http://my-ghost-blog.com',
|
|
|
|
urlSSL: 'http://other-ghost-blog.com',
|
|
|
|
forceAdminSSL: true
|
|
|
|
});
|
|
|
|
|
|
|
|
config.apiUrl().should.eql('https://other-ghost-blog.com/ghost/api/v0.1/');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return https config.urlSSL if forceAdminSSL set', function () {
|
|
|
|
configUtils.set({
|
|
|
|
url: 'http://my-ghost-blog.com',
|
|
|
|
urlSSL: 'https://other-ghost-blog.com',
|
|
|
|
forceAdminSSL: true
|
|
|
|
});
|
|
|
|
|
|
|
|
config.apiUrl().should.eql('https://other-ghost-blog.com/ghost/api/v0.1/');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return https config.urlSSL if set and misconfigured & forceAdminSSL is NOT set', function () {
|
|
|
|
configUtils.set({
|
|
|
|
url: 'http://my-ghost-blog.com',
|
|
|
|
urlSSL: 'http://other-ghost-blog.com'
|
|
|
|
});
|
|
|
|
|
|
|
|
config.apiUrl().should.eql('https://other-ghost-blog.com/ghost/api/v0.1/');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return https config.urlSSL if set & forceAdminSSL is NOT set', function () {
|
|
|
|
configUtils.set({
|
|
|
|
url: 'http://my-ghost-blog.com',
|
|
|
|
urlSSL: 'https://other-ghost-blog.com'
|
|
|
|
});
|
|
|
|
|
|
|
|
config.apiUrl().should.eql('https://other-ghost-blog.com/ghost/api/v0.1/');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return https config.url if config.url is https & forceAdminSSL is NOT set', function () {
|
|
|
|
configUtils.set({
|
|
|
|
url: 'https://my-ghost-blog.com'
|
|
|
|
});
|
|
|
|
|
|
|
|
config.apiUrl().should.eql('https://my-ghost-blog.com/ghost/api/v0.1/');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return no protocol config.url if config.url is NOT https & forceAdminSSL/urlSSL is NOT set', function () {
|
|
|
|
configUtils.set({
|
|
|
|
url: 'http://my-ghost-blog.com'
|
|
|
|
});
|
|
|
|
|
|
|
|
config.apiUrl().should.eql('//my-ghost-blog.com/ghost/api/v0.1/');
|
|
|
|
});
|
|
|
|
});
|
2014-01-03 04:37:21 +04: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
|
|
|
});
|