Ghost/test/regression/settings/settings_spec.js
Rish d6f4f01eff Added new settings integrity tests
refs https://github.com/TryGhost/Ghost/issues/12026

- We made changes to settings table structure in 3.22 which added new columns for `group` and `flags`
- Any new setting needs explicit group and flag migrations since or they fallback to default group value of `core`
- This tests ensures
  - hash is updated in DB integrity test anytime default-settings are changed
  - that a migration is present by maintaining a whitelist of allowed core settings and failing if new setting is added without correct group migration
2020-07-10 18:32:54 +05:30

51 lines
1.7 KiB
JavaScript

const db = require('../../../core/server/data/db');
const testUtils = require('../../utils');
/**
* @NOTE
*
* If this test fails for you, you have modified the default settings.
* When you make a change or add new setting, please ensure that:
* - If a new `core` setting is added/removed/renamed, update the below whitelist
* - If a new non-`core` setting is added, it includes corresponding migration to populate its `group` and `flags`
*/
describe('Settings', function () {
before(function () {
return testUtils.startGhost();
});
// Whitelist: Only this list needs updating when a core setting is added/removed/renamed
const coreSettingKeys = [
'db_hash',
'next_update_check',
'notifications',
'session_secret',
'theme_session_secret',
'ghost_public_key',
'ghost_private_key',
'members_public_key',
'members_private_key',
'members_email_auth_secret'
];
// If this test is failing, then it is likely a new setting has been added without group migration
// In case of `core` setting modifications, whitelist above needs to be updated
it('should not modify core keys without fixing this test', function () {
return db.knex('settings')
.where('group', 'core')
.whereNotIn('key', coreSettingKeys)
.count('*')
.then(function (data) {
const countResult = data[0]['count(*)'];
countResult.should.eql(0);
})
.catch(function (err) {
// CASE: table does not exist
if (err.errno === 1146) {
return Promise.resolve();
}
throw err;
});
});
});