Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 41c3c01

Browse files
authored
Merge pull request #674 from UziTech/update-standard
2 parents b796afe + c6fa259 commit 41c3c01

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+749
-747
lines changed

examples/inmemory.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
var ldap = require('../lib/index')
1+
const ldap = require('../lib/index')
22

33
/// --- Shared handlers
44

55
function authorize (req, res, next) {
66
/* Any user may search after bind, only cn=root has full power */
7-
var isSearch = (req instanceof ldap.SearchRequest)
7+
const isSearch = (req instanceof ldap.SearchRequest)
88
if (!req.connection.ldap.bindDN.equals('cn=root') && !isSearch) { return next(new ldap.InsufficientAccessRightsError()) }
99

1010
return next()
1111
}
1212

1313
/// --- Globals
1414

15-
var SUFFIX = 'o=smartdc'
16-
var db = {}
17-
var server = ldap.createServer()
15+
const SUFFIX = 'o=smartdc'
16+
const db = {}
17+
const server = ldap.createServer()
1818

1919
server.bind('cn=root', function (req, res, next) {
2020
if (req.dn.toString() !== 'cn=root' || req.credentials !== 'secret') { return next(new ldap.InvalidCredentialsError()) }
@@ -24,7 +24,7 @@ server.bind('cn=root', function (req, res, next) {
2424
})
2525

2626
server.add(SUFFIX, authorize, function (req, res, next) {
27-
var dn = req.dn.toString()
27+
const dn = req.dn.toString()
2828

2929
if (db[dn]) { return next(new ldap.EntryAlreadyExistsError(dn)) }
3030

@@ -34,7 +34,7 @@ server.add(SUFFIX, authorize, function (req, res, next) {
3434
})
3535

3636
server.bind(SUFFIX, function (req, res, next) {
37-
var dn = req.dn.toString()
37+
const dn = req.dn.toString()
3838
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
3939

4040
if (!db[dn].userpassword) { return next(new ldap.NoSuchAttributeError('userPassword')) }
@@ -46,14 +46,14 @@ server.bind(SUFFIX, function (req, res, next) {
4646
})
4747

4848
server.compare(SUFFIX, authorize, function (req, res, next) {
49-
var dn = req.dn.toString()
49+
const dn = req.dn.toString()
5050
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
5151

5252
if (!db[dn][req.attribute]) { return next(new ldap.NoSuchAttributeError(req.attribute)) }
5353

54-
var matches = false
55-
var vals = db[dn][req.attribute]
56-
for (var i = 0; i < vals.length; i++) {
54+
let matches = false
55+
const vals = db[dn][req.attribute]
56+
for (let i = 0; i < vals.length; i++) {
5757
if (vals[i] === req.value) {
5858
matches = true
5959
break
@@ -65,7 +65,7 @@ server.compare(SUFFIX, authorize, function (req, res, next) {
6565
})
6666

6767
server.del(SUFFIX, authorize, function (req, res, next) {
68-
var dn = req.dn.toString()
68+
const dn = req.dn.toString()
6969
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
7070

7171
delete db[dn]
@@ -75,14 +75,14 @@ server.del(SUFFIX, authorize, function (req, res, next) {
7575
})
7676

7777
server.modify(SUFFIX, authorize, function (req, res, next) {
78-
var dn = req.dn.toString()
78+
const dn = req.dn.toString()
7979
if (!req.changes.length) { return next(new ldap.ProtocolError('changes required')) }
8080
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
8181

82-
var entry = db[dn]
82+
const entry = db[dn]
8383

8484
let mod
85-
for (var i = 0; i < req.changes.length; i++) {
85+
for (let i = 0; i < req.changes.length; i++) {
8686
mod = req.changes[i].modification
8787
switch (req.changes[i].operation) {
8888
case 'replace':
@@ -121,10 +121,10 @@ server.modify(SUFFIX, authorize, function (req, res, next) {
121121
})
122122

123123
server.search(SUFFIX, authorize, function (req, res, next) {
124-
var dn = req.dn.toString()
124+
const dn = req.dn.toString()
125125
if (!db[dn]) { return next(new ldap.NoSuchObjectError(dn)) }
126126

127-
var scopeCheck
127+
let scopeCheck
128128

129129
switch (req.scope) {
130130
case 'base':
@@ -142,7 +142,7 @@ server.search(SUFFIX, authorize, function (req, res, next) {
142142
scopeCheck = function (k) {
143143
if (req.dn.equals(k)) { return true }
144144

145-
var parent = ldap.parseDN(k).parent()
145+
const parent = ldap.parseDN(k).parent()
146146
return (parent ? parent.equals(req.dn) : false)
147147
}
148148
break

lib/assert.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright 2015 Joyent, Inc.
22

3-
var assert = require('assert')
4-
var util = require('util')
3+
const assert = require('assert')
4+
const util = require('util')
55

6-
var isDN = require('./dn').DN.isDN
7-
var isAttribute = require('./attribute').isAttribute
6+
const isDN = require('./dn').DN.isDN
7+
const isAttribute = require('./attribute').isAttribute
88

99
/// --- Helpers
1010

lib/attribute.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
22

3-
var assert = require('assert')
3+
const assert = require('assert')
44

5-
var asn1 = require('asn1')
5+
const asn1 = require('asn1')
66

7-
var Protocol = require('./protocol')
7+
const Protocol = require('./protocol')
88

99
/// --- API
1010

@@ -42,13 +42,13 @@ Object.defineProperties(Attribute.prototype, {
4242
},
4343
vals: {
4444
get: function getVals () {
45-
var eType = _bufferEncoding(this.type)
45+
const eType = _bufferEncoding(this.type)
4646
return this._vals.map(function (v) {
4747
return v.toString(eType)
4848
})
4949
},
5050
set: function setVals (vals) {
51-
var self = this
51+
const self = this
5252
this._vals = []
5353
if (Array.isArray(vals)) {
5454
vals.forEach(function (v) {
@@ -81,7 +81,7 @@ Attribute.compare = function compare (a, b) {
8181
if (a.vals.length < b.vals.length) return -1
8282
if (a.vals.length > b.vals.length) return 1
8383

84-
for (var i = 0; i < a.vals.length; i++) {
84+
for (let i = 0; i < a.vals.length; i++) {
8585
if (a.vals[i] < b.vals[i]) return -1
8686
if (a.vals[i] > b.vals[i]) return 1
8787
}
@@ -98,7 +98,7 @@ Attribute.prototype.parse = function parse (ber) {
9898

9999
if (ber.peek() === Protocol.LBER_SET) {
100100
if (ber.readSequence(Protocol.LBER_SET)) {
101-
var end = ber.offset + ber.length
101+
const end = ber.offset + ber.length
102102
while (ber.offset < end) { this._vals.push(ber.readString(asn1.Ber.OctetString, true)) }
103103
}
104104
}
@@ -116,7 +116,7 @@ Attribute.prototype.toBer = function toBer (ber) {
116116
this._vals.forEach(function (b) {
117117
ber.writeByte(asn1.Ber.OctetString)
118118
ber.writeLength(b.length)
119-
for (var i = 0; i < b.length; i++) { ber.writeByte(b[i]) }
119+
for (let i = 0; i < b.length; i++) { ber.writeByte(b[i]) }
120120
})
121121
} else {
122122
ber.writeStringArray([])

lib/change.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
22

3-
var assert = require('assert-plus')
3+
const assert = require('assert-plus')
44

5-
var Attribute = require('./attribute')
5+
const Attribute = require('./attribute')
66
// var Protocol = require('./protocol')
77

88
/// --- API
@@ -68,15 +68,15 @@ Object.defineProperties(Change.prototype, {
6868
return
6969
}
7070

71-
var keys = Object.keys(val)
71+
const keys = Object.keys(val)
7272
if (keys.length > 1) {
7373
throw new Error('Only one attribute per Change allowed')
7474
} else if (keys.length === 0) {
7575
return
7676
}
7777

78-
var k = keys[0]
79-
var _attr = new Attribute({ type: k })
78+
const k = keys[0]
79+
const _attr = new Attribute({ type: k })
8080
if (Array.isArray(val[k])) {
8181
val[k].forEach(function (v) {
8282
_attr.addValue(v.toString())
@@ -136,9 +136,9 @@ Change.apply = function apply (change, obj, scalar) {
136136
assert.ok(Array.isArray(change.modification.vals))
137137
assert.object(obj)
138138

139-
var type = change.modification.type
140-
var vals = change.modification.vals
141-
var data = obj[type]
139+
const type = change.modification.type
140+
const vals = change.modification.vals
141+
let data = obj[type]
142142
if (data !== undefined) {
143143
if (!Array.isArray(data)) {
144144
data = [data]
@@ -156,13 +156,14 @@ Change.apply = function apply (change, obj, scalar) {
156156
data = vals
157157
}
158158
break
159-
case 'add':
159+
case 'add': {
160160
// add only new unique entries
161-
var newValues = vals.filter(function (entry) {
161+
const newValues = vals.filter(function (entry) {
162162
return (data.indexOf(entry) === -1)
163163
})
164164
data = data.concat(newValues)
165165
break
166+
}
166167
case 'delete':
167168
data = data.filter(function (entry) {
168169
return (vals.indexOf(entry) === -1)

0 commit comments

Comments
 (0)