chore(lint): lint lib/

This commit is contained in:
Tony Brix 2020-12-05 17:58:13 -06:00
parent 9ac1daaea5
commit 2489d87079
3 changed files with 43 additions and 43 deletions

View File

@ -418,25 +418,25 @@ Client.prototype.modify = function modify (name, change, controls, callback) {
const changes = [] const changes = []
function changeFromObject (change) { function changeFromObject (obj) {
if (!change.operation && !change.type) { throw new Error('change.operation required') } if (!obj.operation && !obj.type) { throw new Error('change.operation required') }
if (typeof (change.modification) !== 'object') { throw new Error('change.modification (object) required') } if (typeof (obj.modification) !== 'object') { throw new Error('change.modification (object) required') }
if (Object.keys(change.modification).length === 2 && if (Object.keys(obj.modification).length === 2 &&
typeof (change.modification.type) === 'string' && typeof (obj.modification.type) === 'string' &&
Array.isArray(change.modification.vals)) { Array.isArray(obj.modification.vals)) {
// Use modification directly if it's already normalized: // Use modification directly if it's already normalized:
changes.push(new Change({ changes.push(new Change({
operation: change.operation || change.type, operation: obj.operation || obj.type,
modification: change.modification modification: obj.modification
})) }))
} else { } else {
// Normalize the modification object // Normalize the modification object
Object.keys(change.modification).forEach(function (k) { Object.keys(obj.modification).forEach(function (k) {
const mod = {} const mod = {}
mod[k] = change.modification[k] mod[k] = obj.modification[k]
changes.push(new Change({ changes.push(new Change({
operation: change.operation || change.type, operation: obj.operation || obj.type,
modification: mod modification: mod
})) }))
}) })
@ -679,9 +679,9 @@ Client.prototype.starttls = function starttls (options,
return callback(new Error('STARTTLS already in progress or active')) return callback(new Error('STARTTLS already in progress or active'))
} }
function onSend (err, emitter) { function onSend (sendErr, emitter) {
if (err) { if (sendErr) {
callback(err) callback(sendErr)
return return
} }
/* /*
@ -850,9 +850,9 @@ Client.prototype.connect = function connect () {
} }
// Initialize socket events and LDAP parser. // Initialize socket events and LDAP parser.
function initSocket (url) { function initSocket (server) {
tracker = messageTrackerFactory({ tracker = messageTrackerFactory({
id: url ? url.href : self.socketPath, id: server ? server.href : self.socketPath,
parser: new Parser({ log: log }) parser: new Parser({ log: log })
}) })

View File

@ -16,8 +16,8 @@ const { MAX_MSGID } = require('../constants')
module.exports = function idGeneratorFactory (start = 0) { module.exports = function idGeneratorFactory (start = 0) {
let currentID = start let currentID = start
return function nextID () { return function nextID () {
const nextID = currentID + 1 const id = currentID + 1
currentID = (nextID >= MAX_MSGID) ? 1 : nextID currentID = (id >= MAX_MSGID) ? 1 : id
return currentID return currentID
} }
} }

View File

@ -313,28 +313,28 @@ function Server (options) {
return c return c
} }
function newConnection (c) { function newConnection (conn) {
setupConnection(c) setupConnection(conn)
log.trace('new connection from %s', c.ldap.id) log.trace('new connection from %s', conn.ldap.id)
dtrace.fire('server-connection', function () { dtrace.fire('server-connection', function () {
return [c.remoteAddress] return [conn.remoteAddress]
}) })
c.parser = new Parser({ conn.parser = new Parser({
log: options.log log: options.log
}) })
c.parser.on('message', function (req) { conn.parser.on('message', function (req) {
req.connection = c req.connection = conn
req.logId = c.ldap.id + '::' + req.messageID req.logId = conn.ldap.id + '::' + req.messageID
req.startTime = new Date().getTime() req.startTime = new Date().getTime()
log.debug('%s: message received: req=%j', c.ldap.id, req.json) log.debug('%s: message received: req=%j', conn.ldap.id, req.json)
const res = getResponse(req) const res = getResponse(req)
if (!res) { if (!res) {
log.warn('Unimplemented server method: %s', req.type) log.warn('Unimplemented server method: %s', req.type)
c.destroy() conn.destroy()
return false return false
} }
@ -368,7 +368,7 @@ function Server (options) {
} }
} }
res.connection = c res.connection = conn
res.logId = req.logId res.logId = req.logId
res.requestDN = req.dn res.requestDN = req.dn
@ -376,10 +376,10 @@ function Server (options) {
let i = 0 let i = 0
return (function messageIIFE (err) { return (function messageIIFE (err) {
function sendError (err) { function sendError (sendErr) {
res.status = err.code || errors.LDAP_OPERATIONS_ERROR res.status = sendErr.code || errors.LDAP_OPERATIONS_ERROR
res.matchedDN = req.suffix ? req.suffix.toString() : '' res.matchedDN = req.suffix ? req.suffix.toString() : ''
res.errorMessage = err.message || '' res.errorMessage = sendErr.message || ''
return res.end() return res.end()
} }
@ -388,8 +388,8 @@ function Server (options) {
function next () {} // stub out next for the post chain function next () {} // stub out next for the post chain
self._postChain.forEach(function (c) { self._postChain.forEach(function (cb) {
c.call(self, req, res, next) cb.call(self, req, res, next)
}) })
} }
@ -404,7 +404,7 @@ function Server (options) {
const next = messageIIFE const next = messageIIFE
if (chain.handlers[i]) { return chain.handlers[i++].call(chain.backend, req, res, next) } if (chain.handlers[i]) { return chain.handlers[i++].call(chain.backend, req, res, next) }
if (req.protocolOp === Protocol.LDAP_REQ_BIND && res.status === 0) { c.ldap.bindDN = req.dn } if (req.protocolOp === Protocol.LDAP_REQ_BIND && res.status === 0) { conn.ldap.bindDN = req.dn }
return after() return after()
} catch (e) { } catch (e) {
@ -415,23 +415,23 @@ function Server (options) {
}()) }())
}) })
c.parser.on('error', function (err, message) { conn.parser.on('error', function (err, message) {
self.emit('error', new VError(err, 'Parser error for %s', c.ldap.id)) self.emit('error', new VError(err, 'Parser error for %s', conn.ldap.id))
if (!message) { return c.destroy() } if (!message) { return conn.destroy() }
const res = getResponse(message) const res = getResponse(message)
if (!res) { return c.destroy() } if (!res) { return conn.destroy() }
res.status = 0x02 // protocol error res.status = 0x02 // protocol error
res.errorMessage = err.toString() res.errorMessage = err.toString()
return c.end(res.toBer()) return conn.end(res.toBer())
}) })
c.on('data', function (data) { conn.on('data', function (data) {
log.trace('data on %s: %s', c.ldap.id, util.inspect(data)) log.trace('data on %s: %s', conn.ldap.id, util.inspect(data))
c.parser.write(data) conn.parser.write(data)
}) })
} // end newConnection } // end newConnection