-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 🎨 deny auto switch no issue - deny auth switch after the blog was setup - setup completed depends on the status of the user right now, see comments * Updates from comments - re-use statuses in user model - update error message
- Loading branch information
Showing
8 changed files
with
172 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var Promise = require('bluebird'), | ||
models = require('../models'), | ||
errors = require('../errors'); | ||
|
||
/** | ||
* 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 | ||
*/ | ||
exports.switch = function validate(options) { | ||
var authType = options.authType; | ||
|
||
return models.User.isSetup() | ||
.then(function (isSetup) { | ||
if (!isSetup) { | ||
return; | ||
} | ||
|
||
return models.Client.findOne({slug: 'ghost-auth'}, {columns: 'id'}) | ||
.then(function (client) { | ||
if ((client && authType === 'password') || !client && authType === 'ghost') { | ||
return Promise.reject(new errors.InternalServerError({ | ||
code: 'AUTH_SWITCH', | ||
message: 'Switching the auth strategy is not allowed.', | ||
context: 'Please reset your database and start from scratch.', | ||
help: 'NODE_ENV=production|development knex-migrator reset && NODE_ENV=production|development knex-migrator init\n' | ||
})); | ||
} | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
var should = require('should'), | ||
sinon = require('sinon'), | ||
Promise = require('bluebird'), | ||
auth = require('../../../server/auth'), | ||
models = require('../../../server/models'), | ||
sandbox = sinon.sandbox.create(); | ||
|
||
describe('UNIT: auth validation', function () { | ||
before(function () { | ||
models.init(); | ||
}); | ||
|
||
beforeEach(function () { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('ghost is enabled', function () { | ||
it('[success]', function () { | ||
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(false)); | ||
|
||
return auth.validation.switch({ | ||
authType: 'ghost' | ||
}); | ||
}); | ||
|
||
it('[success]', function () { | ||
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(true)); | ||
sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(true)); | ||
|
||
return auth.validation.switch({ | ||
authType: 'ghost' | ||
}); | ||
}); | ||
|
||
it('[failure]', function () { | ||
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(true)); | ||
sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(true)); | ||
|
||
return auth.validation.switch({ | ||
authType: 'password' | ||
}).catch(function (err) { | ||
should.exist(err); | ||
err.code.should.eql('AUTH_SWITCH'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('password is enabled', function () { | ||
it('[success]', function () { | ||
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(false)); | ||
|
||
return auth.validation.switch({ | ||
authType: 'password' | ||
}); | ||
}); | ||
|
||
it('[success]', function () { | ||
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(true)); | ||
sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(false)); | ||
|
||
return auth.validation.switch({ | ||
authType: 'password' | ||
}); | ||
}); | ||
|
||
it('[failure]', function () { | ||
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(true)); | ||
sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(true)); | ||
|
||
return auth.validation.switch({ | ||
authType: 'ghost' | ||
}).catch(function (err) { | ||
should.exist(err); | ||
err.code.should.eql('AUTH_SWITCH'); | ||
}); | ||
}); | ||
}); | ||
}); |