1 | 'use strict'
|
2 |
|
3 |
|
4 |
|
5 | const expect = require('chai').expect
|
6 | const ActiveDirectory = require('../index')
|
7 | const config = require('./config')
|
8 |
|
9 | let server = require('./mockServer')
|
10 |
|
11 | describe('ctor method', function () {
|
12 | it('should support legacy parameters (url, baseDN, username, password)', function (done) {
|
13 | const ad = new ActiveDirectory(config.url, config.baseDN, config.username, config.password)
|
14 | expect(ad.baseDN).to.equal(config.baseDN)
|
15 | expect(ad.opts.url).to.equal(config.url)
|
16 | expect(ad.opts.bindDN).to.equal(config.username)
|
17 | expect(ad.opts.bindCredentials).to.equal(config.password)
|
18 | done()
|
19 | })
|
20 |
|
21 | it('should set parameters from configuration object', function (done) {
|
22 | const ad = new ActiveDirectory(config)
|
23 | expect(ad.baseDN).to.equal(config.baseDN)
|
24 | expect(ad.opts.url).to.equal(config.url)
|
25 | expect(ad.opts.bindDN).to.equal(config.username)
|
26 | expect(ad.opts.bindDN).to.equal(config.username)
|
27 | expect(ad.opts.bindCredentials).to.equal(config.password)
|
28 | done()
|
29 | })
|
30 |
|
31 | it('should replace default user attributes if specified', function (done) {
|
32 | const ad = new ActiveDirectory(Object.assign({}, config, {
|
33 | attributes: {
|
34 | user: [ 'mycustomuserattribute' ]
|
35 | }
|
36 | }))
|
37 | const defaultAttributes = ad.defaultAttributes || {}
|
38 | expect(defaultAttributes.user.length).to.equal(1)
|
39 | expect(defaultAttributes.group.length).to.be.gt(0)
|
40 | done()
|
41 | })
|
42 |
|
43 | it('should replace default group attributes if specified', function (done) {
|
44 | const ad = new ActiveDirectory(Object.assign({}, config, {
|
45 | attributes: {
|
46 | group: [ 'mycustomgroupattribute' ]
|
47 | }
|
48 | }))
|
49 | const defaultAttributes = ad.defaultAttributes || {}
|
50 | expect(defaultAttributes.group.length).to.equal(1)
|
51 | expect(defaultAttributes.user.length).to.be.gt(0)
|
52 | done()
|
53 | })
|
54 |
|
55 | it('should throw an InvalidCredentialsError exception if the username/password are incorrect.', function (done) {
|
56 | let ad
|
57 | function doTest () {
|
58 | ad.findUser('unknown', function (err, user) {
|
59 | expect(err).to.not.be.null
|
60 | expect(err).to.be.an.instanceof(Error)
|
61 | expect(err.name).to.equal('InvalidCredentialsError')
|
62 | done()
|
63 | })
|
64 | }
|
65 |
|
66 | server(function (s) {
|
67 | ad = new ActiveDirectory(Object.assign({}, config, {
|
68 | password: 'TheWrongPassword!',
|
69 | username: 'AnInvalidUsername'
|
70 | }))
|
71 | server = s
|
72 | doTest()
|
73 | })
|
74 | })
|
75 |
|
76 | it('should parse ldapjs options into the opts property', function (done) {
|
77 | const ad = new ActiveDirectory(Object.assign({}, config, {
|
78 | tlsOptions: {foo: 'bar'},
|
79 | paged: true
|
80 | }))
|
81 |
|
82 | expect(ad.opts.paged).to.be.true
|
83 | expect(ad.opts.tlsOptions).to.exist
|
84 | expect(ad.opts.tlsOptions.foo).to.equal('bar')
|
85 | done()
|
86 | })
|
87 | })
|