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 Authentication', function () {
|
12 | let ad
|
13 | const settings = require('./settings').authenticate
|
14 | const LDAP_INVALID_CREDENTIALS = 49
|
15 |
|
16 | before(function (done) {
|
17 | server(function (s) {
|
18 | ad = new ActiveDirectory(config)
|
19 | server = s
|
20 | done()
|
21 | })
|
22 | })
|
23 |
|
24 | describe('#authenticate()', function () {
|
25 | it('should return true if the username (distinguishedName) and password are correct', function (done) {
|
26 | ad.authenticate(settings.username.dn, settings.password)
|
27 | .then((auth) => {
|
28 | expect(auth).to.be.true
|
29 | done()
|
30 | })
|
31 | .catch(done)
|
32 | })
|
33 |
|
34 | it('should return true if the username (userPrincipalName) and password are correct', function (done) {
|
35 | ad.authenticate(settings.username.userPrincipalName, settings.password)
|
36 | .then((auth) => {
|
37 | expect(auth).to.be.true
|
38 | done()
|
39 | })
|
40 | .catch(done)
|
41 | })
|
42 |
|
43 | it('should return true if the username (DOMAIN\\username) and password are correct', function (done) {
|
44 | ad.authenticate(settings.username.domainUsername, settings.password)
|
45 | .then((auth) => {
|
46 | expect(auth).to.be.true
|
47 | done()
|
48 | })
|
49 | .catch(done)
|
50 | })
|
51 |
|
52 | it('should return empty or null err if the username and password are correct', function (done) {
|
53 | ad.authenticate(settings.username.domainUsername, settings.password)
|
54 | .then((auth) => {
|
55 | expect(auth).to.be.true
|
56 | done()
|
57 | })
|
58 | .catch(done)
|
59 | })
|
60 |
|
61 | it('should return false if username is null', function (done) {
|
62 | ad.authenticate(null, settings.password)
|
63 | .then((auth) => {
|
64 | expect(auth).to.be.false
|
65 | done()
|
66 | })
|
67 | .catch((err) => {
|
68 | expect(err).to.be.an('object')
|
69 | expect(err.code).to.exist
|
70 | expect(err.code).to.equal(LDAP_INVALID_CREDENTIALS)
|
71 | done()
|
72 | })
|
73 | })
|
74 |
|
75 | it('should return false if username is an empty string.', function (done) {
|
76 | ad.authenticate('', settings.password)
|
77 | .then((auth) => {
|
78 | expect(auth).to.be.false
|
79 | done()
|
80 | })
|
81 | .catch((err) => {
|
82 | expect(err).to.be.an('object')
|
83 | expect(err.code).to.exist
|
84 | expect(err.code).to.equal(LDAP_INVALID_CREDENTIALS)
|
85 | done()
|
86 | })
|
87 | })
|
88 |
|
89 | it('should return err with LDAP_INVALID_CREDENTIALS if username and password are incorrect', function (done) {
|
90 | ad.authenticate('CN=invalid,DC=domain,DC=com', '!!!INVALID PASSWORD!!!')
|
91 | .then((auth) => {
|
92 | expect(auth).to.be.false
|
93 | done()
|
94 | })
|
95 | .catch((err) => {
|
96 | expect(err).to.be.an('object')
|
97 | expect(err.code).to.exist
|
98 | expect(err.code).to.equal(LDAP_INVALID_CREDENTIALS)
|
99 | done()
|
100 | })
|
101 | })
|
102 | })
|
103 | })
|