From 003c8d54621b63a92545c99ff05fb33a95ace74f Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Sun, 14 Feb 2016 18:44:34 +0000 Subject: [PATCH] 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 --- .../server/data/migration/fixtures/fixtures.json | 8 ++------ core/server/data/migration/fixtures/index.js | 5 ----- core/server/models/client.js | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/core/server/data/migration/fixtures/fixtures.json b/core/server/data/migration/fixtures/fixtures.json index 692c934f67..735a6fd04c 100644 --- a/core/server/data/migration/fixtures/fixtures.json +++ b/core/server/data/migration/fixtures/fixtures.json @@ -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" } ] } diff --git a/core/server/data/migration/fixtures/index.js b/core/server/data/migration/fixtures/index.js index d845ba609c..c7e371f492 100644 --- a/core/server/data/migration/fixtures/index.js +++ b/core/server/data/migration/fixtures/index.js @@ -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(); diff --git a/core/server/models/client.js b/core/server/models/client.js index 0f614125d9..caab81c742 100644 --- a/core/server/models/client.js +++ b/core/server/models/client.js @@ -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'); }