UNPKG

2.23 kBJavaScriptView Raw
1'use strict'
2/* eslint-env node, mocha */
3/* eslint-disable no-unused-expressions */
4
5const expect = require('chai').expect
6const ActiveDirectory = require('../index')
7const config = require('./config')
8
9let server = require('./mockServer')
10
11describe('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', (err) => {
24 expect(err).to.not.be.null
25 expect(err).to.be.an.instanceof(Error)
26 expect(err.errno).to.equal('ECONNREFUSED')
27 done()
28 })
29 })
30
31 it('should return an error if no url specified', function (done) {
32 expect(
33 ActiveDirectory.getRootDSE.bind(null, null, () => {})
34 ).to.throw(Error)
35 done()
36 })
37
38 it('should use the instance url property if omitted', function (done) {
39 ad.getRootDSE((err, result) => {
40 expect(err).to.be.null
41 expect(result).to.not.be.undefined
42 done()
43 })
44 })
45
46 it('should return all attributes when none specified', function (done) {
47 const attrs = ['dn', 'dnsHostName', 'serverName', 'supportedLDAPVersion']
48 ad.getRootDSE('ldap://127.0.0.1:1389', (err, result) => {
49 expect(err).to.be.null
50 expect(result).to.not.be.undefined
51 const keys = Object.keys(result)
52 keys.forEach((k) => expect(attrs).to.contain(k))
53 done()
54 })
55 })
56
57 it('should return only specified attributes', function (done) {
58 // dn is always returned
59 const attrs = ['dn', 'supportedLDAPVersion']
60 ad.getRootDSE('ldap://127.0.0.1:1389', attrs, (err, result) => {
61 expect(err).to.be.null
62 expect(result).to.not.be.undefined
63 const keys = Object.keys(result)
64 keys.forEach((k) => expect(attrs).to.contain(k))
65 done()
66 })
67 })
68
69 it('should not return the controls attribute', function (done) {
70 ad.getRootDSE('ldap://127.0.0.1:1389', (err, result) => {
71 expect(err).to.be.null
72 expect(result).to.not.be.undefined
73 const keys = Object.keys(result)
74 expect(keys.indexOf('controls')).to.equal(-1)
75 done()
76 })
77 })
78})