|
| 1 | +const chai = require('chai'); |
| 2 | +const service = require('../src/service'); |
| 3 | +const config = require('../src/config'); |
| 4 | +const sinon = require('sinon'); |
| 5 | +const proxyquire = require('proxyquire'); |
| 6 | + |
| 7 | +chai.should(); |
| 8 | +const expect = chai.expect; |
| 9 | + |
| 10 | +describe('auth methods', async () => { |
| 11 | + let app; |
| 12 | + |
| 13 | + before(async function () { |
| 14 | + app = await service.start(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('should return a local auth method by default', async function () { |
| 18 | + const authMethods = config.getAuthMethods(); |
| 19 | + expect(authMethods).to.have.lengthOf(1); |
| 20 | + expect(authMethods[0].type).to.equal('local'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should return an error if no auth methods are enabled', async function () { |
| 24 | + const newConfig = JSON.stringify({ |
| 25 | + authentication: [ |
| 26 | + { type: 'local', enabled: false }, |
| 27 | + { type: 'ActiveDirectory', enabled: false }, |
| 28 | + { type: 'openidconnect', enabled: false }, |
| 29 | + ], |
| 30 | + }); |
| 31 | + |
| 32 | + const fsStub = { |
| 33 | + existsSync: sinon.stub().returns(true), |
| 34 | + readFileSync: sinon.stub().returns(newConfig), |
| 35 | + }; |
| 36 | + |
| 37 | + const config = proxyquire('../src/config', { |
| 38 | + fs: fsStub, |
| 39 | + }); |
| 40 | + |
| 41 | + expect(() => config.getAuthMethods()).to.throw(Error, 'No authentication method enabled'); |
| 42 | + }); |
| 43 | +}); |
0 commit comments