|
| 1 | +const chai = require('chai'); |
| 2 | +const sinon = require('sinon'); |
| 3 | +const proxyquire = require('proxyquire'); |
| 4 | +const expect = chai.expect; |
| 5 | + |
| 6 | +describe('ActiveDirectory auth method', () => { |
| 7 | + let ldapStub, dbStub, passportStub, strategyCallback; |
| 8 | + |
| 9 | + const newConfig = JSON.stringify({ |
| 10 | + authentication: [ |
| 11 | + { |
| 12 | + type: 'ActiveDirectory', |
| 13 | + enabled: true, |
| 14 | + adminGroup: 'test-admin-group', |
| 15 | + userGroup: 'test-user-group', |
| 16 | + domain: 'test.com', |
| 17 | + adConfig: { |
| 18 | + url: 'ldap://test-url', |
| 19 | + baseDN: 'dc=test,dc=com', |
| 20 | + searchBase: 'ou=users,dc=test,dc=com', |
| 21 | + }, |
| 22 | + }, |
| 23 | + ], |
| 24 | + }); |
| 25 | + |
| 26 | + beforeEach(() => { |
| 27 | + ldapStub = { |
| 28 | + isUserInAdGroup: sinon.stub(), |
| 29 | + }; |
| 30 | + |
| 31 | + dbStub = { |
| 32 | + updateUser: sinon.stub(), |
| 33 | + }; |
| 34 | + |
| 35 | + passportStub = { |
| 36 | + use: sinon.stub(), |
| 37 | + serializeUser: sinon.stub(), |
| 38 | + deserializeUser: sinon.stub(), |
| 39 | + }; |
| 40 | + |
| 41 | + const fsStub = { |
| 42 | + existsSync: sinon.stub().returns(true), |
| 43 | + readFileSync: sinon.stub().returns(newConfig), |
| 44 | + }; |
| 45 | + |
| 46 | + const config = proxyquire('../src/config', { |
| 47 | + fs: fsStub, |
| 48 | + }); |
| 49 | + |
| 50 | + const { configure } = proxyquire('../src/service/passport/activeDirectory', { |
| 51 | + './ldaphelper': ldapStub, |
| 52 | + '../../db': dbStub, |
| 53 | + '../../config': config, |
| 54 | + 'passport-activedirectory': function (options, callback) { |
| 55 | + strategyCallback = callback; |
| 56 | + return { |
| 57 | + name: 'ActiveDirectory', |
| 58 | + authenticate: () => {}, |
| 59 | + }; |
| 60 | + }, |
| 61 | + }); |
| 62 | + |
| 63 | + configure(passportStub); |
| 64 | + }); |
| 65 | + |
| 66 | +}); |
0 commit comments