11const chai = require ( 'chai' ) ;
2- const service = require ( '../src/service' ) ;
32const config = require ( '../src/config' ) ;
43const sinon = require ( 'sinon' ) ;
54const proxyquire = require ( 'proxyquire' ) ;
@@ -8,12 +7,6 @@ chai.should();
87const expect = chai . expect ;
98
109describe ( 'auth methods' , async ( ) => {
11- let app ;
12-
13- before ( async function ( ) {
14- app = await service . start ( ) ;
15- } ) ;
16-
1710 it ( 'should return a local auth method by default' , async function ( ) {
1811 const authMethods = config . getAuthMethods ( ) ;
1912 expect ( authMethods ) . to . have . lengthOf ( 1 ) ;
@@ -41,7 +34,28 @@ describe('auth methods', async () => {
4134 expect ( ( ) => config . getAuthMethods ( ) ) . to . throw ( Error , 'No authentication method enabled' ) ;
4235 } ) ;
4336
44- after ( async function ( ) {
45- await service . httpServer . close ( ) ;
46- } ) ;
37+ it ( 'should return an array of enabled auth methods when overridden' , async function ( ) {
38+ const newConfig = JSON . stringify ( {
39+ authentication : [
40+ { type : 'local' , enabled : true } ,
41+ { type : 'ActiveDirectory' , enabled : true } ,
42+ { type : 'openidconnect' , enabled : true } ,
43+ ] ,
44+ } ) ;
45+
46+ const fsStub = {
47+ existsSync : sinon . stub ( ) . returns ( true ) ,
48+ readFileSync : sinon . stub ( ) . returns ( newConfig ) ,
49+ } ;
50+
51+ const config = proxyquire ( '../src/config' , {
52+ fs : fsStub ,
53+ } ) ;
54+
55+ const authMethods = config . getAuthMethods ( ) ;
56+ expect ( authMethods ) . to . have . lengthOf ( 3 ) ;
57+ expect ( authMethods [ 0 ] . type ) . to . equal ( 'local' ) ;
58+ expect ( authMethods [ 1 ] . type ) . to . equal ( 'ActiveDirectory' ) ;
59+ expect ( authMethods [ 2 ] . type ) . to . equal ( 'openidconnect' ) ;
60+ } )
4761} ) ;
0 commit comments