mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Move client secret logic into the model
refs #6301 - Move secret generation logic to the model defaults, so there's no need to handle this in fixtures - Tested upgrades from 003 & fresh installs -> all is well
This commit is contained in:
parent
c3099a3c8c
commit
003c8d5462
3 changed files with 18 additions and 11 deletions
|
@ -70,16 +70,12 @@
|
|||
{
|
||||
"name": "Ghost Admin",
|
||||
"slug": "ghost-admin",
|
||||
"status": "enabled",
|
||||
"type": "ua",
|
||||
"secret": "not_available"
|
||||
"status": "enabled"
|
||||
},
|
||||
{
|
||||
"name": "Ghost Frontend",
|
||||
"slug": "ghost-frontend",
|
||||
"status": "enabled",
|
||||
"type": "ua",
|
||||
"secret": "not_available"
|
||||
"status": "enabled"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -93,10 +93,6 @@ 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));
|
||||
});
|
||||
|
||||
|
@ -252,7 +248,6 @@ to004 = function to004() {
|
|||
if (!client) {
|
||||
logInfo(i18n.t('notices.data.fixtures.addFrontendClientFixture'));
|
||||
var frontendClient = fixtures.clients[1];
|
||||
frontendClient.secret = crypto.randomBytes(6).toString('hex');
|
||||
return models.Client.add(frontendClient, options);
|
||||
}
|
||||
return Promise.resolve();
|
||||
|
|
|
@ -1,10 +1,26 @@
|
|||
var ghostBookshelf = require('./base'),
|
||||
crypto = require('crypto'),
|
||||
uuid = require('node-uuid'),
|
||||
|
||||
Client,
|
||||
Clients;
|
||||
|
||||
Client = ghostBookshelf.Model.extend({
|
||||
|
||||
tableName: 'clients',
|
||||
|
||||
defaults: function defaults() {
|
||||
var env = process.env.NODE_ENV,
|
||||
secret = env.indexOf('testing') !== 0 ? crypto.randomBytes(6).toString('hex') : 'not_available';
|
||||
|
||||
return {
|
||||
uuid: uuid.v4(),
|
||||
secret: secret,
|
||||
status: 'development',
|
||||
type: 'ua'
|
||||
};
|
||||
},
|
||||
|
||||
trustedDomains: function trustedDomains() {
|
||||
return this.hasMany('ClientTrustedDomain', 'client_id');
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue