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('entryParser', function () {
|
12 | let ad
|
13 | const settings = require('./settings').findUser
|
14 |
|
15 | before(function (done) {
|
16 | server(function (s) {
|
17 | server = s
|
18 | done()
|
19 | })
|
20 | })
|
21 |
|
22 | it('should return objectSid as human readable string from default entryParser', function (done) {
|
23 | ad = new ActiveDirectory(config)
|
24 | const opts = {
|
25 | attributes: ['objectSid']
|
26 | }
|
27 | ad.findUser(opts, settings.username.userPrincipalName, function (err, user) {
|
28 | expect(err).to.be.null
|
29 | expect(user.objectSid).to.not.be.undefined
|
30 | expect(user.objectSid).to.be.string
|
31 | done()
|
32 | })
|
33 | })
|
34 |
|
35 | it('should return custom attribute set by custom entryParser in global config', function (done) {
|
36 | config.entryParser = function (entry, raw, cb) {
|
37 | entry.foobar = true
|
38 | cb(entry)
|
39 | }
|
40 | ad = new ActiveDirectory(config)
|
41 | const opts = {
|
42 | attributes: ['foobar']
|
43 | }
|
44 | ad.findUser(opts, settings.username.userPrincipalName, function (err, user) {
|
45 | expect(err).to.be.null
|
46 | expect(user.foobar).to.be.true
|
47 | done()
|
48 | })
|
49 | })
|
50 |
|
51 | it('should return custom attribute set by custom entryParser in local config', function (done) {
|
52 | ad = new ActiveDirectory(config)
|
53 | const opts = {
|
54 | attributes: ['foobar'],
|
55 | entryParser: function (entry, raw, cb) {
|
56 | entry.foobar = true
|
57 | cb(entry)
|
58 | }
|
59 | }
|
60 | ad.findUser(opts, settings.username.userPrincipalName, function (err, user) {
|
61 | expect(err).to.be.null
|
62 | expect(user.foobar).to.be.true
|
63 | done()
|
64 | })
|
65 | })
|
66 | })
|