2017-03-02 20:50:58 +01:00
|
|
|
var should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
|
|
|
Promise = require('bluebird'),
|
|
|
|
auth = require('../../../server/auth'),
|
|
|
|
models = require('../../../server/models'),
|
2017-03-21 08:24:11 +00:00
|
|
|
|
2017-03-02 20:50:58 +01:00
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
|
2017-04-24 19:56:49 +02:00
|
|
|
/**
|
|
|
|
* See https://github.com/TryGhost/Ghost/issues/8342
|
|
|
|
* We have disabled Ghost authentication temporary.
|
|
|
|
* That's why some tests are skipped for now.
|
|
|
|
*/
|
2017-03-02 20:50:58 +01:00
|
|
|
describe('UNIT: auth validation', function () {
|
|
|
|
before(function () {
|
|
|
|
models.init();
|
|
|
|
});
|
|
|
|
|
2017-04-05 23:02:16 +02:00
|
|
|
afterEach(function () {
|
2017-03-02 20:50:58 +01:00
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('ghost is enabled', function () {
|
2017-04-24 19:56:49 +02:00
|
|
|
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 () {
|
2017-03-02 20:50:58 +01:00
|
|
|
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(false));
|
|
|
|
|
2017-04-24 19:56:49 +02:00
|
|
|
return auth.validation.validate({
|
2017-03-02 20:50:58 +01:00
|
|
|
authType: 'ghost'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-24 19:56:49 +02:00
|
|
|
it.skip('[success]', function () {
|
2017-03-02 20:50:58 +01:00
|
|
|
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(true));
|
|
|
|
sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(true));
|
|
|
|
|
2017-04-24 19:56:49 +02:00
|
|
|
return auth.validation.validate({
|
2017-03-02 20:50:58 +01:00
|
|
|
authType: 'ghost'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-24 19:56:49 +02:00
|
|
|
it.skip('[failure]', function () {
|
2017-03-02 20:50:58 +01:00
|
|
|
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(true));
|
|
|
|
sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(true));
|
|
|
|
|
2017-04-24 19:56:49 +02:00
|
|
|
return auth.validation.validate({
|
2017-03-02 20:50:58 +01:00
|
|
|
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));
|
|
|
|
|
2017-04-24 19:56:49 +02:00
|
|
|
return auth.validation.validate({
|
2017-03-02 20:50:58 +01:00
|
|
|
authType: 'password'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('[success]', function () {
|
|
|
|
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(true));
|
|
|
|
sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(false));
|
|
|
|
|
2017-04-24 19:56:49 +02:00
|
|
|
return auth.validation.validate({
|
2017-03-02 20:50:58 +01:00
|
|
|
authType: 'password'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-24 19:56:49 +02:00
|
|
|
it.skip('[failure]', function () {
|
2017-03-02 20:50:58 +01:00
|
|
|
sandbox.stub(models.User, 'isSetup').returns(Promise.resolve(true));
|
|
|
|
sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(true));
|
|
|
|
|
2017-04-24 19:56:49 +02:00
|
|
|
return auth.validation.validate({
|
2017-03-02 20:50:58 +01:00
|
|
|
authType: 'ghost'
|
|
|
|
}).catch(function (err) {
|
|
|
|
should.exist(err);
|
|
|
|
err.code.should.eql('AUTH_SWITCH');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|