mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Merge pull request #5876 from sebgie/issue#5872
Fix client.secret for new installs
This commit is contained in:
commit
77447fc42d
3 changed files with 23 additions and 4 deletions
|
@ -92,6 +92,10 @@ populate = function populate() {
|
|||
});
|
||||
|
||||
_.each(fixtures.clients, function (client) {
|
||||
// no random secrets during testing
|
||||
if (process.env.NODE_ENV.indexOf('testing') !== 0) {
|
||||
client.secret = crypto.randomBytes(6).toString('hex');
|
||||
}
|
||||
ops.push(Client.add(client, options));
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
var _ = require('lodash'),
|
||||
Promise = require('bluebird'),
|
||||
crypto = require('crypto'),
|
||||
sequence = require('../../utils/sequence'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
|
@ -19,6 +20,7 @@ var _ = require('lodash'),
|
|||
logInfo,
|
||||
populateDefaultSettings,
|
||||
backupDatabase,
|
||||
fixClientSecret,
|
||||
|
||||
// public
|
||||
init,
|
||||
|
@ -52,6 +54,19 @@ backupDatabase = function backupDatabase() {
|
|||
});
|
||||
};
|
||||
|
||||
// TODO: move to migration.to005() for next DB version
|
||||
fixClientSecret = function () {
|
||||
return models.Clients.forge().query('where', 'secret', '=', 'not_available').fetch().then(function updateClients(results) {
|
||||
return Promise.map(results.models, function mapper(client) {
|
||||
if (process.env.NODE_ENV.indexOf('testing') !== 0) {
|
||||
logInfo('Updating client secret');
|
||||
client.secret = crypto.randomBytes(6).toString('hex');
|
||||
}
|
||||
return models.Client.edit(client, {context: {internal: true}, id: client.id});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Check for whether data is needed to be bootstrapped or not
|
||||
init = function (tablesOnly) {
|
||||
tablesOnly = tablesOnly || false;
|
||||
|
@ -78,7 +93,8 @@ init = function (tablesOnly) {
|
|||
if (databaseVersion === defaultVersion) {
|
||||
// 1. The database exists and is up-to-date
|
||||
logInfo('Up to date at version ' + databaseVersion);
|
||||
return;
|
||||
// TODO: temporary fix for missing client.secret
|
||||
return fixClientSecret();
|
||||
}
|
||||
|
||||
if (databaseVersion > defaultVersion) {
|
||||
|
|
|
@ -57,10 +57,10 @@ function forkGhost(newConfig, envName) {
|
|||
newConfig.server.port = port;
|
||||
newConfig.url = url.format(_.extend({}, url.parse(newConfig.url), {port: port, host: null}));
|
||||
|
||||
var newConfigFile = path.join(config.paths.appRoot, 'config.test' + port + '.js');
|
||||
var newConfigFile = path.join(config.paths.appRoot, 'config.test.' + envName + '.js');
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.writeFile(newConfigFile, 'module.exports = {' + envName + ': ' + JSON.stringify(newConfig) + '}', function (err) {
|
||||
fs.writeFile(newConfigFile, 'module.exports = {"' + process.env.NODE_ENV + '": ' + JSON.stringify(newConfig) + '}', function (err) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
@ -81,7 +81,6 @@ function forkGhost(newConfig, envName) {
|
|||
};
|
||||
|
||||
env.GHOST_CONFIG = newConfigFile;
|
||||
env.NODE_ENV = envName;
|
||||
child = cp.fork(path.join(config.paths.appRoot, 'index.js'), {env: env});
|
||||
// return the port to make it easier to do requests
|
||||
child.port = port;
|
||||
|
|
Loading…
Add table
Reference in a new issue