Skip to content

Commit

Permalink
馃殤 Disable remote authentication (#8346)
Browse files Browse the repository at this point in the history
closes #8342
- extend auth validation to deny auth type "ghost" for now
- skip some tests
  • Loading branch information
kirrg001 authored and kevinansfield committed Apr 24, 2017
1 parent 2300219 commit 7549473
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
13 changes: 12 additions & 1 deletion core/server/auth/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ var Promise = require('bluebird'),
* If the setup is completed and...
* 1. the public client does exist, deny to switch to local
* 2. the public client does not exist, deny to switch to remote
*
* See https://github.com/TryGhost/Ghost/issues/8342
* Remote authentication is disabled right now.
*/
exports.switch = function validate(options) {
exports.validate = function validate(options) {
var authType = options.authType;

if (authType === 'ghost') {
return Promise.reject(new errors.InternalServerError({
code: 'AUTH_TYPE',
message: 'Ghost doesn\'t support remote authentication at the moment.',
help: 'Set `auth.type` to "password".'
}));
}

return models.User.isSetup()
.then(function (isSetup) {
if (!isSetup) {
Expand Down
3 changes: 1 addition & 2 deletions core/server/config/env/config.production.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
}
},
"auth": {
"type": "ghost",
"url": "https://auth.ghost.org"
"type": "password"
},
"paths": {
"contentPath": "content/"
Expand Down
2 changes: 1 addition & 1 deletion core/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function init() {

debug('Express Apps done');
}).then(function () {
return auth.validation.switch({
return auth.validation.validate({
authType: config.get('auth:type')
});
}).then(function () {
Expand Down
34 changes: 24 additions & 10 deletions core/test/unit/auth/validation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ var should = require('should'),

sandbox = sinon.sandbox.create();

/**
* See https://github.com/TryGhost/Ghost/issues/8342
* We have disabled Ghost authentication temporary.
* That's why some tests are skipped for now.
*/
describe('UNIT: auth validation', function () {
before(function () {
models.init();
Expand All @@ -16,28 +21,37 @@ describe('UNIT: auth validation', function () {
});

describe('ghost is enabled', function () {
it('[success]', function () {
it('[failure]', function () {
return auth.validation.validate({
authType: 'ghost'
}).catch(function (err) {
should.exist(err);
err.code.should.eql('AUTH_TYPE');
});
});

it.skip('[success]', function () {
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(false));

return auth.validation.switch({
return auth.validation.validate({
authType: 'ghost'
});
});

it('[success]', function () {
it.skip('[success]', function () {
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(true));
sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(true));

return auth.validation.switch({
return auth.validation.validate({
authType: 'ghost'
});
});

it('[failure]', function () {
it.skip('[failure]', function () {
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(true));
sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(true));

return auth.validation.switch({
return auth.validation.validate({
authType: 'password'
}).catch(function (err) {
should.exist(err);
Expand All @@ -50,7 +64,7 @@ describe('UNIT: auth validation', function () {
it('[success]', function () {
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(false));

return auth.validation.switch({
return auth.validation.validate({
authType: 'password'
});
});
Expand All @@ -59,16 +73,16 @@ describe('UNIT: auth validation', function () {
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(true));
sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(false));

return auth.validation.switch({
return auth.validation.validate({
authType: 'password'
});
});

it('[failure]', function () {
it.skip('[failure]', function () {
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(true));
sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(true));

return auth.validation.switch({
return auth.validation.validate({
authType: 'ghost'
}).catch(function (err) {
should.exist(err);
Expand Down

0 comments on commit 7549473

Please sign in to comment.