1 | 'use strict'
|
2 |
|
3 |
|
4 |
|
5 | const expect = require('chai').expect
|
6 | const ActiveDirectory = require('../index').promiseWrapper
|
7 | const config = require('./config')
|
8 |
|
9 | let server = require('./mockServer')
|
10 |
|
11 | describe('Promised getRootDSE method', function () {
|
12 | let ad
|
13 |
|
14 | before(function (done) {
|
15 | server(function (s) {
|
16 | ad = new ActiveDirectory(config)
|
17 | server = s
|
18 | done()
|
19 | })
|
20 | })
|
21 |
|
22 | it('should return ECONNREFUSED for closed port', function (done) {
|
23 | ActiveDirectory.getRootDSE('ldap://127.0.0.1:389')
|
24 | .then(done)
|
25 | .catch((err) => {
|
26 | expect(err).to.not.be.null
|
27 | expect(err).to.be.an.instanceof(Error)
|
28 | expect(err.errno).to.equal('ECONNREFUSED')
|
29 | done()
|
30 | })
|
31 | })
|
32 |
|
33 | it('should return an error if no url specified', function (done) {
|
34 | ActiveDirectory.getRootDSE(null)
|
35 | .then(done)
|
36 | .catch((err) => {
|
37 | expect(err).to.not.be.null
|
38 | expect(err).to.be.an.instanceof(Error)
|
39 | expect(err.message).to.include('in the form')
|
40 | done()
|
41 | })
|
42 | })
|
43 |
|
44 | it('should use the instance url property if omitted', function (done) {
|
45 | ad.getRootDSE()
|
46 | .then((result) => {
|
47 | expect(result).to.not.be.undefined
|
48 | done()
|
49 | })
|
50 | .catch(done)
|
51 | })
|
52 |
|
53 | it('should return all attributes when none specified', function (done) {
|
54 | const attrs = ['dn', 'dnsHostName', 'serverName', 'supportedLDAPVersion']
|
55 | ad.getRootDSE('ldap://127.0.0.1:1389')
|
56 | .then((result) => {
|
57 | expect(result).to.not.be.undefined
|
58 | const keys = Object.keys(result)
|
59 | keys.forEach((k) => expect(attrs).to.contain(k))
|
60 | done()
|
61 | })
|
62 | .catch(done)
|
63 | })
|
64 |
|
65 | it('should return only specified attributes', function (done) {
|
66 |
|
67 | const attrs = ['dn', 'supportedLDAPVersion']
|
68 | ad.getRootDSE('ldap://127.0.0.1:1389', attrs)
|
69 | .then((result) => {
|
70 | expect(result).to.not.be.undefined
|
71 | const keys = Object.keys(result)
|
72 | keys.forEach((k) => expect(attrs).to.contain(k))
|
73 | done()
|
74 | })
|
75 | .catch(done)
|
76 | })
|
77 |
|
78 | it('should not return the controls attribute', function (done) {
|
79 | ad.getRootDSE('ldap://127.0.0.1:1389')
|
80 | .then((result) => {
|
81 | expect(result).to.not.be.undefined
|
82 | const keys = Object.keys(result)
|
83 | expect(keys.indexOf('controls')).to.equal(-1)
|
84 | done()
|
85 | })
|
86 | .catch(done)
|
87 | })
|
88 | })
|