Skip to content

Commit

Permalink
🎨 Use GhostAuth name and example emails (#7475)
Browse files Browse the repository at this point in the history
refs #7452

- remove references to 'patronus' in favour of GhostAuth, Note: this will require databases to be deleted ;)
- remove email addresses from test data
  • Loading branch information
ErisDS authored and kevinansfield committed Oct 3, 2016
1 parent 92be253 commit e40290a
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 70 deletions.
10 changes: 5 additions & 5 deletions core/server/auth/auth-strategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ strategies = {

/**
* Ghost Strategy
* patronusRefreshToken: will be null for now, because we don't need it right now
* ghostAuthRefreshToken: will be null for now, because we don't need it right now
*
* CASES:
* - via invite token
* - via normal auth
* - via setup
*
* @TODO: validate patronus profile?
* @TODO: validate GhostAuth profile?
*/
ghostStrategy: function ghostStrategy(req, patronusAccessToken, patronusRefreshToken, profile, done) {
ghostStrategy: function ghostStrategy(req, ghostAuthAccessToken, ghostAuthRefreshToken, profile, done) {
var inviteToken = req.body.inviteToken,
options = {context: {internal: true}},
handleInviteToken, handleSetup;
Expand Down Expand Up @@ -135,9 +135,9 @@ strategies = {

return handleSetup();
})
.then(function updatePatronusToken(user) {
.then(function updateGhostAuthToken(user) {
options.id = user.id;
return models.User.edit({patronus_access_token: patronusAccessToken}, options);
return models.User.edit({ghost_auth_access_token: ghostAuthAccessToken}, options);
})
.then(function returnResponse(user) {
done(null, user, profile);
Expand Down
10 changes: 5 additions & 5 deletions core/server/auth/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ _private.registerClient = function registerClient(options) {

return new Promise(function (resolve, reject) {
var retry = function retry(retryCount, done) {
models.Client.findOne({name: 'Ghost Patronus'}, {context: {internal: true}})
models.Client.findOne({slug: 'ghost-auth'}, {context: {internal: true}})
.then(function (client) {
// CASE: patronus client is already registered
// CASE: Ghost Auth client is already registered
if (client) {
return done(null, {
client_id: client.get('uuid'),
Expand All @@ -31,8 +31,8 @@ _private.registerClient = function registerClient(options) {
return ghostOAuth2Strategy.registerClient({clientName: url})
.then(function addClient(credentials) {
return models.Client.add({
name: 'Ghost Patronus',
slug: 'patronus',
name: 'Ghost Auth',
slug: 'ghost-auth',
uuid: credentials.client_id,
secret: credentials.client_secret
}, {context: {internal: true}});
Expand Down Expand Up @@ -80,7 +80,7 @@ exports.init = function initPassport(options) {
passport.use(new ClientPasswordStrategy(authStrategies.clientPasswordStrategy));
passport.use(new BearerStrategy(authStrategies.bearerStrategy));

if (type !== 'patronus') {
if (type !== 'ghost') {
return resolve({passport: passport.initialize()});
}

Expand Down
3 changes: 2 additions & 1 deletion core/server/config/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"active": "SchedulingDefault"
},
"auth": {
"type": "password"
"type": "ghost",
"url": "http://devauth.ghost.org:8080"
}
}
4 changes: 0 additions & 4 deletions core/server/config/env/config.development.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@
},
"paths": {
"contentPath": "content/"
},
"auth": {
"type": "patronus",
"url": "http://devauth.ghost.org:8080"
}
}
3 changes: 3 additions & 0 deletions core/server/config/env/config.testing-mysql.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"database" : "ghost_testing"
}
},
"auth": {
"type": "password"
},
"logging": false
}
3 changes: 3 additions & 0 deletions core/server/config/env/config.testing.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
"server": {
"port": 2369
},
"auth": {
"type": "password"
},
"logging": false
}
6 changes: 3 additions & 3 deletions core/server/controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ adminControllers = {
fetch = {
configuration: api.configuration.read().then(function (res) { return res.configuration[0]; }),
client: api.clients.read({slug: 'ghost-admin'}).then(function (res) { return res.clients[0]; }),
patronus: api.clients.read({slug: 'patronus'})
ghostAuth: api.clients.read({slug: 'ghost-auth'})
.then(function (res) { return res.clients[0]; })
.catch(function () {
return;
Expand All @@ -34,8 +34,8 @@ adminControllers = {
configuration.clientId = {value: result.client.slug, type: 'string'};
configuration.clientSecret = {value: result.client.secret, type: 'string'};

if (result.patronus && config.get('auth:type') === 'patronus') {
configuration.ghostAuthId = {value: result.patronus.uuid, type: 'string'};
if (result.ghostAuth && config.get('auth:type') === 'ghost') {
configuration.ghostAuthId = {value: result.ghostAuth.uuid, type: 'string'};
}

debug('rendering default template');
Expand Down
2 changes: 1 addition & 1 deletion core/server/data/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
uuid: {type: 'string', maxlength: 36, nullable: false, validations: {isUUID: true}},
name: {type: 'string', maxlength: 150, nullable: false},
slug: {type: 'string', maxlength: 150, nullable: false, unique: true},
patronus_access_token: {type: 'string', nullable: true},
ghost_auth_access_token: {type: 'string', nullable: true},
password: {type: 'string', maxlength: 60, nullable: false},
email: {type: 'string', maxlength: 191, nullable: false, unique: true, validations: {isEmail: true}},
image: {type: 'text', maxlength: 2000, nullable: true},
Expand Down
2 changes: 1 addition & 1 deletion core/server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ User = ghostBookshelf.Model.extend({
var attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options);
// remove password hash for security reasons
delete attrs.password;
delete attrs.patronus_access_token;
delete attrs.ghost_auth_access_token;

if (!options || !options.context || (!options.context.user && !options.context.internal)) {
delete attrs.email;
Expand Down
30 changes: 15 additions & 15 deletions core/test/integration/api/api_invites_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Invites API', function () {
describe('Add', function () {
it('add invite 1', function (done) {
InvitesAPI.add({
invites: [{email: 'kate+1@ghost.org', roles: [testUtils.roles.ids.editor]}]
invites: [{email: 'test@example.com', roles: [testUtils.roles.ids.editor]}]
}, _.merge({}, {include: ['roles']}, testUtils.context.owner))
.then(function (response) {
response.invites.length.should.eql(1);
Expand All @@ -41,7 +41,7 @@ describe('Invites API', function () {

it('add invite 2', function (done) {
InvitesAPI.add({
invites: [{email: 'kate+2@ghost.org', roles: [testUtils.roles.ids.author]}]
invites: [{email: 'test2@example.com', roles: [testUtils.roles.ids.author]}]
}, _.merge({}, {include: ['roles']}, testUtils.context.owner))
.then(function (response) {
response.invites.length.should.eql(1);
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.owner]
}
]
Expand All @@ -202,7 +202,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.admin]
}
]
Expand All @@ -217,7 +217,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.editor]
}
]
Expand All @@ -232,7 +232,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.author]
}
]
Expand All @@ -247,7 +247,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.author.toString()]
}
]
Expand All @@ -264,7 +264,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.owner]
}
]
Expand All @@ -277,7 +277,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.admin]
}
]
Expand All @@ -292,7 +292,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.editor]
}
]
Expand All @@ -307,7 +307,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.author]
}
]
Expand All @@ -324,7 +324,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.owner]
}
]
Expand All @@ -337,7 +337,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.author]
}
]
Expand All @@ -352,7 +352,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.owner]
}
]
Expand All @@ -365,7 +365,7 @@ describe('Invites API', function () {
InvitesAPI.add({
invites: [
{
email: 'kate+1@ghost.org',
email: 'test@example.com',
roles: [testUtils.roles.ids.author]
}
]
Expand Down
36 changes: 18 additions & 18 deletions core/test/unit/auth/auth-strategies_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ describe('Auth Strategies', function () {
});

it('with invite, but with wrong invite token', function (done) {
var patronusAccessToken = '12345',
var ghostAuthAccessToken = '12345',
req = {body: {inviteToken: 'wrong'}},
profile = {email_address: 'kate@ghost.org'};
profile = {email_address: 'test@example.com'};

userByEmailStub.returns(Promise.resolve(null));
inviteStub.returns(Promise.reject(new errors.NotFoundError()));

authStrategies.ghostStrategy(req, patronusAccessToken, null, profile, function (err) {
authStrategies.ghostStrategy(req, ghostAuthAccessToken, null, profile, function (err) {
should.exist(err);
(err instanceof errors.NotFoundError).should.eql(true);
userByEmailStub.calledOnce.should.be.true();
Expand All @@ -229,9 +229,9 @@ describe('Auth Strategies', function () {
});

it('with correct invite token, but expired', function (done) {
var patronusAccessToken = '12345',
var ghostAuthAccessToken = '12345',
req = {body: {inviteToken: 'token'}},
profile = {email_address: 'kate@ghost.org'};
profile = {email_address: 'test@example.com'};

userByEmailStub.returns(Promise.resolve(null));
inviteStub.returns(Promise.resolve(Models.Invite.forge({
Expand All @@ -240,7 +240,7 @@ describe('Auth Strategies', function () {
expires: Date.now() - 1000
})));

authStrategies.ghostStrategy(req, patronusAccessToken, null, profile, function (err) {
authStrategies.ghostStrategy(req, ghostAuthAccessToken, null, profile, function (err) {
should.exist(err);
(err instanceof errors.NotFoundError).should.eql(true);
userByEmailStub.calledOnce.should.be.true();
Expand All @@ -250,9 +250,9 @@ describe('Auth Strategies', function () {
});

it('with correct invite token', function (done) {
var patronusAccessToken = '12345',
var ghostAuthAccessToken = '12345',
req = {body: {inviteToken: 'token'}},
invitedProfile = {email_address: 'kate@ghost.org'},
invitedProfile = {email_address: 'test@example.com'},
invitedUser = {id: 2},
inviteModel = Models.Invite.forge({
id: 1,
Expand All @@ -266,7 +266,7 @@ describe('Auth Strategies', function () {
inviteStub.returns(Promise.resolve(inviteModel));
sandbox.stub(inviteModel, 'destroy').returns(Promise.resolve());

authStrategies.ghostStrategy(req, patronusAccessToken, null, invitedProfile, function (err, user, profile) {
authStrategies.ghostStrategy(req, ghostAuthAccessToken, null, invitedProfile, function (err, user, profile) {
should.not.exist(err);
should.exist(user);
should.exist(profile);
Expand All @@ -280,24 +280,24 @@ describe('Auth Strategies', function () {
});

it('setup', function (done) {
var patronusAccessToken = '12345',
var ghostAuthAccessToken = '12345',
req = {body: {}},
ownerProfile = {email_address: 'kate@ghost.org'},
ownerProfile = {email_address: 'test@example.com'},
owner = {id: 2};

userByEmailStub.returns(Promise.resolve(null));
userFindOneStub.returns(Promise.resolve(_.merge({}, {status: 'inactive'}, owner)));
userEditStub.withArgs({status: 'active', email: 'kate@ghost.org'}, {
userEditStub.withArgs({status: 'active', email: 'test@example.com'}, {
context: {internal: true},
id: owner.id
}).returns(Promise.resolve(owner));

userEditStub.withArgs({patronus_access_token: patronusAccessToken}, {
userEditStub.withArgs({ghost_auth_access_token: ghostAuthAccessToken}, {
context: {internal: true},
id: owner.id
}).returns(Promise.resolve(owner));

authStrategies.ghostStrategy(req, patronusAccessToken, null, ownerProfile, function (err, user, profile) {
authStrategies.ghostStrategy(req, ghostAuthAccessToken, null, ownerProfile, function (err, user, profile) {
should.not.exist(err);
userByEmailStub.calledOnce.should.be.true();
inviteStub.calledOnce.should.be.false();
Expand All @@ -311,18 +311,18 @@ describe('Auth Strategies', function () {
});

it('auth', function (done) {
var patronusAccessToken = '12345',
var ghostAuthAccessToken = '12345',
req = {body: {}},
ownerProfile = {email_address: 'kate@ghost.org'},
ownerProfile = {email_address: 'test@example.com'},
owner = {id: 2};

userByEmailStub.returns(Promise.resolve(owner));
userEditStub.withArgs({patronus_access_token: patronusAccessToken}, {
userEditStub.withArgs({ghost_auth_access_token: ghostAuthAccessToken}, {
context: {internal: true},
id: owner.id
}).returns(Promise.resolve(owner));

authStrategies.ghostStrategy(req, patronusAccessToken, null, ownerProfile, function (err, user, profile) {
authStrategies.ghostStrategy(req, ghostAuthAccessToken, null, ownerProfile, function (err, user, profile) {
should.not.exist(err);
userByEmailStub.calledOnce.should.be.true();
userEditStub.calledOnce.should.be.true();
Expand Down
Loading

0 comments on commit e40290a

Please sign in to comment.