1 | 'use strict'
|
2 |
|
3 |
|
4 |
|
5 | const expect = require('chai').expect
|
6 | const ldapjs = require('ldapjs')
|
7 | const ActiveDirectory = require('../index')
|
8 |
|
9 | describe('Network Connections', function () {
|
10 | const username = 'username'
|
11 | const password = 'password'
|
12 |
|
13 | describe('#authenticate()', function () {
|
14 | it('should return err (ENOTFOUND) on invalid hostname (dns)', function (done) {
|
15 | const ad = new ActiveDirectory({
|
16 | url: 'ldap://invalid.domain.net'
|
17 | })
|
18 | ad.authenticate(username, password, function (err, auth) {
|
19 | expect(err).to.be.an.instanceof(Error)
|
20 | expect(err.code).to.equal('ENOTFOUND')
|
21 | expect(auth).to.be.false
|
22 | done()
|
23 | })
|
24 | })
|
25 |
|
26 | it('should return err (ECONNREFUSED) on non listening port', function (done) {
|
27 | const ad = new ActiveDirectory({
|
28 | url: 'ldap://127.0.0.1:65535/'
|
29 | })
|
30 | ad.authenticate(username, password, function (err, auth) {
|
31 | expect(err).to.be.an.instanceof(Error)
|
32 | expect(err.code).to.equal('ECONNREFUSED')
|
33 | expect(auth).to.be.false
|
34 | done()
|
35 | })
|
36 | })
|
37 |
|
38 | it('should return err (ConnectionError) when connection timeouts', function (done) {
|
39 | const ad = new ActiveDirectory({
|
40 | url: 'ldap://example.com',
|
41 | connectTimeout: 1
|
42 | })
|
43 | ad.authenticate(username, password, function (err, auth) {
|
44 | expect(err).to.be.an.instanceOf(ldapjs.ConnectionError)
|
45 | expect(auth).to.be.false
|
46 | done()
|
47 | })
|
48 | })
|
49 | })
|
50 | })
|