2019-02-04 17:16:24 +03:00
|
|
|
const should = require('should');
|
|
|
|
const supertest = require('supertest');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../../../core/shared/config');
|
2019-02-04 17:16:24 +03:00
|
|
|
const testUtils = require('../../../../utils');
|
|
|
|
const localUtils = require('./utils');
|
|
|
|
const ghost = testUtils.startGhost;
|
|
|
|
|
2020-06-22 14:21:00 +03:00
|
|
|
// NOTE: in future iterations these fields should be fetched from a central module.
|
|
|
|
// Have put a list as is here for the lack of better place for it.
|
2020-06-25 08:13:24 +03:00
|
|
|
const defaultSettingsKeyTypes = [
|
2020-06-29 17:22:42 +03:00
|
|
|
{key: 'title', type: 'blog'},
|
|
|
|
{key: 'description', type: 'blog'},
|
|
|
|
{key: 'logo', type: 'blog'},
|
|
|
|
{key: 'cover_image', type: 'blog'},
|
|
|
|
{key: 'icon', type: 'blog'},
|
|
|
|
{key: 'codeinjection_head', type: 'blog'},
|
|
|
|
{key: 'codeinjection_foot', type: 'blog'},
|
|
|
|
{key: 'facebook', type: 'blog'},
|
|
|
|
{key: 'twitter', type: 'blog'},
|
|
|
|
{key: 'navigation', type: 'blog'},
|
|
|
|
{key: 'secondary_navigation', type: 'blog'},
|
|
|
|
{key: 'meta_title', type: 'blog'},
|
|
|
|
{key: 'meta_description', type: 'blog'},
|
|
|
|
{key: 'og_image', type: 'blog'},
|
|
|
|
{key: 'og_title', type: 'blog'},
|
|
|
|
{key: 'og_description', type: 'blog'},
|
|
|
|
{key: 'twitter_image', type: 'blog'},
|
|
|
|
{key: 'twitter_title', type: 'blog'},
|
|
|
|
{key: 'twitter_description', type: 'blog'},
|
|
|
|
{key: 'active_theme', type: 'theme'},
|
|
|
|
{key: 'is_private', type: 'private'},
|
|
|
|
{key: 'password', type: 'private'},
|
|
|
|
{key: 'public_hash', type: 'private'},
|
|
|
|
{key: 'default_content_visibility', type: 'members'},
|
|
|
|
{key: 'members_allow_free_signup', type: 'members'},
|
|
|
|
{key: 'members_from_address', type: 'members'},
|
2020-08-27 17:57:50 +03:00
|
|
|
{key: 'members_support_address', type: 'members'},
|
|
|
|
{key: 'members_reply_address', type: 'members'},
|
2020-11-17 20:17:54 +03:00
|
|
|
{key: 'members_paid_signup_redirect', type: 'members'},
|
|
|
|
{key: 'members_free_signup_redirect', type: 'members'},
|
2020-06-29 17:22:42 +03:00
|
|
|
{key: 'stripe_product_name', type: 'members'},
|
|
|
|
{key: 'stripe_plans', type: 'members'},
|
|
|
|
{key: 'stripe_secret_key', type: 'members'},
|
|
|
|
{key: 'stripe_publishable_key', type: 'members'},
|
|
|
|
{key: 'stripe_connect_secret_key', type: 'members'},
|
|
|
|
{key: 'stripe_connect_publishable_key', type: 'members'},
|
|
|
|
{key: 'stripe_connect_account_id', type: 'members'},
|
|
|
|
{key: 'stripe_connect_display_name', type: 'members'},
|
|
|
|
{key: 'stripe_connect_livemode', type: 'members'},
|
|
|
|
{key: 'portal_name', type: 'portal'},
|
|
|
|
{key: 'portal_button', type: 'portal'},
|
|
|
|
{key: 'portal_plans', type: 'portal'},
|
2020-07-07 11:02:47 +03:00
|
|
|
{key: 'portal_button_style', type: 'portal'},
|
|
|
|
{key: 'portal_button_icon', type: 'portal'},
|
|
|
|
{key: 'portal_button_signup_text', type: 'portal'},
|
2020-07-03 12:00:20 +03:00
|
|
|
{key: 'mailgun_api_key', type: 'bulk_email'},
|
|
|
|
{key: 'mailgun_domain', type: 'bulk_email'},
|
|
|
|
{key: 'mailgun_base_url', type: 'bulk_email'},
|
2020-11-23 21:36:12 +03:00
|
|
|
{key: 'email_track_opens', type: 'bulk_email'},
|
2020-06-29 17:22:42 +03:00
|
|
|
{key: 'amp', type: 'blog'},
|
2020-07-10 16:19:45 +03:00
|
|
|
{key: 'amp_gtag_id', type: 'blog'},
|
2020-06-29 17:22:42 +03:00
|
|
|
{key: 'labs', type: 'blog'},
|
|
|
|
{key: 'slack', type: 'blog'},
|
|
|
|
{key: 'unsplash', type: 'blog'},
|
|
|
|
{key: 'shared_views', type: 'blog'},
|
|
|
|
{key: 'ghost_head', type: 'blog'},
|
|
|
|
{key: 'ghost_foot', type: 'blog'},
|
|
|
|
{key: 'active_timezone', type: 'blog'},
|
2020-11-11 15:56:11 +03:00
|
|
|
{key: 'default_locale', type: 'blog'},
|
|
|
|
{key: 'newsletter_show_badge', type: 'newsletter'},
|
|
|
|
{key: 'newsletter_show_header', type: 'newsletter'},
|
2020-11-13 16:18:47 +03:00
|
|
|
{key: 'newsletter_footer_content', type: 'newsletter'},
|
2021-01-15 16:35:15 +03:00
|
|
|
{key: 'newsletter_body_font_category', type: 'newsletter'},
|
|
|
|
{key: 'firstpromoter', type: 'firstpromoter'},
|
|
|
|
{key: 'firstpromoter_id', type: 'firstpromoter'}
|
2020-06-22 14:21:00 +03:00
|
|
|
];
|
|
|
|
|
2019-10-09 20:37:44 +03:00
|
|
|
describe('Settings API (v2)', function () {
|
2019-02-04 17:16:24 +03:00
|
|
|
let ghostServer;
|
2019-10-09 11:26:54 +03:00
|
|
|
let request;
|
2019-02-04 17:16:24 +03:00
|
|
|
|
2019-10-09 11:26:54 +03:00
|
|
|
describe('As Owner', function () {
|
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then(function (_ghostServer) {
|
|
|
|
ghostServer = _ghostServer;
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
return localUtils.doAuth(request);
|
|
|
|
});
|
|
|
|
});
|
2019-02-04 17:16:24 +03:00
|
|
|
|
2020-06-24 11:01:28 +03:00
|
|
|
it('Can request all settings', function () {
|
|
|
|
return request.get(localUtils.API.getApiQuery(`settings/`))
|
2019-10-09 11:26:54 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-06-24 11:01:28 +03:00
|
|
|
.expect(200)
|
|
|
|
.then((res) => {
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
should.exist(jsonResponse.meta);
|
|
|
|
|
|
|
|
jsonResponse.settings.should.be.an.Object();
|
|
|
|
const settings = jsonResponse.settings;
|
|
|
|
|
2020-06-29 17:22:42 +03:00
|
|
|
should.equal(settings.length, defaultSettingsKeyTypes.length);
|
|
|
|
for (const defaultSetting of defaultSettingsKeyTypes) {
|
|
|
|
should.exist(settings.find((setting) => {
|
|
|
|
return setting.key === defaultSetting.key && setting.type === defaultSetting.type;
|
|
|
|
}));
|
|
|
|
}
|
2020-06-24 11:01:28 +03:00
|
|
|
|
|
|
|
localUtils.API.checkResponse(jsonResponse, 'settings');
|
|
|
|
});
|
2019-10-09 11:26:54 +03:00
|
|
|
});
|
2019-02-04 17:16:24 +03:00
|
|
|
|
2020-06-24 11:01:28 +03:00
|
|
|
it('Can request settings by type', function () {
|
|
|
|
return request.get(localUtils.API.getApiQuery(`settings/?type=theme`))
|
2020-06-22 14:21:00 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.then((res) => {
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
should.exist(jsonResponse.meta);
|
|
|
|
|
|
|
|
jsonResponse.settings.should.be.an.Object();
|
|
|
|
const settings = jsonResponse.settings;
|
|
|
|
|
2020-06-24 11:01:28 +03:00
|
|
|
Object.keys(settings).length.should.equal(1);
|
|
|
|
settings[0].key.should.equal('active_theme');
|
|
|
|
settings[0].value.should.equal('casper');
|
|
|
|
settings[0].type.should.equal('theme');
|
|
|
|
|
|
|
|
localUtils.API.checkResponse(jsonResponse, 'settings');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-25 08:13:24 +03:00
|
|
|
xit('Can not request settings by group, returns all settings instead', function () {
|
2020-06-25 07:32:16 +03:00
|
|
|
return request.get(localUtils.API.getApiQuery(`settings/?group=theme`))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.then((res) => {
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
should.exist(jsonResponse.meta);
|
|
|
|
|
|
|
|
jsonResponse.settings.should.be.an.Object();
|
|
|
|
const settings = jsonResponse.settings;
|
|
|
|
|
|
|
|
Object.keys(settings).length.should.equal(39);
|
2020-06-25 08:13:24 +03:00
|
|
|
settings.map(s => s.key).should.deepEqual(defaultSettingsKeyTypes);
|
2020-06-25 07:32:16 +03:00
|
|
|
|
|
|
|
localUtils.API.checkResponse(jsonResponse, 'settings');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can request settings by type and ignores group ', function () {
|
|
|
|
return request.get(localUtils.API.getApiQuery(`settings/?group=theme&type=private`))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.then((res) => {
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
should.exist(jsonResponse.meta);
|
|
|
|
|
|
|
|
jsonResponse.settings.should.be.an.Object();
|
|
|
|
const settings = jsonResponse.settings;
|
|
|
|
|
|
|
|
Object.keys(settings).length.should.equal(3);
|
|
|
|
settings[0].key.should.equal('is_private');
|
|
|
|
settings[0].value.should.equal(false);
|
|
|
|
settings[0].type.should.equal('private');
|
|
|
|
|
|
|
|
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
|
|
|
|
localUtils.API.checkResponse(jsonResponse, 'settings');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-24 11:01:28 +03:00
|
|
|
it('Requesting core settings type returns no results', function () {
|
|
|
|
return request.get(localUtils.API.getApiQuery(`settings/?type=core`))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.then((res) => {
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
should.exist(jsonResponse.meta);
|
|
|
|
|
|
|
|
jsonResponse.settings.should.be.an.Object();
|
|
|
|
const settings = jsonResponse.settings;
|
|
|
|
|
|
|
|
Object.keys(settings).length.should.equal(0);
|
2020-06-22 14:21:00 +03:00
|
|
|
|
|
|
|
localUtils.API.checkResponse(jsonResponse, 'settings');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-24 11:01:28 +03:00
|
|
|
it('Can\'t read core setting', function () {
|
|
|
|
return request
|
|
|
|
.get(localUtils.API.getApiQuery('settings/db_hash/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(403);
|
|
|
|
});
|
|
|
|
|
2019-10-09 11:26:54 +03:00
|
|
|
it('Can\'t read permalinks', function (done) {
|
|
|
|
request.get(localUtils.API.getApiQuery('settings/permalinks/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-02-04 17:16:24 +03:00
|
|
|
|
2019-10-09 11:26:54 +03:00
|
|
|
done();
|
2020-06-22 14:21:00 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can read default_locale deprecated in v3', function (done) {
|
|
|
|
request.get(localUtils.API.getApiQuery('settings/default_locale/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
|
|
|
|
jsonResponse.settings.length.should.eql(1);
|
|
|
|
|
2020-06-25 07:32:16 +03:00
|
|
|
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
|
2020-06-22 14:21:00 +03:00
|
|
|
jsonResponse.settings[0].key.should.eql('default_locale');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can read active_timezone deprecated in v3', function (done) {
|
|
|
|
request.get(localUtils.API.getApiQuery('settings/active_timezone/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
|
|
|
|
jsonResponse.settings.length.should.eql(1);
|
|
|
|
|
2020-06-25 07:32:16 +03:00
|
|
|
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
|
2020-06-22 14:21:00 +03:00
|
|
|
jsonResponse.settings[0].key.should.eql('active_timezone');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can read ghost_head deprecated in v3', function (done) {
|
|
|
|
request.get(localUtils.API.getApiQuery('settings/ghost_head/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
|
|
|
|
jsonResponse.settings.length.should.eql(1);
|
|
|
|
|
2020-06-25 07:32:16 +03:00
|
|
|
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
|
2020-06-22 14:21:00 +03:00
|
|
|
jsonResponse.settings[0].key.should.eql('ghost_head');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can read codeinjection_foot renamed in v3', function (done) {
|
|
|
|
request.get(localUtils.API.getApiQuery('settings/codeinjection_foot/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
|
|
|
|
jsonResponse.settings.length.should.eql(1);
|
|
|
|
|
2020-06-25 07:32:16 +03:00
|
|
|
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
|
2020-06-22 14:21:00 +03:00
|
|
|
jsonResponse.settings[0].key.should.eql('codeinjection_foot');
|
|
|
|
done();
|
2019-10-09 11:26:54 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can\'t read non existent setting', function (done) {
|
|
|
|
request.get(localUtils.API.getApiQuery('settings/testsetting/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
2020-04-29 18:44:27 +03:00
|
|
|
const jsonResponse = res.body;
|
2019-10-09 11:26:54 +03:00
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.errors);
|
|
|
|
testUtils.API.checkResponseValue(jsonResponse.errors[0], [
|
|
|
|
'message',
|
|
|
|
'context',
|
|
|
|
'type',
|
|
|
|
'details',
|
|
|
|
'property',
|
|
|
|
'help',
|
|
|
|
'code',
|
|
|
|
'id'
|
|
|
|
]);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can\'t edit permalinks', function (done) {
|
|
|
|
const settingToChange = {
|
|
|
|
settings: [{key: 'permalinks', value: '/:primary_author/:slug/'}]
|
|
|
|
};
|
|
|
|
|
|
|
|
request.put(localUtils.API.getApiQuery('settings/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send(settingToChange)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-19 07:45:26 +03:00
|
|
|
it('can\'t edit non existent setting', function () {
|
|
|
|
return request.get(localUtils.API.getApiQuery('settings/'))
|
2019-10-09 11:26:54 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-10-19 07:45:26 +03:00
|
|
|
.then(function (res) {
|
2020-04-29 18:44:27 +03:00
|
|
|
let jsonResponse = res.body;
|
|
|
|
const newValue = 'new value';
|
2019-10-09 11:26:54 +03:00
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
jsonResponse.settings = [{key: 'testvalue', value: newValue}];
|
|
|
|
|
2020-10-19 07:45:26 +03:00
|
|
|
return request.put(localUtils.API.getApiQuery('settings/'))
|
2019-10-09 11:26:54 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send(jsonResponse)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
2020-10-19 07:45:26 +03:00
|
|
|
.then(function ({body, headers}) {
|
|
|
|
jsonResponse = body;
|
|
|
|
should.not.exist(headers['x-cache-invalidate']);
|
2019-10-09 11:26:54 +03:00
|
|
|
should.exist(jsonResponse.errors);
|
|
|
|
testUtils.API.checkResponseValue(jsonResponse.errors[0], [
|
|
|
|
'message',
|
|
|
|
'context',
|
|
|
|
'type',
|
|
|
|
'details',
|
|
|
|
'property',
|
|
|
|
'help',
|
|
|
|
'code',
|
|
|
|
'id'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-19 07:45:26 +03:00
|
|
|
it('Will transform "1"', function () {
|
|
|
|
return request.get(localUtils.API.getApiQuery('settings/'))
|
2019-10-09 11:26:54 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-10-19 07:45:26 +03:00
|
|
|
.then(function (res) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const jsonResponse = res.body;
|
|
|
|
|
|
|
|
const settingToChange = {
|
|
|
|
settings: [
|
|
|
|
{
|
|
|
|
key: 'is_private',
|
|
|
|
value: '1'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2019-10-09 11:26:54 +03:00
|
|
|
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.settings);
|
2019-02-04 17:16:24 +03:00
|
|
|
|
2019-10-09 11:26:54 +03:00
|
|
|
request.put(localUtils.API.getApiQuery('settings/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send(settingToChange)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
2020-10-19 07:45:26 +03:00
|
|
|
.then(function ({body, headers}) {
|
|
|
|
const putBody = body;
|
|
|
|
headers['x-cache-invalidate'].should.eql('/*');
|
2019-10-09 11:26:54 +03:00
|
|
|
should.exist(putBody);
|
|
|
|
|
|
|
|
putBody.settings[0].key.should.eql('is_private');
|
|
|
|
putBody.settings[0].value.should.eql(true);
|
|
|
|
|
|
|
|
localUtils.API.checkResponse(putBody, 'settings');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
|
|
|
|
2019-10-09 11:26:54 +03:00
|
|
|
describe('As Admin', function () {
|
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then(function (_ghostServer) {
|
|
|
|
ghostServer = _ghostServer;
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
// create admin
|
|
|
|
return testUtils.createUser({
|
|
|
|
user: testUtils.DataGenerator.forKnex.createUser({email: 'admin+1@ghost.org'}),
|
|
|
|
role: testUtils.DataGenerator.Content.roles[0].name
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2019-10-09 11:26:54 +03:00
|
|
|
})
|
|
|
|
.then(function (admin) {
|
|
|
|
request.user = admin;
|
|
|
|
|
|
|
|
// by default we login with the owner
|
|
|
|
return localUtils.doAuth(request);
|
|
|
|
});
|
|
|
|
});
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2019-03-06 14:56:26 +03:00
|
|
|
|
2019-10-09 11:26:54 +03:00
|
|
|
describe('As Editor', function () {
|
|
|
|
let editor;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then(function (_ghostServer) {
|
|
|
|
ghostServer = _ghostServer;
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
// create editor
|
|
|
|
return testUtils.createUser({
|
|
|
|
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+1@ghost.org'}),
|
|
|
|
role: testUtils.DataGenerator.Content.roles[1].name
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(function (_user1) {
|
|
|
|
editor = _user1;
|
|
|
|
request.user = editor;
|
|
|
|
|
|
|
|
// by default we login with the owner
|
|
|
|
return localUtils.doAuth(request);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-19 07:45:26 +03:00
|
|
|
it('should not be able to edit settings', function () {
|
|
|
|
return request.get(localUtils.API.getApiQuery('settings/'))
|
2019-10-09 11:26:54 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-10-19 07:45:26 +03:00
|
|
|
.then(function (res) {
|
2020-04-29 18:44:27 +03:00
|
|
|
let jsonResponse = res.body;
|
2020-10-19 07:45:26 +03:00
|
|
|
|
2019-10-09 11:26:54 +03:00
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
jsonResponse.settings = [{key: 'visibility', value: 'public'}];
|
|
|
|
|
2020-10-19 07:45:26 +03:00
|
|
|
return request.put(localUtils.API.getApiQuery('settings/'))
|
2019-10-09 11:26:54 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send(jsonResponse)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(403)
|
2020-10-19 07:45:26 +03:00
|
|
|
.then(function ({body, headers}) {
|
|
|
|
jsonResponse = body;
|
|
|
|
should.not.exist(headers['x-cache-invalidate']);
|
2019-10-09 11:26:54 +03:00
|
|
|
should.exist(jsonResponse.errors);
|
|
|
|
testUtils.API.checkResponseValue(jsonResponse.errors[0], [
|
|
|
|
'message',
|
|
|
|
'context',
|
|
|
|
'type',
|
|
|
|
'details',
|
|
|
|
'property',
|
|
|
|
'help',
|
|
|
|
'code',
|
|
|
|
'id'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('As Author', function () {
|
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then(function (_ghostServer) {
|
|
|
|
ghostServer = _ghostServer;
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
// create author
|
|
|
|
return testUtils.createUser({
|
|
|
|
user: testUtils.DataGenerator.forKnex.createUser({email: 'test+2@ghost.org'}),
|
|
|
|
role: testUtils.DataGenerator.Content.roles[2].name
|
2019-03-06 14:56:26 +03:00
|
|
|
});
|
2019-10-09 11:26:54 +03:00
|
|
|
})
|
|
|
|
.then(function (author) {
|
|
|
|
request.user = author;
|
|
|
|
|
|
|
|
// by default we login with the owner
|
|
|
|
return localUtils.doAuth(request);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-19 07:45:26 +03:00
|
|
|
it('should not be able to edit settings', function () {
|
|
|
|
return request.get(localUtils.API.getApiQuery('settings/'))
|
2019-10-09 11:26:54 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-10-19 07:45:26 +03:00
|
|
|
.then(function (res) {
|
2020-04-29 18:44:27 +03:00
|
|
|
let jsonResponse = res.body;
|
2019-10-09 11:26:54 +03:00
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
jsonResponse.settings = [{key: 'visibility', value: 'public'}];
|
|
|
|
|
2020-10-19 07:45:26 +03:00
|
|
|
return request.put(localUtils.API.getApiQuery('settings/'))
|
2019-10-09 11:26:54 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send(jsonResponse)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(403)
|
2020-10-19 07:45:26 +03:00
|
|
|
.then(function ({body, headers}) {
|
|
|
|
jsonResponse = body;
|
|
|
|
should.not.exist(headers['x-cache-invalidate']);
|
2019-10-09 11:26:54 +03:00
|
|
|
should.exist(jsonResponse.errors);
|
|
|
|
testUtils.API.checkResponseValue(jsonResponse.errors[0], [
|
|
|
|
'message',
|
|
|
|
'context',
|
|
|
|
'type',
|
|
|
|
'details',
|
|
|
|
'property',
|
|
|
|
'help',
|
|
|
|
'code',
|
|
|
|
'id'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-03-06 14:56:26 +03:00
|
|
|
});
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|