Initial setup for 0.5 (use eng.git layout)

This commit is contained in:
Mark Cavage 2012-02-18 08:15:52 +00:00
parent 4df59978ce
commit afeb354eac
106 changed files with 1180 additions and 2030 deletions

6
.dir-locals.el Normal file
View File

@ -0,0 +1,6 @@
((nil . ((indent-tabs-mode . nil)
(tab-width . 8)
(fill-column . 80)))
(js-mode . ((js-indent-level . 2)
(indent-tabs-mode . nil)
)))

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
build
node_modules node_modules
*.log *.log
*.ldif *.ldif
*.tar* *.tar*
docs/pkg

9
.gitmodules vendored Normal file
View File

@ -0,0 +1,9 @@
[submodule "deps/javascriptlint"]
path = deps/javascriptlint
url = https://github.com/davepacheco/javascriptlint
[submodule "deps/jsstyle"]
path = deps/jsstyle
url = https://github.com/davepacheco/jsstyle
[submodule "deps/restdown"]
path = deps/restdown
url = https://github.com/trentm/restdown

120
Makefile
View File

@ -1,85 +1,49 @@
#
# Copyright (c) 2012, Joyent, Inc. All rights reserved.
#
# Makefile: basic Makefile for template API service
#
# This Makefile is a template for new repos. It contains only repo-specific
# logic and uses included makefiles to supply common targets (javascriptlint,
# jsstyle, restdown, etc.), which are used by other repos as well. You may well
# need to rewrite most of this file, but you shouldn't need to touch the
# included makefiles.
#
# If you find yourself adding support for new targets that could be useful for
# other projects too, you should add these to the original versions of the
# included Makefiles (in eng.git) so that other teams can use them too.
#
ifeq ($(VERSION), "") #
@echo "Use gmake" # Tools
endif #
NPM := npm
TAP := ./node_modules/.bin/tap
#
# Files
#
DOC_FILES = client.md \
dn.md \
errors.md \
examples.md \
filters.md
DOCPKGDIR = ./docs/pkg JS_FILES := $(shell find lib test -name '*.js')
HAVE_GJSLINT := $(shell which gjslint >/dev/null && echo yes || echo no) JSL_CONF_NODE = tools/jsl.node.conf
LINT = ./node_modules/.javascriptlint/build/install/jsl --conf ./tools/jsl.conf JSL_FILES_NODE = $(JS_FILES)
NAME=ldapjs JSSTYLE_FILES = $(JS_FILES)
RESTDOWN_VERSION=1.2.13 JSSTYLE_FLAGS = -f tools/jsstyle.conf
SRC := $(shell pwd)
TAR = tar
UNAME := $(shell uname)
ifeq ($(UNAME), SunOS)
TAR = gtar
endif
NPM := npm_config_tar=$(TAR) npm
RESTDOWN = ./node_modules/.restdown/bin/restdown \ # Repo-specific targets
-b ./docs/branding \ #
-m ${DOCPKGDIR} \ .PHONY: all
-D mediaroot=media all:
.PHONY: dep lint test doc clean all install
all:: test doc
node_modules/.ldapjs.npm.installed:
$(NPM) install $(NPM) install
if [[ ! -d node_modules/.restdown ]]; then \
git clone git://github.com/trentm/restdown.git node_modules/.restdown; \
else \
(cd node_modules/.restdown && git fetch origin); \
fi
if [[ ! -d node_modules/.javascriptlint ]]; then \ .PHONY: test
git clone https://github.com/davepacheco/javascriptlint node_modules/.javascriptlint; \ test: $(TAP)
else \ $(TAP) test/*.test.js
(cd node_modules/.javascriptlint && git fetch origin); \
fi
@(cd ./node_modules/.restdown && git checkout $(RESTDOWN_VERSION)) include ./Makefile.deps
@(cd ./node_modules/.javascriptlint && $(MAKE) install) include ./Makefile.targ
@touch ./node_modules/.ldapjs.npm.installed
dep: ./node_modules/.ldapjs.npm.installed
install: dep
gjslint:
gjslint --nojsdoc -r lib -r tst
ifeq ($(HAVE_GJSLINT), yes)
lint: install gjslint
${LINT} --recurse lib/*.js
else
lint: install
@echo "* * *"
@echo "* Warning: Cannot lint with gjslint. Install it from:"
@echo "* http://code.google.com/closure/utilities/docs/linter_howto.html"
@echo "* * *"
${LINT} --recurse lib/*.js
endif
doc: dep
@rm -rf ${DOCPKGDIR}
@mkdir -p ${DOCPKGDIR}
${RESTDOWN} ./docs/client.md
${RESTDOWN} ./docs/dn.md
${RESTDOWN} ./docs/errors.md
${RESTDOWN} ./docs/examples.md
${RESTDOWN} ./docs/filters.md
${RESTDOWN} ./docs/guide.md
${RESTDOWN} ./docs/index.md
${RESTDOWN} ./docs/server.md
rm docs/*.json
mv docs/*.html ${DOCPKGDIR}
(cd ${DOCPKGDIR} && $(TAR) -czf ${SRC}/${NAME}-docs-`git log -1 --pretty='format:%h'`.tar.gz *)
test: dep lint
$(NPM) test
clean:
@rm -fr ${DOCPKGDIR} *.log *.tar.gz

46
Makefile.deps Normal file
View File

@ -0,0 +1,46 @@
#
# Copyright (c) 2012, Joyent, Inc. All rights reserved.
#
# Makefile.deps: Makefile for including common tools as dependencies
#
#
# javascriptlint
#
JSL_SCRIPT = deps/javascriptlint/build/install/jsl
JSL = python $(JSL_SCRIPT)
$(JSL_SCRIPT): | deps/javascriptlint/.git
cd deps/javascriptlint && make install
deps/javascriptlint/.git:
git submodule update --init deps/javascriptlint
#
# jsstyle
#
JSSTYLE_SCRIPT = deps/jsstyle/jsstyle
JSSTYLE = $(JSSTYLE_SCRIPT)
deps/jsstyle/jsstyle:
git submodule update --init deps/jsstyle
#
# restdown
#
RESTDOWN = python deps/restdown/bin/restdown
$(RESTDOWN): | deps/restdown/.git
deps/restdown/.git:
git submodule update --init deps/restdown
#
# The restdown submodule should be updated before we build "docs".
#
docs: $(RESTDOWN)
#
# JSL and JSSTYLE must be around before we build "check".
#
check: $(JSL_SCRIPT) $(JSSTYLE)

1
deps/javascriptlint vendored Submodule

@ -0,0 +1 @@
Subproject commit 5693fd3ce6f31f66f85bfde275ab64e609ea04d0

1
deps/jsstyle vendored Submodule

@ -0,0 +1 @@
Subproject commit ab8f1fc8d90db8484bbed8a526ff40add5aa1c15

1
deps/restdown vendored Submodule

@ -0,0 +1 @@
Subproject commit 14131f6b33bf45a04b4c66e388d0ce1f3e5b55ef

View File

@ -12,9 +12,9 @@ var Protocol = require('./protocol');
function Attribute(options) { function Attribute(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.type && typeof(options.type) !== 'string') if (options.type && typeof (options.type) !== 'string')
throw new TypeError('options.type must be a string'); throw new TypeError('options.type must be a string');
} else { } else {
options = {}; options = {};
@ -25,10 +25,11 @@ function Attribute(options) {
this.type = options.type || ''; this.type = options.type || '';
this._vals = []; this._vals = [];
this.__defineGetter__('vals', function() { this.__defineGetter__('vals', function () {
var _vals = []; var _vals = [];
self._vals.forEach(function(v) { self._vals.forEach(function (v) {
/* JSSTYLED */
if (/;binary$/.test(self.type)) { if (/;binary$/.test(self.type)) {
_vals.push(v.toString('base64')); _vals.push(v.toString('base64'));
} else { } else {
@ -39,9 +40,9 @@ function Attribute(options) {
return _vals; return _vals;
}); });
this.__defineSetter__('vals', function(vals) { this.__defineSetter__('vals', function (vals) {
if (Array.isArray(vals)) { if (Array.isArray(vals)) {
vals.forEach(function(v) { vals.forEach(function (v) {
self.addValue(v); self.addValue(v);
}); });
} else { } else {
@ -49,11 +50,11 @@ function Attribute(options) {
} }
}); });
this.__defineGetter__('buffers', function() { this.__defineGetter__('buffers', function () {
return self._vals; return self._vals;
}); });
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
return { return {
type: self.type, type: self.type,
vals: self.vals vals: self.vals
@ -67,11 +68,12 @@ function Attribute(options) {
module.exports = Attribute; module.exports = Attribute;
Attribute.prototype.addValue = function(val) { Attribute.prototype.addValue = function (val) {
if (Buffer.isBuffer(val)) { if (Buffer.isBuffer(val)) {
this._vals.push(val); this._vals.push(val);
} else { } else {
var encoding = 'utf8'; var encoding = 'utf8';
/* JSSTYLED */
if (/;binary$/.test(this.type)) if (/;binary$/.test(this.type))
encoding = 'base64'; encoding = 'base64';
this._vals.push(new Buffer(val + '', encoding)); this._vals.push(new Buffer(val + '', encoding));
@ -79,7 +81,8 @@ Attribute.prototype.addValue = function(val) {
}; };
Attribute.compare = function(a, b) { /* BEGIN JSSTYLED */
Attribute.compare = function compare(a, b) {
if (!(a instanceof Attribute) || !(b instanceof Attribute)) if (!(a instanceof Attribute) || !(b instanceof Attribute))
throw new TypeError('can only compare Attributes'); throw new TypeError('can only compare Attributes');
@ -95,9 +98,10 @@ Attribute.compare = function(a, b) {
return 0; return 0;
}; };
/* END JSSTYLED */
Attribute.prototype.parse = function(ber) { Attribute.prototype.parse = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.readSequence(); ber.readSequence();
@ -115,14 +119,14 @@ Attribute.prototype.parse = function(ber) {
}; };
Attribute.prototype.toBer = function(ber) { Attribute.prototype.toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.startSequence(); ber.startSequence();
ber.writeString(this.type); ber.writeString(this.type);
ber.startSequence(Protocol.LBER_SET); ber.startSequence(Protocol.LBER_SET);
if (this._vals.length) { if (this._vals.length) {
this._vals.forEach(function(b) { this._vals.forEach(function (b) {
ber.writeByte(asn1.Ber.OctetString); ber.writeByte(asn1.Ber.OctetString);
ber.writeLength(b.length); ber.writeLength(b.length);
for (var i = 0; i < b.length; i++) for (var i = 0; i < b.length; i++)
@ -137,26 +141,28 @@ Attribute.prototype.toBer = function(ber) {
return ber; return ber;
}; };
Attribute.toBer = function(attr, ber) { Attribute.toBer = function (attr, ber) {
return Attribute.prototype.toBer.call(attr, ber); return Attribute.prototype.toBer.call(attr, ber);
}; };
Attribute.isAttribute = function(attr) { /* BEGIN JSSTYLED */
Attribute.isAttribute = function (attr) {
if (!attr) return false; if (!attr) return false;
if (typeof(attr) !== 'object') return false; if (typeof (attr) !== 'object') return false;
if (attr instanceof Attribute) return true; if (attr instanceof Attribute) return true;
if (!attr.type || typeof(attr.type) !== 'string') return false; if (!attr.type || typeof (attr.type) !== 'string') return false;
if (!attr.vals || !Array.isArray(attr.vals)) return false; if (!attr.vals || !Array.isArray(attr.vals)) return false;
for (var i = 0; i < attr.vals.length; i++) { for (var i = 0; i < attr.vals.length; i++) {
if (typeof(attr.vals[i]) !== 'string' && !Buffer.isBuffer(attr.vals[i])) if (typeof (attr.vals[i]) !== 'string' && !Buffer.isBuffer(attr.vals[i]))
return false; return false;
} }
return true; return true;
}; };
/* END JSSTLYED */
Attribute.prototype.toString = function() { Attribute.prototype.toString = function () {
return JSON.stringify(this.json); return JSON.stringify(this.json);
}; };

View File

@ -11,16 +11,18 @@ var Protocol = require('./protocol');
function Change(options) { function Change(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.operation && typeof(options.operation) !== 'string') if (options.operation && typeof (options.operation) !== 'string')
throw new TypeError('options.operation must be a string'); throw new TypeError('options.operation must be a string');
} else { } else {
options = {}; options = {};
} }
var self = this; var self = this;
this.__defineGetter__('operation', function() { this._modification = false;
this.__defineGetter__('operation', function () {
switch (self._operation) { switch (self._operation) {
case 0x00: return 'add'; case 0x00: return 'add';
case 0x01: return 'delete'; case 0x01: return 'delete';
@ -29,8 +31,8 @@ function Change(options) {
throw new Error('0x' + self._operation.toString(16) + ' is invalid'); throw new Error('0x' + self._operation.toString(16) + ' is invalid');
} }
}); });
this.__defineSetter__('operation', function(val) { this.__defineSetter__('operation', function (val) {
if (typeof(val) !== 'string') if (typeof (val) !== 'string')
throw new TypeError('operation must be a string'); throw new TypeError('operation must be a string');
switch (val.toLowerCase()) { switch (val.toLowerCase()) {
@ -47,10 +49,11 @@ function Change(options) {
throw new Error('Invalid operation type: 0x' + val.toString(16)); throw new Error('Invalid operation type: 0x' + val.toString(16));
} }
}); });
this.__defineGetter__('modification', function() { this.__defineGetter__('modification', function () {
return self._modification; return self._modification;
}); });
this.__defineSetter__('modification', function(attr) {
this.__defineSetter__('modification', function (attr) {
if (Attribute.isAttribute(attr)) { if (Attribute.isAttribute(attr)) {
self._modification = attr; self._modification = attr;
return; return;
@ -59,10 +62,10 @@ function Change(options) {
if (keys.length > 1) if (keys.length > 1)
throw new Error('Only one attribute per Change allowed'); throw new Error('Only one attribute per Change allowed');
keys.forEach(function(k) { keys.forEach(function (k) {
var _attr = new Attribute({type: k}); var _attr = new Attribute({type: k});
if (Array.isArray(attr[k])) { if (Array.isArray(attr[k])) {
attr[k].forEach(function(v) { attr[k].forEach(function (v) {
_attr.addValue(v.toString()); _attr.addValue(v.toString());
}); });
} else { } else {
@ -71,7 +74,7 @@ function Change(options) {
self._modification = _attr; self._modification = _attr;
}); });
}); });
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
return { return {
operation: self.operation, operation: self.operation,
modification: self._modification ? self._modification.json : {} modification: self._modification ? self._modification.json : {}
@ -84,18 +87,20 @@ function Change(options) {
module.exports = Change; module.exports = Change;
Change.compare = function(a, b) { Change.compare = function (a, b) {
if (!(a instanceof Change) || !(b instanceof Change)) if (!(a instanceof Change) || !(b instanceof Change))
throw new TypeError('can only compare Changes'); throw new TypeError('can only compare Changes');
if (a.operation < b.operation) return -1; if (a.operation < b.operation)
if (a.operation > b.operation) return 1; return -1;
if (a.operation > b.operation)
return 1;
return Attribute.compare(a.modification, b.modification); return Attribute.compare(a.modification, b.modification);
}; };
Change.prototype.parse = function(ber) { Change.prototype.parse = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.readSequence(); ber.readSequence();
@ -107,7 +112,7 @@ Change.prototype.parse = function(ber) {
}; };
Change.prototype.toBer = function(ber) { Change.prototype.toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.startSequence(); ber.startSequence();

View File

@ -53,8 +53,11 @@ var MAX_MSGID = Math.pow(2, 31) - 1;
function xor() { function xor() {
var b = false; var b = false;
for (var i = 0; i < arguments.length; i++) { for (var i = 0; i < arguments.length; i++) {
if (arguments[i] && !b) b = true; if (arguments[i] && !b) {
else if (arguments[i] && b) return false; b = true;
} else if (arguments[i] && b) {
return false;
}
} }
return b; return b;
} }
@ -62,7 +65,7 @@ function xor() {
function validateControls(controls) { function validateControls(controls) {
if (Array.isArray(controls)) { if (Array.isArray(controls)) {
controls.forEach(function(c) { controls.forEach(function (c) {
if (!(c instanceof Control)) if (!(c instanceof Control))
throw new TypeError('controls must be [Control]'); throw new TypeError('controls must be [Control]');
}); });
@ -103,13 +106,13 @@ util.inherits(ConnectionError, errors.LDAPError);
* @throws {TypeError} on bad input. * @throws {TypeError} on bad input.
*/ */
function Client(options) { function Client(options) {
if (!options || typeof(options) !== 'object') if (!options || typeof (options) !== 'object')
throw new TypeError('options (object) required'); throw new TypeError('options (object) required');
if (options.url && typeof(options.url) !== 'string') if (options.url && typeof (options.url) !== 'string')
throw new TypeError('options.url (string) required'); throw new TypeError('options.url (string) required');
if (options.socketPath && typeof(options.socketPath) !== 'string') if (options.socketPath && typeof (options.socketPath) !== 'string')
throw new TypeError('options.socketPath must be a string'); throw new TypeError('options.socketPath must be a string');
if (options.log4js && typeof(options.log4js) !== 'object') if (options.log4js && typeof (options.log4js) !== 'object')
throw new TypeError('options.log4s must be an object'); throw new TypeError('options.log4s must be an object');
if (!xor(options.url, options.socketPath)) if (!xor(options.url, options.socketPath))
@ -132,19 +135,19 @@ function Client(options) {
socketPath: options.socketPath || undefined socketPath: options.socketPath || undefined
}; };
this.log4js = options.log4js || logStub; this.log4js = options.log4js || logStub;
this.reconnect = (typeof(options.reconnect) === 'number' ? this.reconnect = (typeof (options.reconnect) === 'number' ?
options.reconnect : 1000); options.reconnect : 1000);
this.shutdown = false; this.shutdown = false;
this.timeout = options.timeout || false; this.timeout = options.timeout || false;
this.__defineGetter__('log', function() { this.__defineGetter__('log', function () {
if (!self._log) if (!self._log)
self._log = self.log4js.getLogger('Client'); self._log = self.log4js.getLogger('Client');
return self._log; return self._log;
}); });
return this.connect(function() {}); return this.connect(function () {});
} }
util.inherits(Client, EventEmitter); util.inherits(Client, EventEmitter);
module.exports = Client; module.exports = Client;
@ -156,14 +159,14 @@ module.exports = Client;
* *
* @param {Function} callback invoked when `connect()` is done. * @param {Function} callback invoked when `connect()` is done.
*/ */
Client.prototype.connect = function(callback) { Client.prototype.connect = function (callback) {
if (this.connection) if (this.connection)
return callback(); return callback();
var self = this; var self = this;
var timer = false; var timer = false;
if (this.connectTimeout) { if (this.connectTimeout) {
timer = setTimeout(function() { timer = setTimeout(function () {
if (self.connection) if (self.connection)
self.connection.destroy(); self.connection.destroy();
@ -178,21 +181,24 @@ Client.prototype.connect = function(callback) {
function reconnect() { function reconnect() {
self.connection = null; self.connection = null;
if (self.reconnect) if (self.reconnect) {
setTimeout(function() { self.connect(function() {}); }, self.reconnect); setTimeout(function () {
self.connect(function () {});
}, self.reconnect);
}
} }
self.connection.on('close', function(had_err) { self.connection.on('close', function (had_err) {
self.emit('close', had_err); self.emit('close', had_err);
reconnect(); reconnect();
}); });
self.connection.on('connect', function() { self.connection.on('connect', function () {
if (timer) if (timer)
clearTimeout(timer); clearTimeout(timer);
if (self._bindDN && self._credentials) if (self._bindDN && self._credentials)
return self.bind(self._bindDN, self._credentials, function(err) { return self.bind(self._bindDN, self._credentials, function (err) {
if (err) { if (err) {
self.log.error('Unable to bind(on(\'connect\')): %s', err.stack); self.log.error('Unable to bind(on(\'connect\')): %s', err.stack);
self.connection.end(); self.connection.end();
@ -218,23 +224,23 @@ Client.prototype.connect = function(callback) {
* @param {Socket} conn don't use this. Internal only (reconnects). * @param {Socket} conn don't use this. Internal only (reconnects).
* @throws {TypeError} on invalid input. * @throws {TypeError} on invalid input.
*/ */
Client.prototype.bind = function(name, credentials, controls, callback, conn) { Client.prototype.bind = function (name, credentials, controls, callback, conn) {
if (typeof(name) !== 'string' && !(name instanceof dn.DN)) if (typeof (name) !== 'string' && !(name instanceof dn.DN))
throw new TypeError('name (string) required'); throw new TypeError('name (string) required');
if (typeof(credentials) !== 'string') if (typeof (credentials) !== 'string')
throw new TypeError('credentials (string) required'); throw new TypeError('credentials (string) required');
if (typeof(controls) === 'function') { if (typeof (controls) === 'function') {
callback = controls; callback = controls;
controls = []; controls = [];
} else { } else {
controls = validateControls(controls); controls = validateControls(controls);
} }
if (typeof(callback) !== 'function') if (typeof (callback) !== 'function')
throw new TypeError('callback (function) required'); throw new TypeError('callback (function) required');
var self = this; var self = this;
this.connect(function() { this.connect(function () {
var req = new BindRequest({ var req = new BindRequest({
name: name || '', name: name || '',
authentication: 'Simple', authentication: 'Simple',
@ -242,7 +248,7 @@ Client.prototype.bind = function(name, credentials, controls, callback, conn) {
controls: controls controls: controls
}); });
return self._send(req, [errors.LDAP_SUCCESS], function(err, res) { return self._send(req, [errors.LDAP_SUCCESS], function (err, res) {
if (!err) { // In case we need to reconnect later if (!err) { // In case we need to reconnect later
self._bindDN = name; self._bindDN = name;
self._credentials = credentials; self._credentials = credentials;
@ -265,16 +271,16 @@ Client.prototype.bind = function(name, credentials, controls, callback, conn) {
* @param {Function} callback of the form f(err). * @param {Function} callback of the form f(err).
* @throws {TypeError} on invalid input. * @throws {TypeError} on invalid input.
*/ */
Client.prototype.abandon = function(messageID, controls, callback) { Client.prototype.abandon = function (messageID, controls, callback) {
if (typeof(messageID) !== 'number') if (typeof (messageID) !== 'number')
throw new TypeError('messageID (number) required'); throw new TypeError('messageID (number) required');
if (typeof(controls) === 'function') { if (typeof (controls) === 'function') {
callback = controls; callback = controls;
controls = []; controls = [];
} else { } else {
controls = validateControls(controls); controls = validateControls(controls);
} }
if (typeof(callback) !== 'function') if (typeof (callback) !== 'function')
throw new TypeError('callback (function) required'); throw new TypeError('callback (function) required');
var req = new AbandonRequest({ var req = new AbandonRequest({
@ -299,22 +305,22 @@ Client.prototype.abandon = function(messageID, controls, callback) {
* @param {Function} callback of the form f(err, res). * @param {Function} callback of the form f(err, res).
* @throws {TypeError} on invalid input. * @throws {TypeError} on invalid input.
*/ */
Client.prototype.add = function(name, entry, controls, callback) { Client.prototype.add = function (name, entry, controls, callback) {
if (typeof(name) !== 'string') if (typeof (name) !== 'string')
throw new TypeError('name (string) required'); throw new TypeError('name (string) required');
if (typeof(entry) !== 'object') if (typeof (entry) !== 'object')
throw new TypeError('entry (object) required'); throw new TypeError('entry (object) required');
if (typeof(controls) === 'function') { if (typeof (controls) === 'function') {
callback = controls; callback = controls;
controls = []; controls = [];
} else { } else {
controls = validateControls(controls); controls = validateControls(controls);
} }
if (typeof(callback) !== 'function') if (typeof (callback) !== 'function')
throw new TypeError('callback (function) required'); throw new TypeError('callback (function) required');
if (Array.isArray(entry)) { if (Array.isArray(entry)) {
entry.forEach(function(a) { entry.forEach(function (a) {
if (!Attribute.isAttribute(a)) if (!Attribute.isAttribute(a))
throw new TypeError('entry must be an Array of Attributes'); throw new TypeError('entry must be an Array of Attributes');
}); });
@ -322,10 +328,10 @@ Client.prototype.add = function(name, entry, controls, callback) {
var save = entry; var save = entry;
entry = []; entry = [];
Object.keys(save).forEach(function(k) { Object.keys(save).forEach(function (k) {
var attr = new Attribute({type: k}); var attr = new Attribute({type: k});
if (Array.isArray(save[k])) { if (Array.isArray(save[k])) {
save[k].forEach(function(v) { save[k].forEach(function (v) {
attr.addValue(v.toString()); attr.addValue(v.toString());
}); });
} else { } else {
@ -355,20 +361,20 @@ Client.prototype.add = function(name, entry, controls, callback) {
* @param {Function} callback of the form f(err, boolean, res). * @param {Function} callback of the form f(err, boolean, res).
* @throws {TypeError} on invalid input. * @throws {TypeError} on invalid input.
*/ */
Client.prototype.compare = function(name, attr, value, controls, callback) { Client.prototype.compare = function (name, attr, value, controls, callback) {
if (typeof(name) !== 'string') if (typeof (name) !== 'string')
throw new TypeError('name (string) required'); throw new TypeError('name (string) required');
if (typeof(attr) !== 'string') if (typeof (attr) !== 'string')
throw new TypeError('attribute (string) required'); throw new TypeError('attribute (string) required');
if (typeof(value) !== 'string') if (typeof (value) !== 'string')
throw new TypeError('value (string) required'); throw new TypeError('value (string) required');
if (typeof(controls) === 'function') { if (typeof (controls) === 'function') {
callback = controls; callback = controls;
controls = []; controls = [];
} else { } else {
controls = validateControls(controls); controls = validateControls(controls);
} }
if (typeof(callback) !== 'function') if (typeof (callback) !== 'function')
throw new TypeError('callback (function) required'); throw new TypeError('callback (function) required');
var req = new CompareRequest({ var req = new CompareRequest({
@ -399,16 +405,16 @@ Client.prototype.compare = function(name, attr, value, controls, callback) {
* @param {Function} callback of the form f(err, res). * @param {Function} callback of the form f(err, res).
* @throws {TypeError} on invalid input. * @throws {TypeError} on invalid input.
*/ */
Client.prototype.del = function(name, controls, callback) { Client.prototype.del = function (name, controls, callback) {
if (typeof(name) !== 'string') if (typeof (name) !== 'string')
throw new TypeError('name (string) required'); throw new TypeError('name (string) required');
if (typeof(controls) === 'function') { if (typeof (controls) === 'function') {
callback = controls; callback = controls;
controls = []; controls = [];
} else { } else {
controls = validateControls(controls); controls = validateControls(controls);
} }
if (typeof(callback) !== 'function') if (typeof (callback) !== 'function')
throw new TypeError('callback (function) required'); throw new TypeError('callback (function) required');
var req = new DeleteRequest({ var req = new DeleteRequest({
@ -433,23 +439,23 @@ Client.prototype.del = function(name, controls, callback) {
* @param {Function} callback of the form f(err, value, res). * @param {Function} callback of the form f(err, value, res).
* @throws {TypeError} on invalid input. * @throws {TypeError} on invalid input.
*/ */
Client.prototype.exop = function(name, value, controls, callback) { Client.prototype.exop = function (name, value, controls, callback) {
if (typeof(name) !== 'string') if (typeof (name) !== 'string')
throw new TypeError('name (string) required'); throw new TypeError('name (string) required');
if (typeof(value) === 'function') { if (typeof (value) === 'function') {
callback = value; callback = value;
controls = []; controls = [];
value = ''; value = '';
} }
if (typeof(value) !== 'string') if (typeof (value) !== 'string')
throw new TypeError('value (string) required'); throw new TypeError('value (string) required');
if (typeof(controls) === 'function') { if (typeof (controls) === 'function') {
callback = controls; callback = controls;
controls = []; controls = [];
} else { } else {
controls = validateControls(controls); controls = validateControls(controls);
} }
if (typeof(callback) !== 'function') if (typeof (callback) !== 'function')
throw new TypeError('callback (function) required'); throw new TypeError('callback (function) required');
var req = new ExtendedRequest({ var req = new ExtendedRequest({
@ -478,10 +484,10 @@ Client.prototype.exop = function(name, value, controls, callback) {
* @param {Function} callback of the form f(err, res). * @param {Function} callback of the form f(err, res).
* @throws {TypeError} on invalid input. * @throws {TypeError} on invalid input.
*/ */
Client.prototype.modify = function(name, change, controls, callback) { Client.prototype.modify = function (name, change, controls, callback) {
if (typeof(name) !== 'string') if (typeof (name) !== 'string')
throw new TypeError('name (string) required'); throw new TypeError('name (string) required');
if (typeof(change) !== 'object') if (typeof (change) !== 'object')
throw new TypeError('change (Change) required'); throw new TypeError('change (Change) required');
var changes = []; var changes = [];
@ -489,10 +495,10 @@ Client.prototype.modify = function(name, change, controls, callback) {
function changeFromObject(change) { function changeFromObject(change) {
if (!change.operation && !change.type) if (!change.operation && !change.type)
throw new Error('change.operation required'); throw new Error('change.operation required');
if (typeof(change.modification) !== 'object') if (typeof (change.modification) !== 'object')
throw new Error('change.modification (object) required'); throw new Error('change.modification (object) required');
Object.keys(change.modification).forEach(function(k) { Object.keys(change.modification).forEach(function (k) {
var mod = {}; var mod = {};
mod[k] = change.modification[k]; mod[k] = change.modification[k];
changes.push(new Change({ changes.push(new Change({
@ -505,7 +511,7 @@ Client.prototype.modify = function(name, change, controls, callback) {
if (change instanceof Change) { if (change instanceof Change) {
changes.push(change); changes.push(change);
} else if (Array.isArray(change)) { } else if (Array.isArray(change)) {
change.forEach(function(c) { change.forEach(function (c) {
if (c instanceof Change) { if (c instanceof Change) {
changes.push(c); changes.push(c);
} else { } else {
@ -516,13 +522,13 @@ Client.prototype.modify = function(name, change, controls, callback) {
changeFromObject(change); changeFromObject(change);
} }
if (typeof(controls) === 'function') { if (typeof (controls) === 'function') {
callback = controls; callback = controls;
controls = []; controls = [];
} else { } else {
controls = validateControls(controls); controls = validateControls(controls);
} }
if (typeof(callback) !== 'function') if (typeof (callback) !== 'function')
throw new TypeError('callback (function) required'); throw new TypeError('callback (function) required');
var req = new ModifyRequest({ var req = new ModifyRequest({
@ -549,18 +555,18 @@ Client.prototype.modify = function(name, change, controls, callback) {
* @param {Function} callback of the form f(err, res). * @param {Function} callback of the form f(err, res).
* @throws {TypeError} on invalid input. * @throws {TypeError} on invalid input.
*/ */
Client.prototype.modifyDN = function(name, newName, controls, callback) { Client.prototype.modifyDN = function (name, newName, controls, callback) {
if (typeof(name) !== 'string') if (typeof (name) !== 'string')
throw new TypeError('name (string) required'); throw new TypeError('name (string) required');
if (typeof(newName) !== 'string') if (typeof (newName) !== 'string')
throw new TypeError('newName (string) required'); throw new TypeError('newName (string) required');
if (typeof(controls) === 'function') { if (typeof (controls) === 'function') {
callback = controls; callback = controls;
controls = []; controls = [];
} else { } else {
controls = validateControls(controls); controls = validateControls(controls);
} }
if (typeof(callback) !== 'function') if (typeof (callback) !== 'function')
throw new TypeError('callback (function) required'); throw new TypeError('callback (function) required');
var DN = dn.parse(name); var DN = dn.parse(name);
@ -606,24 +612,24 @@ Client.prototype.modifyDN = function(name, newName, controls, callback) {
* @param {Function} callback of the form f(err, res). * @param {Function} callback of the form f(err, res).
* @throws {TypeError} on invalid input. * @throws {TypeError} on invalid input.
*/ */
Client.prototype.search = function(base, options, controls, callback) { Client.prototype.search = function (base, options, controls, callback) {
if (typeof(base) !== 'string' && !(base instanceof dn.DN)) if (typeof (base) !== 'string' && !(base instanceof dn.DN))
throw new TypeError('base (string) required'); throw new TypeError('base (string) required');
if (Array.isArray(options) || (options instanceof Control)) { if (Array.isArray(options) || (options instanceof Control)) {
controls = options; controls = options;
options = {}; options = {};
} else if (typeof(options) === 'function') { } else if (typeof (options) === 'function') {
callback = options; callback = options;
controls = []; controls = [];
options = { options = {
filter: new PresenceFilter({attribute: 'objectclass'}) filter: new PresenceFilter({attribute: 'objectclass'})
}; };
} else if (typeof(options) === 'string') { } else if (typeof (options) === 'string') {
options = {filter: filters.parseString(options)}; options = {filter: filters.parseString(options)};
} else if (typeof(options) !== 'object') { } else if (typeof (options) !== 'object') {
throw new TypeError('options (object) required'); throw new TypeError('options (object) required');
} }
if (typeof(options.filter) === 'string') { if (typeof (options.filter) === 'string') {
options.filter = filters.parseString(options.filter); options.filter = filters.parseString(options.filter);
} else if (!options.filter) { } else if (!options.filter) {
options.filter = new PresenceFilter({attribute: 'objectclass'}); options.filter = new PresenceFilter({attribute: 'objectclass'});
@ -631,26 +637,26 @@ Client.prototype.search = function(base, options, controls, callback) {
throw new TypeError('options.filter (Filter) required'); throw new TypeError('options.filter (Filter) required');
} }
if (typeof(controls) === 'function') { if (typeof (controls) === 'function') {
callback = controls; callback = controls;
controls = []; controls = [];
} else { } else {
controls = validateControls(controls); controls = validateControls(controls);
} }
if (typeof(callback) !== 'function') if (typeof (callback) !== 'function')
throw new TypeError('callback (function) required'); throw new TypeError('callback (function) required');
if (options.attributes) { if (options.attributes) {
if (Array.isArray(options.attributes)) { if (!Array.isArray(options.attributes)) {
// noop if (typeof (options.attributes) === 'string') {
} else if (typeof(options.attributes) === 'string') { options.attributes = [options.attributes];
options.attributes = [options.attributes]; } else {
} else { throw new TypeError('options.attributes must be an Array of Strings');
throw new TypeError('options.attributes must be an Array of Strings'); }
} }
} }
var req = new SearchRequest({ var req = new SearchRequest({
baseObject: typeof(base) === 'string' ? dn.parse(base) : base, baseObject: typeof (base) === 'string' ? dn.parse(base) : base,
scope: options.scope || 'base', scope: options.scope || 'base',
filter: options.filter, filter: options.filter,
derefAliases: Protocol.NEVER_DEREF_ALIASES, derefAliases: Protocol.NEVER_DEREF_ALIASES,
@ -698,11 +704,11 @@ Client.prototype.search = function(base, options, controls, callback) {
* @param {Function} callback of the form f(err). * @param {Function} callback of the form f(err).
* @throws {TypeError} if you pass in callback as not a function. * @throws {TypeError} if you pass in callback as not a function.
*/ */
Client.prototype.unbind = function(callback) { Client.prototype.unbind = function (callback) {
if (callback && typeof(callback) !== 'function') if (callback && typeof (callback) !== 'function')
throw new TypeError('callback must be a function'); throw new TypeError('callback must be a function');
if (!callback) if (!callback)
callback = function() { self.log.trace('disconnected'); }; callback = function () { self.log.trace('disconnected'); };
var self = this; var self = this;
this.reconnect = false; this.reconnect = false;
@ -718,7 +724,7 @@ Client.prototype.unbind = function(callback) {
Client.prototype._send = function(message, expect, callback, connection) { Client.prototype._send = function (message, expect, callback, connection) {
assert.ok(message); assert.ok(message);
assert.ok(expect); assert.ok(expect);
assert.ok(callback); assert.ok(callback);
@ -734,7 +740,7 @@ Client.prototype._send = function(message, expect, callback, connection) {
err = err || new ConnectionError('no connection'); err = err || new ConnectionError('no connection');
if (typeof(callback) === 'function') { if (typeof (callback) === 'function') {
callback(err); callback(err);
} else { } else {
callback.emit('error', err); callback.emit('error', err);
@ -750,7 +756,7 @@ Client.prototype._send = function(message, expect, callback, connection) {
// Now set up the callback in the messages table // Now set up the callback in the messages table
message.messageID = conn.ldap.nextMessageID; message.messageID = conn.ldap.nextMessageID;
if (expect !== 'abandon') { if (expect !== 'abandon') {
conn.ldap.messages[message.messageID] = function(res) { conn.ldap.messages[message.messageID] = function (res) {
if (timer) if (timer)
clearTimeout(timer); clearTimeout(timer);
@ -764,13 +770,13 @@ Client.prototype._send = function(message, expect, callback, connection) {
if (expect.indexOf(res.status) === -1) { if (expect.indexOf(res.status) === -1) {
err = errors.getError(res); err = errors.getError(res);
if (typeof(callback) === 'function') if (typeof (callback) === 'function')
return callback(err); return callback(err);
return callback.emit('error', err); return callback.emit('error', err);
} }
if (typeof(callback) === 'function') if (typeof (callback) === 'function')
return callback(null, res); return callback(null, res);
callback.emit('end', res); callback.emit('end', res);
@ -783,7 +789,7 @@ Client.prototype._send = function(message, expect, callback, connection) {
callback.emit('searchReference', res); callback.emit('searchReference', res);
} else if (res instanceof Error) { } else if (res instanceof Error) {
if (typeof(callback) === 'function') if (typeof (callback) === 'function')
return callback(res); return callback(res);
assert.ok(callback instanceof EventEmitter); assert.ok(callback instanceof EventEmitter);
@ -792,7 +798,7 @@ Client.prototype._send = function(message, expect, callback, connection) {
delete conn.ldap.messages[message.messageID]; delete conn.ldap.messages[message.messageID];
err = new errors.ProtocolError(res.type); err = new errors.ProtocolError(res.type);
if (typeof(callback) === 'function') if (typeof (callback) === 'function')
return callback(err); return callback(err);
callback.emit('error', err); callback.emit('error', err);
@ -804,7 +810,7 @@ Client.prototype._send = function(message, expect, callback, connection) {
// If there's a user specified timeout, pick that up // If there's a user specified timeout, pick that up
if (this.timeout) { if (this.timeout) {
timer = setTimeout(function() { timer = setTimeout(function () {
self.emit('timeout', message); self.emit('timeout', message);
if (conn.ldap.messages[message.messageID]) if (conn.ldap.messages[message.messageID])
conn.ldap.messages[message.messageID](new LDAPResult({ conn.ldap.messages[message.messageID](new LDAPResult({
@ -819,11 +825,11 @@ Client.prototype._send = function(message, expect, callback, connection) {
// will never be a response // will never be a response
var _writeCb = null; var _writeCb = null;
if (expect === 'abandon') { if (expect === 'abandon') {
_writeCb = function() { _writeCb = function () {
return callback(); return callback();
}; };
} else if (expect === 'unbind') { } else if (expect === 'unbind') {
_writeCb = function() { _writeCb = function () {
conn.unbindMessageID = message.id; conn.unbindMessageID = message.id;
conn.end(); conn.end();
}; };
@ -839,14 +845,14 @@ Client.prototype._send = function(message, expect, callback, connection) {
}; };
Client.prototype._newConnection = function() { Client.prototype._newConnection = function () {
var c; var c;
var connectOpts = this.connectOptions; var connectOpts = this.connectOptions;
var log = this.log; var log = this.log;
var self = this; var self = this;
if (this.secure) { if (this.secure) {
c = tls.connect(connectOpts.port, connectOpts.host, function() { c = tls.connect(connectOpts.port, connectOpts.host, function () {
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace('%s connect event', c.ldap.id); log.trace('%s connect event', c.ldap.id);
@ -854,7 +860,7 @@ Client.prototype._newConnection = function() {
c.ldap.id += c.fd ? (':' + c.fd) : ''; c.ldap.id += c.fd ? (':' + c.fd) : '';
c.emit('connect', c.ldap.id); c.emit('connect', c.ldap.id);
}); });
c.setKeepAlive = function(enable, delay) { c.setKeepAlive = function (enable, delay) {
return c.socket.setKeepAlive(enable, delay); return c.socket.setKeepAlive(enable, delay);
}; };
} else { } else {
@ -873,13 +879,13 @@ Client.prototype._newConnection = function() {
messages: {} messages: {}
}; };
c.ldap.__defineGetter__('nextMessageID', function() { c.ldap.__defineGetter__('nextMessageID', function () {
if (++c.ldap.messageID >= MAX_MSGID) if (++c.ldap.messageID >= MAX_MSGID)
c.ldap.messageID = 1; c.ldap.messageID = 1;
return c.ldap.messageID; return c.ldap.messageID;
}); });
c.on('connect', function() { c.on('connect', function () {
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace('%s connect event', c.ldap.id); log.trace('%s connect event', c.ldap.id);
@ -888,18 +894,18 @@ Client.prototype._newConnection = function() {
self.emit('connect', c.ldap.id); self.emit('connect', c.ldap.id);
}); });
c.on('end', function() { c.on('end', function () {
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace('%s end event', c.ldap.id); log.trace('%s end event', c.ldap.id);
c.end(); c.end();
}); });
c.on('close', function(had_err) { c.on('close', function (had_err) {
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace('%s close event had_err=%s', c.ldap.id, had_err ? 'yes' : 'no'); log.trace('%s close event had_err=%s', c.ldap.id, had_err ? 'yes' : 'no');
Object.keys(c.ldap.messages).forEach(function(msgid) { Object.keys(c.ldap.messages).forEach(function (msgid) {
var err; var err;
if (c.unbindMessageID !== parseInt(msgid, 10)) { if (c.unbindMessageID !== parseInt(msgid, 10)) {
err = new ConnectionError(c.ldap.id + ' closed'); err = new ConnectionError(c.ldap.id + ' closed');
@ -910,7 +916,7 @@ Client.prototype._newConnection = function() {
err.status = 'unbind'; err.status = 'unbind';
} }
if (typeof(c.ldap.messages[msgid]) === 'function') { if (typeof (c.ldap.messages[msgid]) === 'function') {
var callback = c.ldap.messages[msgid]; var callback = c.ldap.messages[msgid];
delete c.ldap.messages[msgid]; delete c.ldap.messages[msgid];
return callback(err); return callback(err);
@ -926,7 +932,7 @@ Client.prototype._newConnection = function() {
}); });
}); });
c.on('error', function(err) { c.on('error', function (err) {
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace('%s error event=%s', c.ldap.id, err ? err.stack : '?'); log.trace('%s error event=%s', c.ldap.id, err ? err.stack : '?');
@ -936,7 +942,7 @@ Client.prototype._newConnection = function() {
c.end(); c.end();
}); });
c.on('timeout', function() { c.on('timeout', function () {
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace('%s timeout event=%s', c.ldap.id); log.trace('%s timeout event=%s', c.ldap.id);
@ -944,7 +950,7 @@ Client.prototype._newConnection = function() {
c.end(); c.end();
}); });
c.on('data', function(data) { c.on('data', function (data) {
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace('%s data event: %s', c.ldap.id, util.inspect(data)); log.trace('%s data event: %s', c.ldap.id, util.inspect(data));
@ -952,7 +958,7 @@ Client.prototype._newConnection = function() {
}); });
// The "router" // The "router"
c.parser.on('message', function(message) { c.parser.on('message', function (message) {
message.connection = c; message.connection = c;
var callback = c.ldap.messages[message.messageID]; var callback = c.ldap.messages[message.messageID];
@ -964,7 +970,7 @@ Client.prototype._newConnection = function() {
return callback(message); return callback(message);
}); });
c.parser.on('error', function(err) { c.parser.on('error', function (err) {
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace('%s error event=%s', c.ldap.id, err ? err.stack : '?'); log.trace('%s error event=%s', c.ldap.id, err ? err.stack : '?');

View File

@ -19,14 +19,14 @@ var Ber = asn1.Ber;
function Control(options) { function Control(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.type && typeof(options.type) !== 'string') if (options.type && typeof (options.type) !== 'string')
throw new TypeError('options.type must be a string'); throw new TypeError('options.type must be a string');
if (options.criticality !== undefined && if (options.criticality !== undefined &&
typeof(options.criticality) !== 'boolean') typeof (options.criticality) !== 'boolean')
throw new TypeError('options.criticality must be a boolean'); throw new TypeError('options.criticality must be a boolean');
if (options.value && typeof(options.value) !== 'string') if (options.value && typeof (options.value) !== 'string')
throw new TypeError('options.value must be a string'); throw new TypeError('options.value must be a string');
} else { } else {
options = {}; options = {};
@ -37,25 +37,25 @@ function Control(options) {
this.value = options.value || null; this.value = options.value || null;
var self = this; var self = this;
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
var obj = { var obj = {
controlType: self.type, controlType: self.type,
criticality: self.criticality, criticality: self.criticality,
controlValue: self.value controlValue: self.value
}; };
return (typeof(self._json) === 'function' ? self._json(obj) : obj); return (typeof (self._json) === 'function' ? self._json(obj) : obj);
}); });
} }
module.exports = Control; module.exports = Control;
Control.prototype.toBer = function(ber) { Control.prototype.toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.startSequence(); ber.startSequence();
ber.writeString(this.type || ''); ber.writeString(this.type || '');
ber.writeBoolean(this.criticality); ber.writeBoolean(this.criticality);
if (typeof(this._toBer) === 'function') { if (typeof (this._toBer) === 'function') {
this._toBer(ber); this._toBer(ber);
} else { } else {
if (this.value) if (this.value)
@ -67,6 +67,6 @@ Control.prototype.toBer = function(ber) {
}; };
Control.prototype.toString = function() { Control.prototype.toString = function () {
return this.json; return this.json;
}; };

View File

@ -24,7 +24,7 @@ function EntryChangeNotificationControl(options) {
if (options.value) { if (options.value) {
if (Buffer.isBuffer(options.value)) { if (Buffer.isBuffer(options.value)) {
this.parse(options.value); this.parse(options.value);
} else if (typeof(options.value) === 'object') { } else if (typeof (options.value) === 'object') {
this._value = options.value; this._value = options.value;
} else { } else {
throw new TypeError('options.value must be a Buffer or Object'); throw new TypeError('options.value must be a Buffer or Object');
@ -34,7 +34,7 @@ function EntryChangeNotificationControl(options) {
Control.call(this, options); Control.call(this, options);
var self = this; var self = this;
this.__defineGetter__('value', function() { this.__defineGetter__('value', function () {
return self._value || {}; return self._value || {};
}); });
} }
@ -64,7 +64,7 @@ EntryChangeNotificationControl.prototype.parse = function parse(buffer) {
}; };
EntryChangeNotificationControl.prototype._toBer = function(ber) { EntryChangeNotificationControl.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
if (!this._value) if (!this._value)
@ -83,7 +83,7 @@ EntryChangeNotificationControl.prototype._toBer = function(ber) {
}; };
EntryChangeNotificationControl.prototype._json = function(obj) { EntryChangeNotificationControl.prototype._json = function (obj) {
obj.controlValue = this.value; obj.controlValue = this.value;
return obj; return obj;
}; };

View File

@ -56,6 +56,7 @@ module.exports = {
critical: critical, critical: critical,
value: value ? value.toString('utf8') : null value: value ? value.toString('utf8') : null
}); });
break;
} }
return control; return control;

View File

@ -26,7 +26,7 @@ function PersistentSearchControl(options) {
if (options.value) { if (options.value) {
if (Buffer.isBuffer(options.value)) { if (Buffer.isBuffer(options.value)) {
this.parse(options.value); this.parse(options.value);
} else if (typeof(options.value) === 'object') { } else if (typeof (options.value) === 'object') {
this._value = options.value; this._value = options.value;
} else { } else {
throw new TypeError('options.value must be a Buffer or Object'); throw new TypeError('options.value must be a Buffer or Object');
@ -36,7 +36,7 @@ function PersistentSearchControl(options) {
Control.call(this, options); Control.call(this, options);
var self = this; var self = this;
this.__defineGetter__('value', function() { this.__defineGetter__('value', function () {
return self._value || {}; return self._value || {};
}); });
} }
@ -62,7 +62,7 @@ PersistentSearchControl.prototype.parse = function parse(buffer) {
}; };
PersistentSearchControl.prototype._toBer = function(ber) { PersistentSearchControl.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
if (!this._value) if (!this._value)
@ -79,7 +79,7 @@ PersistentSearchControl.prototype._toBer = function(ber) {
}; };
PersistentSearchControl.prototype._json = function(obj) { PersistentSearchControl.prototype._json = function (obj) {
obj.controlValue = this.value; obj.controlValue = this.value;
return obj; return obj;
}; };

View File

@ -25,18 +25,18 @@ function RDN(obj) {
var self = this; var self = this;
if (obj) { if (obj) {
Object.keys(obj).forEach(function(k) { Object.keys(obj).forEach(function (k) {
self[k.toLowerCase()] = obj[k]; self[k.toLowerCase()] = obj[k];
}); });
} }
} }
RDN.prototype.toString = function() { RDN.prototype.toString = function () {
var self = this; var self = this;
var str = ''; var str = '';
Object.keys(this).forEach(function(k) { Object.keys(this).forEach(function (k) {
if (str.length) if (str.length)
str += '+'; str += '+';
@ -48,7 +48,7 @@ RDN.prototype.toString = function() {
// Thank you OpenJDK! // Thank you OpenJDK!
function parse(name) { function parse(name) {
if (typeof(name) !== 'string') if (typeof (name) !== 'string')
throw new TypeError('name (string) required'); throw new TypeError('name (string) required');
var cur = 0; var cur = 0;
@ -190,30 +190,30 @@ function parse(name) {
function DN(rdns) { function DN(rdns) {
if (!Array.isArray(rdns)) if (!Array.isArray(rdns))
throw new TypeError('rdns ([object]) required'); throw new TypeError('rdns ([object]) required');
rdns.forEach(function(rdn) { rdns.forEach(function (rdn) {
if (typeof(rdn) !== 'object') if (typeof (rdn) !== 'object')
throw new TypeError('rdns ([object]) required'); throw new TypeError('rdns ([object]) required');
}); });
this.rdns = rdns.slice(); this.rdns = rdns.slice();
this.__defineGetter__('length', function() { this.__defineGetter__('length', function () {
return this.rdns.length; return this.rdns.length;
}); });
} }
DN.prototype.toString = function() { DN.prototype.toString = function () {
var _dn = []; var _dn = [];
this.rdns.forEach(function(rdn) { this.rdns.forEach(function (rdn) {
_dn.push(rdn.toString()); _dn.push(rdn.toString());
}); });
return _dn.join(', '); return _dn.join(', ');
}; };
DN.prototype.childOf = function(dn) { DN.prototype.childOf = function (dn) {
if (typeof(dn) !== 'object') if (typeof (dn) !== 'object')
dn = parse(dn); dn = parse(dn);
if (this.rdns.length <= dn.rdns.length) if (this.rdns.length <= dn.rdns.length)
@ -239,8 +239,8 @@ DN.prototype.childOf = function(dn) {
}; };
DN.prototype.parentOf = function(dn) { DN.prototype.parentOf = function (dn) {
if (typeof(dn) !== 'object') if (typeof (dn) !== 'object')
dn = parse(dn); dn = parse(dn);
if (!this.rdns.length || this.rdns.length >= dn.rdns.length) if (!this.rdns.length || this.rdns.length >= dn.rdns.length)
@ -266,8 +266,8 @@ DN.prototype.parentOf = function(dn) {
}; };
DN.prototype.equals = function(dn) { DN.prototype.equals = function (dn) {
if (typeof(dn) !== 'object') if (typeof (dn) !== 'object')
dn = parse(dn); dn = parse(dn);
if (this.rdns.length !== dn.rdns.length) if (this.rdns.length !== dn.rdns.length)
@ -296,7 +296,7 @@ DN.prototype.equals = function(dn) {
}; };
DN.prototype.parent = function() { DN.prototype.parent = function () {
if (this.rdns.length > 1) { if (this.rdns.length > 1) {
var save = this.rdns.shift(); var save = this.rdns.shift();
var dn = new DN(this.rdns); var dn = new DN(this.rdns);
@ -308,37 +308,37 @@ DN.prototype.parent = function() {
}; };
DN.prototype.clone = function() { DN.prototype.clone = function () {
return new DN(this.rdns); return new DN(this.rdns);
}; };
DN.prototype.reverse = function() { DN.prototype.reverse = function () {
this.rdns.reverse(); this.rdns.reverse();
return this; return this;
}; };
DN.prototype.pop = function() { DN.prototype.pop = function () {
return this.rdns.pop(); return this.rdns.pop();
}; };
DN.prototype.push = function(rdn) { DN.prototype.push = function (rdn) {
if (typeof(rdn) !== 'object') if (typeof (rdn) !== 'object')
throw new TypeError('rdn (RDN) required'); throw new TypeError('rdn (RDN) required');
return this.rdns.push(rdn); return this.rdns.push(rdn);
}; };
DN.prototype.shift = function() { DN.prototype.shift = function () {
return this.rdns.shift(); return this.rdns.shift();
}; };
DN.prototype.unshift = function(rdn) { DN.prototype.unshift = function (rdn) {
if (typeof(rdn) !== 'object') if (typeof (rdn) !== 'object')
throw new TypeError('rdn (RDN) required'); throw new TypeError('rdn (RDN) required');
return this.rdns.unshift(rdn); return this.rdns.unshift(rdn);

View File

@ -10,7 +10,8 @@ var SERVER_PROVIDER;
var DTRACE_ID = 0; var DTRACE_ID = 0;
var MAX_INT = 4294967295; var MAX_INT = 4294967295;
/* Args: /*
* Args:
* server-*-start: * server-*-start:
* 0 -> id * 0 -> id
* 1 -> remoteIP * 1 -> remoteIP
@ -76,11 +77,11 @@ var SERVER_PROBES = {
///--- API ///--- API
module.exports = function() { module.exports = function () {
if (!SERVER_PROVIDER) { if (!SERVER_PROVIDER) {
SERVER_PROVIDER = dtrace.createDTraceProvider('ldapjs'); SERVER_PROVIDER = dtrace.createDTraceProvider('ldapjs');
Object.keys(SERVER_PROBES).forEach(function(p) { Object.keys(SERVER_PROBES).forEach(function (p) {
var args = SERVER_PROBES[p].splice(0); var args = SERVER_PROBES[p].splice(0);
args.unshift(p); args.unshift(p);
@ -89,7 +90,7 @@ module.exports = function() {
SERVER_PROVIDER.enable(); SERVER_PROVIDER.enable();
SERVER_PROVIDER._nextId = function() { SERVER_PROVIDER._nextId = function () {
if (DTRACE_ID === MAX_INT) if (DTRACE_ID === MAX_INT)
DTRACE_ID = 0; DTRACE_ID = 0;
@ -99,4 +100,3 @@ module.exports = function() {
return SERVER_PROVIDER; return SERVER_PROVIDER;
}(); }();

View File

@ -59,16 +59,16 @@ function LDAPError(errorName, errorCode, msg, dn, caller) {
if (Error.captureStackTrace) if (Error.captureStackTrace)
Error.captureStackTrace(this, caller || LDAPError); Error.captureStackTrace(this, caller || LDAPError);
this.__defineGetter__('dn', function() { this.__defineGetter__('dn', function () {
return (dn ? (dn.toString() || '') : ''); return (dn ? (dn.toString() || '') : '');
}); });
this.__defineGetter__('code', function() { this.__defineGetter__('code', function () {
return errorCode; return errorCode;
}); });
this.__defineGetter__('name', function() { this.__defineGetter__('name', function () {
return errorName; return errorName;
}); });
this.__defineGetter__('message', function() { this.__defineGetter__('message', function () {
return msg || errorName; return msg || errorName;
}); });
} }
@ -82,7 +82,7 @@ util.inherits(LDAPError, Error);
module.exports = {}; module.exports = {};
module.exports.LDAPError = LDAPError; module.exports.LDAPError = LDAPError;
Object.keys(CODES).forEach(function(code) { Object.keys(CODES).forEach(function (code) {
module.exports[code] = CODES[code]; module.exports[code] = CODES[code];
if (code === 'LDAP_SUCCESS') if (code === 'LDAP_SUCCESS')
return; return;
@ -102,14 +102,14 @@ Object.keys(CODES).forEach(function(code) {
// At this point LDAP_OPERATIONS_ERROR is now OperationsError in $err // At this point LDAP_OPERATIONS_ERROR is now OperationsError in $err
// and 'Operations Error' in $msg // and 'Operations Error' in $msg
module.exports[err] = function(message, dn, caller) { module.exports[err] = function (message, dn, caller) {
LDAPError.call(this, LDAPError.call(this,
err, err,
CODES[code], CODES[code],
message || msg, message || msg,
dn || null, dn || null,
caller || module.exports[err]); caller || module.exports[err]);
} };
module.exports[err].constructor = module.exports[err]; module.exports[err].constructor = module.exports[err];
util.inherits(module.exports[err], LDAPError); util.inherits(module.exports[err], LDAPError);
@ -120,7 +120,7 @@ Object.keys(CODES).forEach(function(code) {
}); });
module.exports.getError = function(res) { module.exports.getError = function (res) {
if (!(res instanceof LDAPResult)) if (!(res instanceof LDAPResult))
throw new TypeError('res (LDAPResult) required'); throw new TypeError('res (LDAPResult) required');
@ -132,10 +132,10 @@ module.exports.getError = function(res) {
}; };
module.exports.getMessage = function(code) { module.exports.getMessage = function (code) {
if (typeof(code) !== 'number') if (typeof (code) !== 'number')
throw new TypeError('code (number) required'); throw new TypeError('code (number) required');
var errObj = ERRORS[res.status]; var errObj = ERRORS[code];
return (errObj && errObj.message ? errObj.message : ''); return (errObj && errObj.message ? errObj.message : '');
}; };

View File

@ -12,7 +12,7 @@ var Protocol = require('../protocol');
///--- API ///--- API
function AndFilter(options) { function AndFilter(options) {
if (typeof(options) === 'object') { if (typeof (options) === 'object') {
if (!options.filters || !Array.isArray(options.filters)) if (!options.filters || !Array.isArray(options.filters))
throw new TypeError('options.filters ([Filter]) required'); throw new TypeError('options.filters ([Filter]) required');
this.filters = options.filters.slice(); this.filters = options.filters.slice();
@ -27,7 +27,7 @@ function AndFilter(options) {
this.filters = []; this.filters = [];
var self = this; var self = this;
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
return { return {
type: 'And', type: 'And',
filters: self.filters || [] filters: self.filters || []
@ -38,9 +38,9 @@ util.inherits(AndFilter, Filter);
module.exports = AndFilter; module.exports = AndFilter;
AndFilter.prototype.toString = function() { AndFilter.prototype.toString = function () {
var str = '(&'; var str = '(&';
this.filters.forEach(function(f) { this.filters.forEach(function (f) {
str += f.toString(); str += f.toString();
}); });
str += ')'; str += ')';
@ -49,32 +49,33 @@ AndFilter.prototype.toString = function() {
}; };
AndFilter.prototype.matches = function(target) { AndFilter.prototype.matches = function (target) {
if (typeof(target) !== 'object') if (typeof (target) !== 'object')
throw new TypeError('target (object) required'); throw new TypeError('target (object) required');
var matches = this.filters.length ? true : false; var matches = this.filters.length ? true : false;
for (var i = 0; i < this.filters.length; i++) for (var i = 0; i < this.filters.length; i++) {
if (!this.filters[i].matches(target)) if (!this.filters[i].matches(target))
return false; return false;
}
return matches; return matches;
}; };
AndFilter.prototype.addFilter = function(filter) { AndFilter.prototype.addFilter = function (filter) {
if (!filter || typeof(filter) !== 'object') if (!filter || typeof (filter) !== 'object')
throw new TypeError('filter (object) required'); throw new TypeError('filter (object) required');
this.filters.push(filter); this.filters.push(filter);
}; };
AndFilter.prototype._toBer = function(ber) { AndFilter.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
this.filters.forEach(function(f) { this.filters.forEach(function (f) {
ber = f.toBer(ber); ber = f.toBer(ber);
}); });

View File

@ -12,10 +12,10 @@ var Protocol = require('../protocol');
///--- API ///--- API
function ApproximateFilter(options) { function ApproximateFilter(options) {
if (typeof(options) === 'object') { if (typeof (options) === 'object') {
if (!options.attribute || typeof(options.attribute) !== 'string') if (!options.attribute || typeof (options.attribute) !== 'string')
throw new TypeError('options.attribute (string) required'); throw new TypeError('options.attribute (string) required');
if (!options.value || typeof(options.value) !== 'string') if (!options.value || typeof (options.value) !== 'string')
throw new TypeError('options.value (string) required'); throw new TypeError('options.value (string) required');
this.attribute = options.attribute; this.attribute = options.attribute;
this.value = options.value; this.value = options.value;
@ -26,7 +26,7 @@ function ApproximateFilter(options) {
Filter.call(this, options); Filter.call(this, options);
var self = this; var self = this;
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
return { return {
type: 'ApproximateMatch', type: 'ApproximateMatch',
attribute: self.attribute || undefined, attribute: self.attribute || undefined,
@ -38,13 +38,13 @@ util.inherits(ApproximateFilter, Filter);
module.exports = ApproximateFilter; module.exports = ApproximateFilter;
ApproximateFilter.prototype.toString = function() { ApproximateFilter.prototype.toString = function () {
return '(' + this.attribute + '~=' + this.value + ')'; return '(' + this.attribute + '~=' + this.value + ')';
}; };
ApproximateFilter.prototype.matches = function(target) { ApproximateFilter.prototype.matches = function (target) {
if (typeof(target) !== 'object') if (typeof (target) !== 'object')
throw new TypeError('target (object) required'); throw new TypeError('target (object) required');
var matches = false; var matches = false;
@ -61,7 +61,7 @@ ApproximateFilter.prototype.matches = function(target) {
}; };
ApproximateFilter.prototype.parse = function(ber) { ApproximateFilter.prototype.parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.attribute = ber.readString().toLowerCase(); this.attribute = ber.readString().toLowerCase();
@ -71,7 +71,7 @@ ApproximateFilter.prototype.parse = function(ber) {
}; };
ApproximateFilter.prototype._toBer = function(ber) { ApproximateFilter.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.attribute); ber.writeString(this.attribute);

View File

@ -12,10 +12,10 @@ var Protocol = require('../protocol');
///--- API ///--- API
function EqualityFilter(options) { function EqualityFilter(options) {
if (typeof(options) === 'object') { if (typeof (options) === 'object') {
if (!options.attribute || typeof(options.attribute) !== 'string') if (!options.attribute || typeof (options.attribute) !== 'string')
throw new TypeError('options.attribute (string) required'); throw new TypeError('options.attribute (string) required');
if (!options.value || typeof(options.value) !== 'string') if (!options.value || typeof (options.value) !== 'string')
throw new TypeError('options.value (string) required'); throw new TypeError('options.value (string) required');
this.attribute = options.attribute; this.attribute = options.attribute;
this.value = options.value; this.value = options.value;
@ -26,7 +26,7 @@ function EqualityFilter(options) {
Filter.call(this, options); Filter.call(this, options);
var self = this; var self = this;
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
return { return {
type: 'EqualityMatch', type: 'EqualityMatch',
attribute: self.attribute || undefined, attribute: self.attribute || undefined,
@ -38,19 +38,19 @@ util.inherits(EqualityFilter, Filter);
module.exports = EqualityFilter; module.exports = EqualityFilter;
EqualityFilter.prototype.toString = function() { EqualityFilter.prototype.toString = function () {
return '(' + this.attribute + '=' + this.value + ')'; return '(' + this.attribute + '=' + this.value + ')';
}; };
EqualityFilter.prototype.matches = function(target) { EqualityFilter.prototype.matches = function (target) {
if (typeof(target) !== 'object') if (typeof (target) !== 'object')
throw new TypeError('target (object) required'); throw new TypeError('target (object) required');
if (target.hasOwnProperty(this.attribute)) { if (target.hasOwnProperty(this.attribute)) {
var value = this.value; var value = this.value;
return Filter.multi_test( return Filter.multi_test(
function(v) { return value === v; }, function (v) { return value === v; },
target[this.attribute]); target[this.attribute]);
} }
@ -58,7 +58,7 @@ EqualityFilter.prototype.matches = function(target) {
}; };
EqualityFilter.prototype.parse = function(ber) { EqualityFilter.prototype.parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.attribute = ber.readString().toLowerCase(); this.attribute = ber.readString().toLowerCase();
@ -71,7 +71,7 @@ EqualityFilter.prototype.parse = function(ber) {
}; };
EqualityFilter.prototype._toBer = function(ber) { EqualityFilter.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.attribute); ber.writeString(this.attribute);

View File

@ -12,12 +12,12 @@ var Protocol = require('../protocol');
///--- API ///--- API
function ExtensibleFilter(options) { function ExtensibleFilter(options) {
if (typeof(options) === 'object') { if (typeof (options) === 'object') {
if (options.rule && typeof(options.rule) !== 'string') if (options.rule && typeof (options.rule) !== 'string')
throw new TypeError('options.rule must be a string'); throw new TypeError('options.rule must be a string');
if (options.matchType && typeof(options.matchType) !== 'string') if (options.matchType && typeof (options.matchType) !== 'string')
throw new TypeError('options.type must be a string'); throw new TypeError('options.type must be a string');
if (options.value && typeof(options.value) !== 'string') if (options.value && typeof (options.value) !== 'string')
throw new TypeError('options.value (string) required'); throw new TypeError('options.value (string) required');
} else { } else {
options = {}; options = {};
@ -31,7 +31,7 @@ function ExtensibleFilter(options) {
Filter.call(this, options); Filter.call(this, options);
var self = this; var self = this;
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
return { return {
type: 'ExtensibleMatch', type: 'ExtensibleMatch',
matchRule: self.rule, matchRule: self.rule,
@ -40,10 +40,10 @@ function ExtensibleFilter(options) {
dnAttributes: self.dnAttributes dnAttributes: self.dnAttributes
}; };
}); });
this.__defineGetter__('matchingRule', function() { this.__defineGetter__('matchingRule', function () {
return self.rule; return self.rule;
}); });
this.__defineGetter__('matchValue', function() { this.__defineGetter__('matchValue', function () {
return self.value; return self.value;
}); });
} }
@ -51,7 +51,7 @@ util.inherits(ExtensibleFilter, Filter);
module.exports = ExtensibleFilter; module.exports = ExtensibleFilter;
ExtensibleFilter.prototype.toString = function() { ExtensibleFilter.prototype.toString = function () {
var str = '('; var str = '(';
if (this.matchType) if (this.matchType)
@ -78,8 +78,8 @@ ExtensibleFilter.prototype.toString = function() {
* @param {Object} target the target object. * @param {Object} target the target object.
* @return {Boolean} false always. * @return {Boolean} false always.
*/ */
ExtensibleFilter.prototype.matches = function(target) { ExtensibleFilter.prototype.matches = function (target) {
if (typeof(target) !== 'object') if (typeof (target) !== 'object')
throw new TypeError('target (object) required'); throw new TypeError('target (object) required');
if (this.dnAttribute) if (this.dnAttribute)
@ -90,7 +90,7 @@ ExtensibleFilter.prototype.matches = function(target) {
var self = this; var self = this;
if (this.matchType && target.hasOwnProperty(this.matchType)) { if (this.matchType && target.hasOwnProperty(this.matchType)) {
return Filter.multi_test(function(v) { return Filter.multi_test(function (v) {
if (self.rule === '2.5.13.2') if (self.rule === '2.5.13.2')
return self.value.toLowerCase() === v.toLowerCase(); return self.value.toLowerCase() === v.toLowerCase();
@ -102,7 +102,7 @@ ExtensibleFilter.prototype.matches = function(target) {
}; };
ExtensibleFilter.prototype.parse = function(ber) { ExtensibleFilter.prototype.parse = function (ber) {
var end = ber.offset + ber.length; var end = ber.offset + ber.length;
while (ber.offset < end) { while (ber.offset < end) {
var tag = ber.peek(); var tag = ber.peek();
@ -128,7 +128,7 @@ ExtensibleFilter.prototype.parse = function(ber) {
}; };
ExtensibleFilter.prototype._toBer = function(ber) { ExtensibleFilter.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
if (this.rule) if (this.rule)

View File

@ -18,15 +18,15 @@ var BerWriter = asn1.BerWriter;
///--- API ///--- API
function Filter(options) { function Filter(options) {
if (!options || typeof(options) !== 'object') if (!options || typeof (options) !== 'object')
throw new TypeError('options (object) required'); throw new TypeError('options (object) required');
if (typeof(options.type) !== 'number') if (typeof (options.type) !== 'number')
throw new TypeError('options.type (number) required'); throw new TypeError('options.type (number) required');
this._type = options.type; this._type = options.type;
var self = this; var self = this;
this.__defineGetter__('type', function() { this.__defineGetter__('type', function () {
switch (self._type) { switch (self._type) {
case Protocol.FILTER_AND: return 'and'; case Protocol.FILTER_AND: return 'and';
case Protocol.FILTER_OR: return 'or'; case Protocol.FILTER_OR: return 'or';
@ -47,7 +47,7 @@ function Filter(options) {
module.exports = Filter; module.exports = Filter;
Filter.prototype.toBer = function(ber) { Filter.prototype.toBer = function (ber) {
if (!ber || !(ber instanceof BerWriter)) if (!ber || !(ber instanceof BerWriter))
throw new TypeError('ber (BerWriter) required'); throw new TypeError('ber (BerWriter) required');
@ -61,7 +61,7 @@ Filter.prototype.toBer = function(ber) {
/* /*
* Test a rule against one or more values. * Test a rule against one or more values.
*/ */
Filter.multi_test = function(rule, value) { Filter.multi_test = function (rule, value) {
if (Array.isArray(value)) { if (Array.isArray(value)) {
var response = false; var response = false;
for (var i = 0; i < value.length; i++) { for (var i = 0; i < value.length; i++) {

View File

@ -12,10 +12,10 @@ var Protocol = require('../protocol');
///--- API ///--- API
function GreaterThanEqualsFilter(options) { function GreaterThanEqualsFilter(options) {
if (typeof(options) === 'object') { if (typeof (options) === 'object') {
if (!options.attribute || typeof(options.attribute) !== 'string') if (!options.attribute || typeof (options.attribute) !== 'string')
throw new TypeError('options.attribute (string) required'); throw new TypeError('options.attribute (string) required');
if (!options.value || typeof(options.value) !== 'string') if (!options.value || typeof (options.value) !== 'string')
throw new TypeError('options.value (string) required'); throw new TypeError('options.value (string) required');
this.attribute = options.attribute; this.attribute = options.attribute;
this.value = options.value; this.value = options.value;
@ -27,7 +27,7 @@ function GreaterThanEqualsFilter(options) {
Filter.call(this, options); Filter.call(this, options);
var self = this; var self = this;
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
return { return {
type: 'GreaterThanEqualsMatch', type: 'GreaterThanEqualsMatch',
attribute: self.attribute || undefined, attribute: self.attribute || undefined,
@ -39,19 +39,19 @@ util.inherits(GreaterThanEqualsFilter, Filter);
module.exports = GreaterThanEqualsFilter; module.exports = GreaterThanEqualsFilter;
GreaterThanEqualsFilter.prototype.toString = function() { GreaterThanEqualsFilter.prototype.toString = function () {
return '(' + this.attribute + '>=' + this.value + ')'; return '(' + this.attribute + '>=' + this.value + ')';
}; };
GreaterThanEqualsFilter.prototype.matches = function(target) { GreaterThanEqualsFilter.prototype.matches = function (target) {
if (typeof(target) !== 'object') if (typeof (target) !== 'object')
throw new TypeError('target (object) required'); throw new TypeError('target (object) required');
if (target.hasOwnProperty(this.attribute)) { if (target.hasOwnProperty(this.attribute)) {
var value = this.value; var value = this.value;
return Filter.multi_test( return Filter.multi_test(
function(v) { return value <= v; }, function (v) { return value <= v; },
target[this.attribute]); target[this.attribute]);
} }
@ -59,7 +59,7 @@ GreaterThanEqualsFilter.prototype.matches = function(target) {
}; };
GreaterThanEqualsFilter.prototype.parse = function(ber) { GreaterThanEqualsFilter.prototype.parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.attribute = ber.readString().toLowerCase(); this.attribute = ber.readString().toLowerCase();
@ -69,7 +69,7 @@ GreaterThanEqualsFilter.prototype.parse = function(ber) {
}; };
GreaterThanEqualsFilter.prototype._toBer = function(ber) { GreaterThanEqualsFilter.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.attribute); ber.writeString(this.attribute);

View File

@ -60,8 +60,16 @@ function matchParens(str, openParenIndex) {
// the filter tree is an intermediary step between the incoming expression and // the filter tree is an intermediary step between the incoming expression and
// the outgoing Filter Class structure. // the outgoing Filter Class structure.
function _buildFilterTree(expr) { function _buildFilterTree(expr) {
var c;
var child;
var clean = false;
var endParen;
var esc = false;
var i = 0;
var tree = {}; var tree = {};
var split; var split;
var substrNdx = 0;
var val = '';
if (expr.length === 0) if (expr.length === 0)
return tree; return tree;
@ -85,13 +93,10 @@ function _buildFilterTree(expr) {
} }
if (tree.op != 'expr') { if (tree.op != 'expr') {
var child;
var i = 0;
tree.children = []; tree.children = [];
// logical operators are k-ary, so we go until our expression string runs // logical operators are k-ary, so we go until our expression string runs
// out (at least for this recursion level) // out (at least for this recursion level)
var endParen;
while (expr.length !== 0) { while (expr.length !== 0) {
endParen = matchParens(expr); endParen = matchParens(expr);
if (endParen == expr.length - 1) { if (endParen == expr.length - 1) {
@ -107,29 +112,23 @@ function _buildFilterTree(expr) {
} else { } else {
//else its some sort of non-logical expression, parse and return as such //else its some sort of non-logical expression, parse and return as such
var operatorStr = ''; var operatorStr = '';
var valueOffset = 0;
tree.name = ''; tree.name = '';
tree.value = ''; tree.value = '';
if (expr.indexOf('~=') !== -1) { if (expr.indexOf('~=') !== -1) {
operatorStr = '~='; operatorStr = '~=';
tree.tag = 'approxMatch'; tree.tag = 'approxMatch';
valueOffset = 2;
} else if (expr.indexOf('>=') !== -1) { } else if (expr.indexOf('>=') !== -1) {
operatorStr = '>='; operatorStr = '>=';
tree.tag = 'greaterOrEqual'; tree.tag = 'greaterOrEqual';
valueOffset = 2;
} else if (expr.indexOf('<=') !== -1) { } else if (expr.indexOf('<=') !== -1) {
operatorStr = '<='; operatorStr = '<=';
tree.tag = 'lessOrEqual'; tree.tag = 'lessOrEqual';
valueOffset = 2;
} else if (expr.indexOf(':=') !== -1) { } else if (expr.indexOf(':=') !== -1) {
operatorStr = ':='; operatorStr = ':=';
tree.tag = 'extensibleMatch'; tree.tag = 'extensibleMatch';
valueOffset = 2;
} else if (expr.indexOf('=') !== -1) { } else if (expr.indexOf('=') !== -1) {
operatorStr = '='; operatorStr = '=';
tree.tag = 'equalityMatch'; tree.tag = 'equalityMatch';
valueOffset = 1;
} else { } else {
tree.tag = 'present'; tree.tag = 'present';
} }
@ -138,7 +137,6 @@ function _buildFilterTree(expr) {
tree.name = expr; tree.name = expr;
} else { } else {
// pull out lhs and rhs of equality operator // pull out lhs and rhs of equality operator
var clean = false;
var splitAry = expr.split(operatorStr); var splitAry = expr.split(operatorStr);
tree.name = splitAry.shift(); tree.name = splitAry.shift();
tree.value = splitAry.join(operatorStr); tree.value = splitAry.join(operatorStr);
@ -149,17 +147,14 @@ function _buildFilterTree(expr) {
if (tree.value.length === 0) { if (tree.value.length === 0) {
tree.tag = 'present'; tree.tag = 'present';
} else { } else {
var substrNdx = 0;
var substr = false;
var esc = false;
// Effectively a hand-rolled .shift() to support \* sequences // Effectively a hand-rolled .shift() to support \* sequences
clean = true; clean = true;
split = []; split = [];
substrNdx = 0; substrNdx = 0;
split[substrNdx] = ''; split[substrNdx] = '';
for (var i = 0; i < tree.value.length; i++) { for (i = 0; i < tree.value.length; i++) {
var c = tree.value[i]; c = tree.value[i];
if (esc) { if (esc) {
split[substrNdx] += c; split[substrNdx] += c;
esc = false; esc = false;
@ -227,10 +222,9 @@ function _buildFilterTree(expr) {
// Cleanup any escape sequences // Cleanup any escape sequences
if (!clean) { if (!clean) {
var val = '';
var esc = false; for (i = 0; i < tree.value.length; i++) {
for (var i = 0; i < tree.value.length; i++) { c = tree.value[i];
var c = tree.value[i];
if (esc) { if (esc) {
val += c; val += c;
esc = false; esc = false;
@ -250,7 +244,7 @@ function _buildFilterTree(expr) {
function serializeTree(tree, filter) { function serializeTree(tree, filter) {
if (tree === undefined || tree.length === 0) if (tree === undefined || tree.length === 0)
return filter; return;
// if the current tree object is not an expression then its a logical // if the current tree object is not an expression then its a logical
// operator (ie an internal node in the tree) // operator (ie an internal node in the tree)
@ -266,11 +260,13 @@ function serializeTree(tree, filter) {
case 'not': case 'not':
current = new NotFilter(); current = new NotFilter();
break; break;
default:
break;
} }
filter.addFilter(current || filter); filter.addFilter(current || filter);
if (current || tree.children.length) { if (current || tree.children.length) {
tree.children.forEach(function(child) { tree.children.forEach(function (child) {
serializeTree(child, current); serializeTree(child, current);
}); });
} }
@ -321,8 +317,11 @@ function serializeTree(tree, filter) {
attribute: tree.name attribute: tree.name
}); });
break; break;
default:
break;
} }
filter.addFilter(tmp); if (tmp)
filter.addFilter(tmp);
} }
} }
@ -457,15 +456,15 @@ function _parse(ber) {
module.exports = { module.exports = {
parse: function(ber) { parse: function (ber) {
if (!ber || !(ber instanceof BerReader)) if (!ber || !(ber instanceof BerReader))
throw new TypeError('ber (BerReader) required'); throw new TypeError('ber (BerReader) required');
return _parse(ber); return _parse(ber);
}, },
parseString: function(filter) { parseString: function (filter) {
if (!filter || typeof(filter) !== 'string') if (!filter || typeof (filter) !== 'string')
throw new TypeError('filter (string) required'); throw new TypeError('filter (string) required');
return _parseString(filter); return _parseString(filter);
@ -483,4 +482,3 @@ module.exports = {
SubstringFilter: SubstringFilter, SubstringFilter: SubstringFilter,
Filter: Filter Filter: Filter
}; };

View File

@ -12,10 +12,10 @@ var Protocol = require('../protocol');
///--- API ///--- API
function LessThanEqualsFilter(options) { function LessThanEqualsFilter(options) {
if (typeof(options) === 'object') { if (typeof (options) === 'object') {
if (!options.attribute || typeof(options.attribute) !== 'string') if (!options.attribute || typeof (options.attribute) !== 'string')
throw new TypeError('options.attribute (string) required'); throw new TypeError('options.attribute (string) required');
if (!options.value || typeof(options.value) !== 'string') if (!options.value || typeof (options.value) !== 'string')
throw new TypeError('options.value (string) required'); throw new TypeError('options.value (string) required');
this.attribute = options.attribute; this.attribute = options.attribute;
this.value = options.value; this.value = options.value;
@ -27,7 +27,7 @@ function LessThanEqualsFilter(options) {
Filter.call(this, options); Filter.call(this, options);
var self = this; var self = this;
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
return { return {
type: 'LessThanEqualsMatch', type: 'LessThanEqualsMatch',
attribute: self.attribute || undefined, attribute: self.attribute || undefined,
@ -39,19 +39,19 @@ util.inherits(LessThanEqualsFilter, Filter);
module.exports = LessThanEqualsFilter; module.exports = LessThanEqualsFilter;
LessThanEqualsFilter.prototype.toString = function() { LessThanEqualsFilter.prototype.toString = function () {
return '(' + this.attribute + '<=' + this.value + ')'; return '(' + this.attribute + '<=' + this.value + ')';
}; };
LessThanEqualsFilter.prototype.matches = function(target) { LessThanEqualsFilter.prototype.matches = function (target) {
if (typeof(target) !== 'object') if (typeof (target) !== 'object')
throw new TypeError('target (object) required'); throw new TypeError('target (object) required');
if (target.hasOwnProperty(this.attribute)) { if (target.hasOwnProperty(this.attribute)) {
var value = this.value; var value = this.value;
return Filter.multi_test( return Filter.multi_test(
function(v) { return value >= v; }, function (v) { return value >= v; },
target[this.attribute]); target[this.attribute]);
} }
@ -59,7 +59,7 @@ LessThanEqualsFilter.prototype.matches = function(target) {
}; };
LessThanEqualsFilter.prototype.parse = function(ber) { LessThanEqualsFilter.prototype.parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.attribute = ber.readString().toLowerCase(); this.attribute = ber.readString().toLowerCase();
@ -69,7 +69,7 @@ LessThanEqualsFilter.prototype.parse = function(ber) {
}; };
LessThanEqualsFilter.prototype._toBer = function(ber) { LessThanEqualsFilter.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.attribute); ber.writeString(this.attribute);

View File

@ -12,7 +12,7 @@ var Protocol = require('../protocol');
///--- API ///--- API
function NotFilter(options) { function NotFilter(options) {
if (typeof(options) === 'object') { if (typeof (options) === 'object') {
if (!options.filter || !(options.filter instanceof Filter)) if (!options.filter || !(options.filter instanceof Filter))
throw new TypeError('options.filter (Filter) required'); throw new TypeError('options.filter (Filter) required');
@ -25,7 +25,7 @@ function NotFilter(options) {
Filter.call(this, options); Filter.call(this, options);
var self = this; var self = this;
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
return { return {
type: 'Not', type: 'Not',
filter: self.filter filter: self.filter
@ -36,23 +36,23 @@ util.inherits(NotFilter, Filter);
module.exports = NotFilter; module.exports = NotFilter;
NotFilter.prototype.addFilter = function(f) { NotFilter.prototype.addFilter = function (f) {
if (!(f instanceof Filter)) if (!(f instanceof Filter))
throw new TypeError('filter (Filter) required'); throw new TypeError('filter (Filter) required');
this.filter = f; this.filter = f;
}; };
NotFilter.prototype.toString = function() { NotFilter.prototype.toString = function () {
return '(!' + this.filter.toString() + ')'; return '(!' + this.filter.toString() + ')';
}; };
NotFilter.prototype.matches = function(target) { NotFilter.prototype.matches = function (target) {
return !this.filter.matches(target); return !this.filter.matches(target);
}; };
NotFilter.prototype._toBer = function(ber) { NotFilter.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
return this.filter.toBer(ber); return this.filter.toBer(ber);

View File

@ -12,7 +12,7 @@ var Protocol = require('../protocol');
///--- API ///--- API
function OrFilter(options) { function OrFilter(options) {
if (typeof(options) === 'object') { if (typeof (options) === 'object') {
if (!options.filters || !Array.isArray(options.filters)) if (!options.filters || !Array.isArray(options.filters))
throw new TypeError('options.filters ([Filter]) required'); throw new TypeError('options.filters ([Filter]) required');
this.filters = options.filters.slice(); this.filters = options.filters.slice();
@ -27,7 +27,7 @@ function OrFilter(options) {
this.filters = []; this.filters = [];
var self = this; var self = this;
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
return { return {
type: 'Or', type: 'Or',
filters: self.filters || [] filters: self.filters || []
@ -38,9 +38,9 @@ util.inherits(OrFilter, Filter);
module.exports = OrFilter; module.exports = OrFilter;
OrFilter.prototype.toString = function() { OrFilter.prototype.toString = function () {
var str = '(|'; var str = '(|';
this.filters.forEach(function(f) { this.filters.forEach(function (f) {
str += f.toString(); str += f.toString();
}); });
str += ')'; str += ')';
@ -49,30 +49,31 @@ OrFilter.prototype.toString = function() {
}; };
OrFilter.prototype.matches = function(target) { OrFilter.prototype.matches = function (target) {
if (typeof(target) !== 'object') if (typeof (target) !== 'object')
throw new TypeError('target (object) required'); throw new TypeError('target (object) required');
for (var i = 0; i < this.filters.length; i++) for (var i = 0; i < this.filters.length; i++) {
if (this.filters[i].matches(target)) if (this.filters[i].matches(target))
return true; return true;
}
return false; return false;
}; };
OrFilter.prototype.addFilter = function(filter) { OrFilter.prototype.addFilter = function (filter) {
if (!filter || typeof(filter) !== 'object') if (!filter || typeof (filter) !== 'object')
throw new TypeError('filter (object) required'); throw new TypeError('filter (object) required');
this.filters.push(filter); this.filters.push(filter);
}; };
OrFilter.prototype._toBer = function(ber) { OrFilter.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
this.filters.forEach(function(f) { this.filters.forEach(function (f) {
ber = f.toBer(ber); ber = f.toBer(ber);
}); });

View File

@ -11,8 +11,8 @@ var Protocol = require('../protocol');
///--- API ///--- API
function PresenceFilter(options) { function PresenceFilter(options) {
if (typeof(options) === 'object') { if (typeof (options) === 'object') {
if (!options.attribute || typeof(options.attribute) !== 'string') if (!options.attribute || typeof (options.attribute) !== 'string')
throw new TypeError('options.attribute (string) required'); throw new TypeError('options.attribute (string) required');
this.attribute = options.attribute; this.attribute = options.attribute;
} else { } else {
@ -22,7 +22,7 @@ function PresenceFilter(options) {
Filter.call(this, options); Filter.call(this, options);
var self = this; var self = this;
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
return { return {
type: 'PresenceMatch', type: 'PresenceMatch',
attribute: self.attribute || undefined attribute: self.attribute || undefined
@ -33,20 +33,20 @@ util.inherits(PresenceFilter, Filter);
module.exports = PresenceFilter; module.exports = PresenceFilter;
PresenceFilter.prototype.toString = function() { PresenceFilter.prototype.toString = function () {
return '(' + this.attribute + '=*)'; return '(' + this.attribute + '=*)';
}; };
PresenceFilter.prototype.matches = function(target) { PresenceFilter.prototype.matches = function (target) {
if (typeof(target) !== 'object') if (typeof (target) !== 'object')
throw new TypeError('target (object) required'); throw new TypeError('target (object) required');
return target.hasOwnProperty(this.attribute); return target.hasOwnProperty(this.attribute);
}; };
PresenceFilter.prototype.parse = function(ber) { PresenceFilter.prototype.parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.attribute = this.attribute =
@ -58,7 +58,7 @@ PresenceFilter.prototype.parse = function(ber) {
}; };
PresenceFilter.prototype._toBer = function(ber) { PresenceFilter.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
for (var i = 0; i < this.attribute.length; i++) for (var i = 0; i < this.attribute.length; i++)

View File

@ -12,8 +12,8 @@ var Protocol = require('../protocol');
///--- API ///--- API
function SubstringFilter(options) { function SubstringFilter(options) {
if (typeof(options) === 'object') { if (typeof (options) === 'object') {
if (!options.attribute || typeof(options.attribute) !== 'string') if (!options.attribute || typeof (options.attribute) !== 'string')
throw new TypeError('options.attribute (string) required'); throw new TypeError('options.attribute (string) required');
this.attribute = options.attribute; this.attribute = options.attribute;
this.initial = options.initial || null; this.initial = options.initial || null;
@ -30,7 +30,7 @@ function SubstringFilter(options) {
Filter.call(this, options); Filter.call(this, options);
var self = this; var self = this;
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
return { return {
type: 'SubstringMatch', type: 'SubstringMatch',
initial: self.initial || undefined, initial: self.initial || undefined,
@ -43,7 +43,7 @@ util.inherits(SubstringFilter, Filter);
module.exports = SubstringFilter; module.exports = SubstringFilter;
SubstringFilter.prototype.toString = function() { SubstringFilter.prototype.toString = function () {
var str = '(' + this.attribute + '='; var str = '(' + this.attribute + '=';
if (this.initial) if (this.initial)
@ -51,7 +51,7 @@ SubstringFilter.prototype.toString = function() {
str += '*'; str += '*';
this.any.forEach(function(s) { this.any.forEach(function (s) {
str += s + '*'; str += s + '*';
}); });
@ -64,8 +64,8 @@ SubstringFilter.prototype.toString = function() {
}; };
SubstringFilter.prototype.matches = function(target) { SubstringFilter.prototype.matches = function (target) {
if (typeof(target) !== 'object') if (typeof (target) !== 'object')
throw new TypeError('target (object) required'); throw new TypeError('target (object) required');
if (target.hasOwnProperty(this.attribute)) { if (target.hasOwnProperty(this.attribute)) {
@ -73,7 +73,7 @@ SubstringFilter.prototype.matches = function(target) {
if (this.initial) if (this.initial)
re += '^' + this.initial + '.*'; re += '^' + this.initial + '.*';
this.any.forEach(function(s) { this.any.forEach(function (s) {
re += s + '.*'; re += s + '.*';
}); });
@ -82,7 +82,7 @@ SubstringFilter.prototype.matches = function(target) {
var matcher = new RegExp(re); var matcher = new RegExp(re);
return Filter.multi_test( return Filter.multi_test(
function(v) { return matcher.test(v); }, function (v) { return matcher.test(v); },
target[this.attribute]); target[this.attribute]);
} }
@ -90,7 +90,7 @@ SubstringFilter.prototype.matches = function(target) {
}; };
SubstringFilter.prototype.parse = function(ber) { SubstringFilter.prototype.parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.attribute = ber.readString().toLowerCase(); this.attribute = ber.readString().toLowerCase();
@ -125,7 +125,7 @@ SubstringFilter.prototype.parse = function(ber) {
}; };
SubstringFilter.prototype._toBer = function(ber) { SubstringFilter.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.attribute); ber.writeString(this.attribute);
@ -135,7 +135,7 @@ SubstringFilter.prototype._toBer = function(ber) {
ber.writeString(this.initial, 0x80); ber.writeString(this.initial, 0x80);
if (this.any && this.any.length) if (this.any && this.any.length)
this.any.forEach(function(s) { this.any.forEach(function (s) {
ber.writeString(s, 0x81); ber.writeString(s, 0x81);
}); });

View File

@ -13,7 +13,6 @@ var errors = require('./errors');
var filters = require('./filters'); var filters = require('./filters');
var logStub = require('./log_stub'); var logStub = require('./log_stub');
var messages = require('./messages'); var messages = require('./messages');
var schema = require('./schema');
var url = require('./url'); var url = require('./url');
@ -21,7 +20,7 @@ var url = require('./url');
/// Hack a few things we need (i.e., "monkey patch" the prototype) /// Hack a few things we need (i.e., "monkey patch" the prototype)
if (!String.prototype.startsWith) { if (!String.prototype.startsWith) {
String.prototype.startsWith = function(str) { String.prototype.startsWith = function (str) {
var re = new RegExp('^' + str); var re = new RegExp('^' + str);
return re.test(this); return re.test(this);
}; };
@ -29,7 +28,7 @@ if (!String.prototype.startsWith) {
if (!String.prototype.endsWith) { if (!String.prototype.endsWith) {
String.prototype.endsWith = function(str) { String.prototype.endsWith = function (str) {
var re = new RegExp(str + '$'); var re = new RegExp(str + '$');
return re.test(this); return re.test(this);
}; };
@ -42,15 +41,15 @@ if (!String.prototype.endsWith) {
module.exports = { module.exports = {
Client: Client, Client: Client,
createClient: function(options) { createClient: function (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options (object) required'); throw new TypeError('options (object) required');
return new Client(options); return new Client(options);
}, },
Server: Server, Server: Server,
createServer: function(options) { createServer: function (options) {
return new Server(options); return new Server(options);
}, },
@ -67,12 +66,7 @@ module.exports = {
log4js: logStub, log4js: logStub,
parseURL: url.parse, parseURL: url.parse,
url: url, url: url
loadSchema: schema.load,
createSchemaAddHandler: schema.createAddHandler,
createSchemaModifyHandler: schema.createModifyHandler,
createSchemaSearchHandler: schema.createSearchHandler
}; };

View File

@ -46,7 +46,7 @@ function format(level, name, args) {
args = fmtArgs.concat(args); args = fmtArgs.concat(args);
var output = (FMT_STR + fmtStr).replace(/%[sdj]/g, function(match) { var output = (FMT_STR + fmtStr).replace(/%[sdj]/g, function (match) {
switch (match) { switch (match) {
case '%s': return new String(args.shift()); case '%s': return new String(args.shift());
case '%d': return new Number(args.shift()); case '%d': return new Number(args.shift());
@ -67,61 +67,61 @@ function Log(name) {
this.name = name; this.name = name;
} }
Log.prototype._write = function(level, args) { Log.prototype._write = function (level, args) {
var data = format(level, this.name, args); var data = format(level, this.name, args);
console.error(data); console.error(data);
}; };
Log.prototype.isTraceEnabled = function() { Log.prototype.isTraceEnabled = function () {
return (LEVELS.Trace >= LEVELS[level]); return (LEVELS.Trace >= LEVELS[level]);
}; };
Log.prototype.trace = function() { Log.prototype.trace = function () {
if (this.isTraceEnabled()) if (this.isTraceEnabled())
this._write('TRACE', Array.prototype.slice.call(arguments)); this._write('TRACE', Array.prototype.slice.call(arguments));
}; };
Log.prototype.isDebugEnabled = function() { Log.prototype.isDebugEnabled = function () {
return (LEVELS.Debug >= LEVELS[level]); return (LEVELS.Debug >= LEVELS[level]);
}; };
Log.prototype.debug = function() { Log.prototype.debug = function () {
if (this.isDebugEnabled()) if (this.isDebugEnabled())
this._write('DEBUG', Array.prototype.slice.call(arguments)); this._write('DEBUG', Array.prototype.slice.call(arguments));
}; };
Log.prototype.isInfoEnabled = function() { Log.prototype.isInfoEnabled = function () {
return (LEVELS.Info >= LEVELS[level]); return (LEVELS.Info >= LEVELS[level]);
}; };
Log.prototype.info = function() { Log.prototype.info = function () {
if (this.isInfoEnabled()) if (this.isInfoEnabled())
this._write('INFO', Array.prototype.slice.call(arguments)); this._write('INFO', Array.prototype.slice.call(arguments));
}; };
Log.prototype.isWarnEnabled = function() { Log.prototype.isWarnEnabled = function () {
return (LEVELS.Warn >= LEVELS[level]); return (LEVELS.Warn >= LEVELS[level]);
}; };
Log.prototype.warn = function() { Log.prototype.warn = function () {
if (this.isWarnEnabled()) if (this.isWarnEnabled())
this._write('WARN', Array.prototype.slice.call(arguments)); this._write('WARN', Array.prototype.slice.call(arguments));
}; };
Log.prototype.isErrorEnabled = function() { Log.prototype.isErrorEnabled = function () {
return (LEVELS.Error >= LEVELS[level]); return (LEVELS.Error >= LEVELS[level]);
}; };
Log.prototype.error = function() { Log.prototype.error = function () {
if (this.isErrorEnabled()) if (this.isErrorEnabled())
this._write('ERROR', Array.prototype.slice.call(arguments)); this._write('ERROR', Array.prototype.slice.call(arguments));
}; };
Log.prototype.isFatalEnabled = function() { Log.prototype.isFatalEnabled = function () {
return (LEVELS.Fatal >= LEVELS[level]); return (LEVELS.Fatal >= LEVELS[level]);
}; };
Log.prototype.fatal = function() { Log.prototype.fatal = function () {
if (this.isFatalEnabled()) if (this.isFatalEnabled())
this._write('FATAL', Array.prototype.slice.call(arguments)); this._write('FATAL', Array.prototype.slice.call(arguments));
}; };
@ -129,7 +129,7 @@ Log.prototype.fatal = function() {
module.exports = { module.exports = {
setLevel: function(l) { setLevel: function (l) {
l = l.charAt(0).toUpperCase() + l.slice(1).toLowerCase(); l = l.charAt(0).toUpperCase() + l.slice(1).toLowerCase();
if (LEVELS[l] !== undefined) if (LEVELS[l] !== undefined)
level = l; level = l;
@ -137,14 +137,14 @@ module.exports = {
return level; return level;
}, },
getLogger: function(name) { getLogger: function (name) {
if (!name || typeof(name) !== 'string') if (!name || typeof (name) !== 'string')
throw new TypeError('name (string) required'); throw new TypeError('name (string) required');
return new Log(name); return new Log(name);
}, },
setGlobalLogLevel: function(l) { setGlobalLogLevel: function (l) {
l = l.charAt(0).toUpperCase() + l.slice(1).toLowerCase(); l = l.charAt(0).toUpperCase() + l.slice(1).toLowerCase();
if (LEVELS[l] !== undefined) if (LEVELS[l] !== undefined)
level = l; level = l;

View File

@ -22,9 +22,9 @@ var Ber = asn1.Ber;
function AbandonRequest(options) { function AbandonRequest(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.abandonID && typeof(options.abandonID) !== 'number') if (options.abandonID && typeof (options.abandonID) !== 'number')
throw new TypeError('abandonID must be a number'); throw new TypeError('abandonID must be a number');
} else { } else {
options = {}; options = {};
@ -35,14 +35,13 @@ function AbandonRequest(options) {
this.abandonID = options.abandonID || 0; this.abandonID = options.abandonID || 0;
var self = this; this.__defineGetter__('type', function () { return 'AbandonRequest'; });
this.__defineGetter__('type', function() { return 'AbandonRequest'; });
} }
util.inherits(AbandonRequest, LDAPMessage); util.inherits(AbandonRequest, LDAPMessage);
module.exports = AbandonRequest; module.exports = AbandonRequest;
AbandonRequest.prototype._parse = function(ber, length) { AbandonRequest.prototype._parse = function (ber, length) {
assert.ok(ber); assert.ok(ber);
assert.ok(length); assert.ok(length);
@ -71,13 +70,13 @@ AbandonRequest.prototype._parse = function(ber, length) {
}; };
AbandonRequest.prototype._toBer = function(ber) { AbandonRequest.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
var i = this.abandonID; var i = this.abandonID;
var sz = 4; var sz = 4;
while ((((i & 0xff800000) == 0) || ((i & 0xff800000) == 0xff800000)) && while ((((i & 0xff800000) === 0) || ((i & 0xff800000) === 0xff800000)) &&
(sz > 1)) { (sz > 1)) {
sz--; sz--;
i <<= 8; i <<= 8;
@ -93,11 +92,10 @@ AbandonRequest.prototype._toBer = function(ber) {
}; };
AbandonRequest.prototype._json = function(j) { AbandonRequest.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.abandonID = this.abandonID; j.abandonID = this.abandonID;
return j; return j;
}; };

View File

@ -13,20 +13,20 @@ var Protocol = require('../protocol');
function AbandonResponse(options) { function AbandonResponse(options) {
if (!options) if (!options)
options = {}; options = {};
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
options.protocolOp = 0; options.protocolOp = 0;
LDAPMessage.call(this, options); LDAPMessage.call(this, options);
this.__defineGetter__('type', function() { return 'AbandonResponse'; }); this.__defineGetter__('type', function () { return 'AbandonResponse'; });
} }
util.inherits(AbandonResponse, LDAPMessage); util.inherits(AbandonResponse, LDAPMessage);
module.exports = AbandonResponse; module.exports = AbandonResponse;
AbandonResponse.prototype.end = function(status) {}; AbandonResponse.prototype.end = function (status) {};
AbandonResponse.prototype._json = function(j) { AbandonResponse.prototype._json = function (j) {
return j; return j;
}; };

View File

@ -22,14 +22,14 @@ var Ber = asn1.Ber;
function AddRequest(options) { function AddRequest(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.entry && !(options.entry instanceof dn.DN)) if (options.entry && !(options.entry instanceof dn.DN))
throw new TypeError('options.entry must be a DN'); throw new TypeError('options.entry must be a DN');
if (options.attributes) { if (options.attributes) {
if (!Array.isArray(options.attributes)) if (!Array.isArray(options.attributes))
throw new TypeError('options.attributes must be [Attribute]'); throw new TypeError('options.attributes must be [Attribute]');
options.attributes.forEach(function(a) { options.attributes.forEach(function (a) {
if (!Attribute.isAttribute(a)) if (!Attribute.isAttribute(a))
throw new TypeError('options.attributes must be [Attribute]'); throw new TypeError('options.attributes must be [Attribute]');
}); });
@ -45,14 +45,14 @@ function AddRequest(options) {
this.attributes = options.attributes ? options.attributes.slice(0) : []; this.attributes = options.attributes ? options.attributes.slice(0) : [];
var self = this; var self = this;
this.__defineGetter__('type', function() { return 'AddRequest'; }); this.__defineGetter__('type', function () { return 'AddRequest'; });
this.__defineGetter__('_dn', function() { return self.entry; }); this.__defineGetter__('_dn', function () { return self.entry; });
} }
util.inherits(AddRequest, LDAPMessage); util.inherits(AddRequest, LDAPMessage);
module.exports = AddRequest; module.exports = AddRequest;
AddRequest.prototype._parse = function(ber) { AddRequest.prototype._parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.entry = dn.parse(ber.readString()); this.entry = dn.parse(ber.readString());
@ -76,12 +76,12 @@ AddRequest.prototype._parse = function(ber) {
}; };
AddRequest.prototype._toBer = function(ber) { AddRequest.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.entry.toString()); ber.writeString(this.entry.toString());
ber.startSequence(); ber.startSequence();
this.attributes.forEach(function(a) { this.attributes.forEach(function (a) {
a.toBer(ber); a.toBer(ber);
}); });
ber.endSequence(); ber.endSequence();
@ -90,13 +90,13 @@ AddRequest.prototype._toBer = function(ber) {
}; };
AddRequest.prototype._json = function(j) { AddRequest.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.entry = this.entry.toString(); j.entry = this.entry.toString();
j.attributes = []; j.attributes = [];
this.attributes.forEach(function(a) { this.attributes.forEach(function (a) {
j.attributes.push(a.json); j.attributes.push(a.json);
}); });
@ -104,45 +104,47 @@ AddRequest.prototype._json = function(j) {
}; };
AddRequest.prototype.indexOf = function(attr) { AddRequest.prototype.indexOf = function (attr) {
if (!attr || typeof(attr) !== 'string') if (!attr || typeof (attr) !== 'string')
throw new TypeError('attr (string) required'); throw new TypeError('attr (string) required');
for (var i = 0; i < this.attributes.length; i++) for (var i = 0; i < this.attributes.length; i++) {
if (this.attributes[i].type === attr) if (this.attributes[i].type === attr)
return i; return i;
}
return -1; return -1;
}; };
AddRequest.prototype.attributeNames = function() { AddRequest.prototype.attributeNames = function () {
var attrs = []; var attrs = [];
for (var i = 0; i < this.attributes.length; i++) for (var i = 0; i < this.attributes.length; i++)
attrs.push[this.attributes[i].type.toLowerCase()]; attrs.push(this.attributes[i].type.toLowerCase());
return attrs; return attrs;
}; };
AddRequest.prototype.getAttribute = function(name) { AddRequest.prototype.getAttribute = function (name) {
if (!name || typeof(name) !== 'string') if (!name || typeof (name) !== 'string')
throw new TypeError('attribute name (string) required'); throw new TypeError('attribute name (string) required');
name = name.toLowerCase(); name = name.toLowerCase();
for (var i = 0; i < this.attributes.length; i++) for (var i = 0; i < this.attributes.length; i++) {
if (this.attributes[i].type === name) if (this.attributes[i].type === name)
return this.attribute[i]; return this.attribute[i];
}
return null; return null;
}; };
AddRequest.prototype.addAttribute = function(attr) { AddRequest.prototype.addAttribute = function (attr) {
if (!(attr instanceof Attribute)) if (!(attr instanceof Attribute))
throw new TypeEroror('attribute (Attribute) required'); throw new TypeError('attribute (Attribute) required');
return this.attributes.push(attr); return this.attributes.push(attr);
}; };
@ -163,7 +165,7 @@ AddRequest.prototype.addAttribute = function(attr) {
* *
* @return {Object} that looks like the above. * @return {Object} that looks like the above.
*/ */
AddRequest.prototype.toObject = function() { AddRequest.prototype.toObject = function () {
var self = this; var self = this;
var obj = { var obj = {
@ -174,11 +176,11 @@ AddRequest.prototype.toObject = function() {
if (!this.attributes || !this.attributes.length) if (!this.attributes || !this.attributes.length)
return obj; return obj;
this.attributes.forEach(function(a) { this.attributes.forEach(function (a) {
if (!obj.attributes[a.type]) if (!obj.attributes[a.type])
obj.attributes[a.type] = []; obj.attributes[a.type] = [];
a.vals.forEach(function(v) { a.vals.forEach(function (v) {
if (obj.attributes[a.type].indexOf(v) === -1) if (obj.attributes[a.type].indexOf(v) === -1)
obj.attributes[a.type].push(v); obj.attributes[a.type].push(v);
}); });

View File

@ -11,7 +11,7 @@ var Protocol = require('../protocol');
function AddResponse(options) { function AddResponse(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
} else { } else {
options = {}; options = {};

View File

@ -24,7 +24,7 @@ var LDAP_BIND_SASL = 'sasl';
///--- API ///--- API
function BindRequest(options) { function BindRequest(options) {
if (options && typeof(options) !== 'object') if (options && typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
options = options || {}; options = options || {};
@ -38,14 +38,14 @@ function BindRequest(options) {
this.credentials = options.credentials || ''; this.credentials = options.credentials || '';
var self = this; var self = this;
this.__defineGetter__('type', function() { return 'BindRequest'; }); this.__defineGetter__('type', function () { return 'BindRequest'; });
this.__defineGetter__('_dn', function() { return self.name; }); this.__defineGetter__('_dn', function () { return self.name; });
} }
util.inherits(BindRequest, LDAPMessage); util.inherits(BindRequest, LDAPMessage);
module.exports = BindRequest; module.exports = BindRequest;
BindRequest.prototype._parse = function(ber) { BindRequest.prototype._parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.version = ber.readInt(); this.version = ber.readInt();
@ -64,7 +64,7 @@ BindRequest.prototype._parse = function(ber) {
}; };
BindRequest.prototype._toBer = function(ber) { BindRequest.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeInt(this.version); ber.writeInt(this.version);
@ -76,7 +76,7 @@ BindRequest.prototype._toBer = function(ber) {
}; };
BindRequest.prototype._json = function(j) { BindRequest.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.version = this.version; j.version = this.version;

View File

@ -11,7 +11,7 @@ var Protocol = require('../protocol');
function BindResponse(options) { function BindResponse(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
} else { } else {
options = {}; options = {};
@ -22,4 +22,3 @@ function BindResponse(options) {
} }
util.inherits(BindResponse, LDAPResult); util.inherits(BindResponse, LDAPResult);
module.exports = BindResponse; module.exports = BindResponse;

View File

@ -15,13 +15,13 @@ var Protocol = require('../protocol');
function CompareRequest(options) { function CompareRequest(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.entry && !(options.entry instanceof dn.DN)) if (options.entry && !(options.entry instanceof dn.DN))
throw new TypeError('options.entry must be a DN'); throw new TypeError('options.entry must be a DN');
if (options.attribute && typeof(options.attribute) !== 'string') if (options.attribute && typeof (options.attribute) !== 'string')
throw new TypeError('options.attribute must be a string'); throw new TypeError('options.attribute must be a string');
if (options.value && typeof(options.value) !== 'string') if (options.value && typeof (options.value) !== 'string')
throw new TypeError('options.value must be a string'); throw new TypeError('options.value must be a string');
} else { } else {
options = {}; options = {};
@ -35,8 +35,8 @@ function CompareRequest(options) {
this.value = options.value || ''; this.value = options.value || '';
var self = this; var self = this;
this.__defineGetter__('type', function() { return 'CompareRequest'; }); this.__defineGetter__('type', function () { return 'CompareRequest'; });
this.__defineGetter__('_dn', function() { this.__defineGetter__('_dn', function () {
return self.entry ? self.entry.toString() : ''; return self.entry ? self.entry.toString() : '';
}); });
} }
@ -44,7 +44,7 @@ util.inherits(CompareRequest, LDAPMessage);
module.exports = CompareRequest; module.exports = CompareRequest;
CompareRequest.prototype._parse = function(ber) { CompareRequest.prototype._parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.entry = dn.parse(ber.readString()); this.entry = dn.parse(ber.readString());
@ -57,7 +57,7 @@ CompareRequest.prototype._parse = function(ber) {
}; };
CompareRequest.prototype._toBer = function(ber) { CompareRequest.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.entry.toString()); ber.writeString(this.entry.toString());
@ -70,7 +70,7 @@ CompareRequest.prototype._toBer = function(ber) {
}; };
CompareRequest.prototype._json = function(j) { CompareRequest.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.entry = this.entry.toString(); j.entry = this.entry.toString();

View File

@ -11,7 +11,7 @@ var Protocol = require('../protocol');
function CompareResponse(options) { function CompareResponse(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
} else { } else {
options = {}; options = {};
@ -24,9 +24,9 @@ util.inherits(CompareResponse, LDAPResult);
module.exports = CompareResponse; module.exports = CompareResponse;
CompareResponse.prototype.end = function(matches) { CompareResponse.prototype.end = function (matches) {
var status = 0x06; var status = 0x06;
if (typeof(matches) === 'boolean') { if (typeof (matches) === 'boolean') {
if (!matches) if (!matches)
status = 0x05; // Compare false status = 0x05; // Compare false
} else { } else {

View File

@ -22,7 +22,7 @@ var Ber = asn1.Ber;
function DeleteRequest(options) { function DeleteRequest(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.entry && !(options.entry instanceof dn.DN)) if (options.entry && !(options.entry instanceof dn.DN))
throw new TypeError('options.entry must be a DN'); throw new TypeError('options.entry must be a DN');
@ -36,14 +36,14 @@ function DeleteRequest(options) {
this.entry = options.entry || null; this.entry = options.entry || null;
var self = this; var self = this;
this.__defineGetter__('type', function() { return 'DeleteRequest'; }); this.__defineGetter__('type', function () { return 'DeleteRequest'; });
this.__defineGetter__('_dn', function() { return self.entry; }); this.__defineGetter__('_dn', function () { return self.entry; });
} }
util.inherits(DeleteRequest, LDAPMessage); util.inherits(DeleteRequest, LDAPMessage);
module.exports = DeleteRequest; module.exports = DeleteRequest;
DeleteRequest.prototype._parse = function(ber, length) { DeleteRequest.prototype._parse = function (ber, length) {
assert.ok(ber); assert.ok(ber);
this.entry = dn.parse(ber.buffer.slice(0, length).toString('utf8')); this.entry = dn.parse(ber.buffer.slice(0, length).toString('utf8'));
@ -53,7 +53,7 @@ DeleteRequest.prototype._parse = function(ber, length) {
}; };
DeleteRequest.prototype._toBer = function(ber) { DeleteRequest.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
var buf = new Buffer(this.entry.toString()); var buf = new Buffer(this.entry.toString());
@ -64,7 +64,7 @@ DeleteRequest.prototype._toBer = function(ber) {
}; };
DeleteRequest.prototype._json = function(j) { DeleteRequest.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.entry = this.entry; j.entry = this.entry;

View File

@ -10,7 +10,7 @@ var Protocol = require('../protocol');
function DeleteResponse(options) { function DeleteResponse(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
} else { } else {
options = {}; options = {};

View File

@ -23,11 +23,11 @@ var Ber = asn1.Ber;
function ExtendedRequest(options) { function ExtendedRequest(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.requestName && typeof(options.requestName) !== 'string') if (options.requestName && typeof (options.requestName) !== 'string')
throw new TypeError('options.requestName must be a string'); throw new TypeError('options.requestName must be a string');
if (options.requestValue && typeof(options.requestValue) !== 'string') if (options.requestValue && typeof (options.requestValue) !== 'string')
throw new TypeError('options.requestValue must be a string'); throw new TypeError('options.requestValue must be a string');
} else { } else {
options = {}; options = {};
@ -39,22 +39,22 @@ function ExtendedRequest(options) {
this.requestName = options.requestName || ''; this.requestName = options.requestName || '';
this.requestValue = options.requestValue || undefined; this.requestValue = options.requestValue || undefined;
this.__defineGetter__('type', function() { return 'ExtendedRequest'; }); this.__defineGetter__('type', function () { return 'ExtendedRequest'; });
this.__defineGetter__('_dn', function() { return this.requestName; }); this.__defineGetter__('_dn', function () { return this.requestName; });
this.__defineGetter__('name', function() { this.__defineGetter__('name', function () {
return this.requestName; return this.requestName;
}); });
this.__defineGetter__('value', function() { this.__defineGetter__('value', function () {
return this.requestValue; return this.requestValue;
}); });
this.__defineSetter__('name', function(name) { this.__defineSetter__('name', function (name) {
if (typeof(name) !== 'string') if (typeof (name) !== 'string')
throw new TypeError('name must be a string'); throw new TypeError('name must be a string');
this.requestName = name; this.requestName = name;
}); });
this.__defineSetter__('value', function(val) { this.__defineSetter__('value', function (val) {
if (typeof(val) !== 'string') if (typeof (val) !== 'string')
throw new TypeError('value must be a string'); throw new TypeError('value must be a string');
this.requestValue = val; this.requestValue = val;
@ -64,7 +64,7 @@ util.inherits(ExtendedRequest, LDAPMessage);
module.exports = ExtendedRequest; module.exports = ExtendedRequest;
ExtendedRequest.prototype._parse = function(ber) { ExtendedRequest.prototype._parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.requestName = ber.readString(0x80); this.requestName = ber.readString(0x80);
@ -75,7 +75,7 @@ ExtendedRequest.prototype._parse = function(ber) {
}; };
ExtendedRequest.prototype._toBer = function(ber) { ExtendedRequest.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.requestName, 0x80); ber.writeString(this.requestName, 0x80);
@ -86,7 +86,7 @@ ExtendedRequest.prototype._toBer = function(ber) {
}; };
ExtendedRequest.prototype._json = function(j) { ExtendedRequest.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.requestName = this.requestName; j.requestName = this.requestName;

View File

@ -11,11 +11,11 @@ var Protocol = require('../protocol');
function ExtendedResponse(options) { function ExtendedResponse(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.responseName && typeof(options.responseName) !== 'string') if (options.responseName && typeof (options.responseName) !== 'string')
throw new TypeError('options.responseName must be a string'); throw new TypeError('options.responseName must be a string');
if (options.responseValue && typeof(options.responseValue) !== 'string') if (options.responseValue && typeof (options.responseValue) !== 'string')
throw new TypeError('options.responseValue must be a string'); throw new TypeError('options.responseValue must be a string');
} else { } else {
options = {}; options = {};
@ -27,20 +27,20 @@ function ExtendedResponse(options) {
options.protocolOp = Protocol.LDAP_REP_EXTENSION; options.protocolOp = Protocol.LDAP_REP_EXTENSION;
LDAPResult.call(this, options); LDAPResult.call(this, options);
this.__defineGetter__('name', function() { this.__defineGetter__('name', function () {
return this.responseName; return this.responseName;
}); });
this.__defineGetter__('value', function() { this.__defineGetter__('value', function () {
return this.responseValue; return this.responseValue;
}); });
this.__defineSetter__('name', function(name) { this.__defineSetter__('name', function (name) {
if (typeof(name) !== 'string') if (typeof (name) !== 'string')
throw new TypeError('name must be a string'); throw new TypeError('name must be a string');
this.responseName = name; this.responseName = name;
}); });
this.__defineSetter__('value', function(val) { this.__defineSetter__('value', function (val) {
if (typeof(val) !== 'string') if (typeof (val) !== 'string')
throw new TypeError('value must be a string'); throw new TypeError('value must be a string');
this.responseValue = val; this.responseValue = val;
@ -50,7 +50,7 @@ util.inherits(ExtendedResponse, LDAPResult);
module.exports = ExtendedResponse; module.exports = ExtendedResponse;
ExtendedResponse.prototype._parse = function(ber) { ExtendedResponse.prototype._parse = function (ber) {
assert.ok(ber); assert.ok(ber);
if (!LDAPResult.prototype._parse.call(this, ber)) if (!LDAPResult.prototype._parse.call(this, ber))
@ -65,7 +65,7 @@ ExtendedResponse.prototype._parse = function(ber) {
}; };
ExtendedResponse.prototype._toBer = function(ber) { ExtendedResponse.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
if (!LDAPResult.prototype._toBer.call(this, ber)) if (!LDAPResult.prototype._toBer.call(this, ber))
@ -80,7 +80,7 @@ ExtendedResponse.prototype._toBer = function(ber) {
}; };
ExtendedResponse.prototype._json = function(j) { ExtendedResponse.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j = LDAPResult.prototype._json.call(this, j); j = LDAPResult.prototype._json.call(this, j);

View File

@ -30,7 +30,7 @@ var getControl = require('../controls').getControl;
* @param {Object} options stuff. * @param {Object} options stuff.
*/ */
function LDAPMessage(options) { function LDAPMessage(options) {
if (!options || typeof(options) !== 'object') if (!options || typeof (options) !== 'object')
throw new TypeError('options (object) required'); throw new TypeError('options (object) required');
this.messageID = options.messageID || 0; this.messageID = options.messageID || 0;
@ -40,10 +40,10 @@ function LDAPMessage(options) {
this.log4js = options.log4js || logStub; this.log4js = options.log4js || logStub;
var self = this; var self = this;
this.__defineGetter__('id', function() { return self.messageID; }); this.__defineGetter__('id', function () { return self.messageID; });
this.__defineGetter__('dn', function() { return self._dn || ''; }); this.__defineGetter__('dn', function () { return self._dn || ''; });
this.__defineGetter__('type', function() { return 'LDAPMessage'; }); this.__defineGetter__('type', function () { return 'LDAPMessage'; });
this.__defineGetter__('json', function() { this.__defineGetter__('json', function () {
var j = { var j = {
messageID: self.messageID, messageID: self.messageID,
protocolOp: self.type protocolOp: self.type
@ -52,7 +52,7 @@ function LDAPMessage(options) {
j.controls = self.controls; j.controls = self.controls;
return j; return j;
}); });
this.__defineGetter__('log', function() { this.__defineGetter__('log', function () {
if (!self._log) if (!self._log)
self._log = self.log4js.getLogger(self.type); self._log = self.log4js.getLogger(self.type);
return self._log; return self._log;
@ -61,12 +61,12 @@ function LDAPMessage(options) {
module.exports = LDAPMessage; module.exports = LDAPMessage;
LDAPMessage.prototype.toString = function() { LDAPMessage.prototype.toString = function () {
return JSON.stringify(this.json); return JSON.stringify(this.json);
}; };
LDAPMessage.prototype.parse = function(ber) { LDAPMessage.prototype.parse = function (ber) {
assert.ok(ber); assert.ok(ber);
if (this.log.isTraceEnabled()) if (this.log.isTraceEnabled())
@ -92,7 +92,7 @@ LDAPMessage.prototype.parse = function(ber) {
}; };
LDAPMessage.prototype.toBer = function() { LDAPMessage.prototype.toBer = function () {
var writer = new BerWriter(); var writer = new BerWriter();
writer.startSequence(); writer.startSequence();
writer.writeInt(this.messageID); writer.writeInt(this.messageID);
@ -104,7 +104,7 @@ LDAPMessage.prototype.toBer = function() {
if (this.controls && this.controls.length) { if (this.controls && this.controls.length) {
writer.startSequence(0xa0); writer.startSequence(0xa0);
this.controls.forEach(function(c) { this.controls.forEach(function (c) {
c.toBer(writer); c.toBer(writer);
}); });
writer.endSequence(); writer.endSequence();

View File

@ -22,14 +22,14 @@ var Ber = asn1.Ber;
function ModifyDNRequest(options) { function ModifyDNRequest(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.entry && !(options.entry instanceof dn.DN)) if (options.entry && !(options.entry instanceof dn.DN))
throw new TypeError('options.entry must be a DN'); throw new TypeError('options.entry must be a DN');
if (options.newRdn && !(options.newRdn instanceof dn.DN)) if (options.newRdn && !(options.newRdn instanceof dn.DN))
throw new TypeError('options.newRdn must be a DN'); throw new TypeError('options.newRdn must be a DN');
if (options.deleteOldRdn !== undefined && if (options.deleteOldRdn !== undefined &&
typeof(options.deleteOldRdn) !== 'boolean') typeof (options.deleteOldRdn) !== 'boolean')
throw new TypeError('options.deleteOldRdn must be a boolean'); throw new TypeError('options.deleteOldRdn must be a boolean');
if (options.newSuperior && !(options.newSuperior instanceof dn.DN)) if (options.newSuperior && !(options.newSuperior instanceof dn.DN))
throw new TypeError('options.newSuperior must be a DN'); throw new TypeError('options.newSuperior must be a DN');
@ -47,14 +47,14 @@ function ModifyDNRequest(options) {
this.newSuperior = options.newSuperior || null; this.newSuperior = options.newSuperior || null;
var self = this; var self = this;
this.__defineGetter__('type', function() { return 'ModifyDNRequest'; }); this.__defineGetter__('type', function () { return 'ModifyDNRequest'; });
this.__defineGetter__('_dn', function() { return self.entry; }); this.__defineGetter__('_dn', function () { return self.entry; });
} }
util.inherits(ModifyDNRequest, LDAPMessage); util.inherits(ModifyDNRequest, LDAPMessage);
module.exports = ModifyDNRequest; module.exports = ModifyDNRequest;
ModifyDNRequest.prototype._parse = function(ber) { ModifyDNRequest.prototype._parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.entry = dn.parse(ber.readString()); this.entry = dn.parse(ber.readString());
@ -67,7 +67,7 @@ ModifyDNRequest.prototype._parse = function(ber) {
}; };
ModifyDNRequest.prototype._toBer = function(ber) { ModifyDNRequest.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.entry.toString()); ber.writeString(this.entry.toString());
@ -80,7 +80,7 @@ ModifyDNRequest.prototype._toBer = function(ber) {
}; };
ModifyDNRequest.prototype._json = function(j) { ModifyDNRequest.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.entry = this.entry.toString(); j.entry = this.entry.toString();

View File

@ -10,7 +10,7 @@ var Protocol = require('../protocol');
function ModifyDNResponse(options) { function ModifyDNResponse(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
} else { } else {
options = {}; options = {};

View File

@ -7,6 +7,7 @@ var LDAPMessage = require('./message');
var LDAPResult = require('./result'); var LDAPResult = require('./result');
var dn = require('../dn'); var dn = require('../dn');
var Attribute = require('../attribute');
var Change = require('../change'); var Change = require('../change');
var Protocol = require('../protocol'); var Protocol = require('../protocol');
@ -16,14 +17,14 @@ var Protocol = require('../protocol');
function ModifyRequest(options) { function ModifyRequest(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.object && !(options.object instanceof dn.DN)) if (options.object && !(options.object instanceof dn.DN))
throw new TypeError('options.object must be a DN'); throw new TypeError('options.object must be a DN');
if (options.attributes) { if (options.attributes) {
if (!Array.isArray(options.attributes)) if (!Array.isArray(options.attributes))
throw new TypeError('options.attributes must be [Attribute]'); throw new TypeError('options.attributes must be [Attribute]');
options.attributes.forEach(function(a) { options.attributes.forEach(function (a) {
if (!(a instanceof Attribute)) if (!(a instanceof Attribute))
throw new TypeError('options.attributes must be [Attribute]'); throw new TypeError('options.attributes must be [Attribute]');
}); });
@ -39,14 +40,14 @@ function ModifyRequest(options) {
this.changes = options.changes ? options.changes.slice(0) : []; this.changes = options.changes ? options.changes.slice(0) : [];
var self = this; var self = this;
this.__defineGetter__('type', function() { return 'ModifyRequest'; }); this.__defineGetter__('type', function () { return 'ModifyRequest'; });
this.__defineGetter__('_dn', function() { return self.object; }); this.__defineGetter__('_dn', function () { return self.object; });
} }
util.inherits(ModifyRequest, LDAPMessage); util.inherits(ModifyRequest, LDAPMessage);
module.exports = ModifyRequest; module.exports = ModifyRequest;
ModifyRequest.prototype._parse = function(ber) { ModifyRequest.prototype._parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.object = dn.parse(ber.readString()); this.object = dn.parse(ber.readString());
@ -65,12 +66,12 @@ ModifyRequest.prototype._parse = function(ber) {
}; };
ModifyRequest.prototype._toBer = function(ber) { ModifyRequest.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.object.toString()); ber.writeString(this.object.toString());
ber.startSequence(); ber.startSequence();
this.changes.forEach(function(c) { this.changes.forEach(function (c) {
c.toBer(ber); c.toBer(ber);
}); });
ber.endSequence(); ber.endSequence();
@ -79,13 +80,13 @@ ModifyRequest.prototype._toBer = function(ber) {
}; };
ModifyRequest.prototype._json = function(j) { ModifyRequest.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.object = this.object; j.object = this.object;
j.changes = []; j.changes = [];
this.changes.forEach(function(c) { this.changes.forEach(function (c) {
j.changes.push(c.json); j.changes.push(c.json);
}); });

View File

@ -10,7 +10,7 @@ var Protocol = require('../protocol');
function ModifyResponse(options) { function ModifyResponse(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
} else { } else {
options = {}; options = {};

View File

@ -48,9 +48,9 @@ var BerReader = asn1.BerReader;
///--- API ///--- API
function Parser(options) { function Parser(options) {
if (!options || typeof(options) !== 'object') if (!options || typeof (options) !== 'object')
throw new TypeError('options (object) required'); throw new TypeError('options (object) required');
if (!options.log4js || typeof(options.log4js) !== 'object') if (!options.log4js || typeof (options.log4js) !== 'object')
throw new TypeError('options.log4js (object) required'); throw new TypeError('options.log4js (object) required');
EventEmitter.call(this); EventEmitter.call(this);
@ -63,11 +63,10 @@ util.inherits(Parser, EventEmitter);
module.exports = Parser; module.exports = Parser;
Parser.prototype.write = function(data) { Parser.prototype.write = function (data) {
if (!data || !Buffer.isBuffer(data)) if (!data || !Buffer.isBuffer(data))
throw new TypeError('data (buffer) required'); throw new TypeError('data (buffer) required');
var log = this.log;
var nextMessage = null; var nextMessage = null;
var self = this; var self = this;
@ -113,10 +112,9 @@ Parser.prototype.write = function(data) {
}; };
Parser.prototype.getMessage = function(ber) { Parser.prototype.getMessage = function (ber) {
assert.ok(ber); assert.ok(ber);
var log = this.log;
var self = this; var self = this;
var messageID = ber.readInt(); var messageID = ber.readInt();
@ -209,8 +207,7 @@ Parser.prototype.getMessage = function(ber) {
this.emit('error', this.emit('error',
new Error('protocolOp 0x' + new Error('protocolOp 0x' +
(type ? type.toString(16) : '??') + (type ? type.toString(16) : '??') +
' not supported' ' not supported'),
),
new LDAPResult({ new LDAPResult({
messageID: messageID, messageID: messageID,
protocolOp: type || Protocol.LDAP_REP_EXTENSION protocolOp: type || Protocol.LDAP_REP_EXTENSION
@ -225,4 +222,3 @@ Parser.prototype.getMessage = function(ber) {
log4js: self.log4js log4js: self.log4js
}); });
}; };

View File

@ -22,20 +22,20 @@ var BerWriter = asn1.BerWriter;
function LDAPResult(options) { function LDAPResult(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options (object) required'); throw new TypeError('options (object) required');
if (options.status && typeof(options.status) !== 'number') if (options.status && typeof (options.status) !== 'number')
throw new TypeError('options.status must be a number'); throw new TypeError('options.status must be a number');
if (options.matchedDN && typeof(options.matchedDN) !== 'string') if (options.matchedDN && typeof (options.matchedDN) !== 'string')
throw new TypeError('options.matchedDN must be a string'); throw new TypeError('options.matchedDN must be a string');
if (options.errorMessage && typeof(options.errorMessage) !== 'string') if (options.errorMessage && typeof (options.errorMessage) !== 'string')
throw new TypeError('options.errorMessage must be a string'); throw new TypeError('options.errorMessage must be a string');
if (options.referrals) { if (options.referrals) {
if (!(options.referrals instanceof Array)) if (!(options.referrals instanceof Array))
throw new TypeError('options.referrrals must be an array[string]'); throw new TypeError('options.referrrals must be an array[string]');
options.referrals.forEach(function(r) { options.referrals.forEach(function (r) {
if (typeof(r) !== 'string') if (typeof (r) !== 'string')
throw new TypeError('options.referrals must be an array[string]'); throw new TypeError('options.referrals must be an array[string]');
}); });
} }
@ -52,16 +52,16 @@ function LDAPResult(options) {
this.connection = options.connection || null; this.connection = options.connection || null;
this.__defineGetter__('type', function() { return 'LDAPResult'; }); this.__defineGetter__('type', function () { return 'LDAPResult'; });
} }
util.inherits(LDAPResult, LDAPMessage); util.inherits(LDAPResult, LDAPMessage);
module.exports = LDAPResult; module.exports = LDAPResult;
LDAPResult.prototype.end = function(status) { LDAPResult.prototype.end = function (status) {
assert.ok(this.connection); assert.ok(this.connection);
if (typeof(status) === 'number') if (typeof (status) === 'number')
this.status = status; this.status = status;
var ber = this.toBer(); var ber = this.toBer();
@ -73,7 +73,7 @@ LDAPResult.prototype.end = function(status) {
this.connection.write(ber); this.connection.write(ber);
if (self._dtraceOp && self._dtraceId) { if (self._dtraceOp && self._dtraceId) {
dtrace.fire('server-' + self._dtraceOp + '-done', function() { dtrace.fire('server-' + self._dtraceOp + '-done', function () {
var c = self.connection || {ldap: {}}; var c = self.connection || {ldap: {}};
return [ return [
self._dtraceId || 0, self._dtraceId || 0,
@ -94,7 +94,7 @@ LDAPResult.prototype.end = function(status) {
}; };
LDAPResult.prototype._parse = function(ber) { LDAPResult.prototype._parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.status = ber.readEnumeration(); this.status = ber.readEnumeration();
@ -113,7 +113,7 @@ LDAPResult.prototype._parse = function(ber) {
}; };
LDAPResult.prototype._toBer = function(ber) { LDAPResult.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeEnumeration(this.status); ber.writeEnumeration(this.status);
@ -130,7 +130,7 @@ LDAPResult.prototype._toBer = function(ber) {
}; };
LDAPResult.prototype._json = function(j) { LDAPResult.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.status = this.status; j.status = this.status;

View File

@ -22,7 +22,7 @@ var BerWriter = asn1.BerWriter;
function SearchEntry(options) { function SearchEntry(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.objectName && !(options.objectName instanceof dn.DN)) if (options.objectName && !(options.objectName instanceof dn.DN))
throw new TypeError('options.objectName must be a DN'); throw new TypeError('options.objectName must be a DN');
@ -37,13 +37,13 @@ function SearchEntry(options) {
this.setAttributes(options.attributes || []); this.setAttributes(options.attributes || []);
var self = this; var self = this;
this.__defineGetter__('type', function() { return 'SearchEntry'; }); this.__defineGetter__('type', function () { return 'SearchEntry'; });
this.__defineGetter__('object', function() { this.__defineGetter__('object', function () {
var obj = { var obj = {
dn: self.dn.toString(), dn: self.dn.toString(),
controls: [] controls: []
}; };
self.attributes.forEach(function(a) { self.attributes.forEach(function (a) {
if (a.vals && a.vals.length) { if (a.vals && a.vals.length) {
if (a.vals.length > 1) { if (a.vals.length > 1) {
obj[a.type] = a.vals.slice(); obj[a.type] = a.vals.slice();
@ -54,12 +54,12 @@ function SearchEntry(options) {
obj[a.type] = []; obj[a.type] = [];
} }
}); });
self.controls.forEach(function(element, index, array) { self.controls.forEach(function (element, index, array) {
obj.controls.push(element.json); obj.controls.push(element.json);
}); });
return obj; return obj;
}); });
this.__defineGetter__('_dn', function() { this.__defineGetter__('_dn', function () {
return self.objectName; return self.objectName;
}); });
} }
@ -67,21 +67,21 @@ util.inherits(SearchEntry, LDAPMessage);
module.exports = SearchEntry; module.exports = SearchEntry;
SearchEntry.prototype.addAttribute = function(attr) { SearchEntry.prototype.addAttribute = function (attr) {
if (!attr || typeof(attr) !== 'object') if (!attr || typeof (attr) !== 'object')
throw new TypeError('attr (attribute) required'); throw new TypeError('attr (attribute) required');
this.attributes.push(attr); this.attributes.push(attr);
}; };
SearchEntry.prototype.toObject = function() { SearchEntry.prototype.toObject = function () {
return this.object; return this.object;
}; };
SearchEntry.prototype.fromObject = function(obj) { SearchEntry.prototype.fromObject = function (obj) {
if (typeof(obj) !== 'object') if (typeof (obj) !== 'object')
throw new TypeError('object required'); throw new TypeError('object required');
var self = this; var self = this;
@ -92,19 +92,19 @@ SearchEntry.prototype.fromObject = function(obj) {
obj = obj.attributes; obj = obj.attributes;
this.attributes = []; this.attributes = [];
Object.keys(obj).forEach(function(k) { Object.keys(obj).forEach(function (k) {
self.attributes.push(new Attribute({type: k, vals: obj[k]})); self.attributes.push(new Attribute({type: k, vals: obj[k]}));
}); });
return true; return true;
}; };
SearchEntry.prototype.setAttributes = function(obj) { SearchEntry.prototype.setAttributes = function (obj) {
if (typeof(obj) !== 'object') if (typeof (obj) !== 'object')
throw new TypeError('object required'); throw new TypeError('object required');
if (Array.isArray(obj)) { if (Array.isArray(obj)) {
obj.forEach(function(a) { obj.forEach(function (a) {
if (!Attribute.isAttribute(a)) if (!Attribute.isAttribute(a))
throw new TypeError('entry must be an Array of Attributes'); throw new TypeError('entry must be an Array of Attributes');
}); });
@ -113,10 +113,10 @@ SearchEntry.prototype.setAttributes = function(obj) {
var self = this; var self = this;
self.attributes = []; self.attributes = [];
Object.keys(obj).forEach(function(k) { Object.keys(obj).forEach(function (k) {
var attr = new Attribute({type: k}); var attr = new Attribute({type: k});
if (Array.isArray(obj[k])) { if (Array.isArray(obj[k])) {
obj[k].forEach(function(v) { obj[k].forEach(function (v) {
attr.addValue(v.toString()); attr.addValue(v.toString());
}); });
} else { } else {
@ -128,12 +128,12 @@ SearchEntry.prototype.setAttributes = function(obj) {
}; };
SearchEntry.prototype._json = function(j) { SearchEntry.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.objectName = this.objectName.toString(); j.objectName = this.objectName.toString();
j.attributes = []; j.attributes = [];
this.attributes.forEach(function(a) { this.attributes.forEach(function (a) {
j.attributes.push(a.json || a); j.attributes.push(a.json || a);
}); });
@ -141,7 +141,7 @@ SearchEntry.prototype._json = function(j) {
}; };
SearchEntry.prototype._parse = function(ber) { SearchEntry.prototype._parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.objectName = ber.readString(); this.objectName = ber.readString();
@ -158,12 +158,12 @@ SearchEntry.prototype._parse = function(ber) {
}; };
SearchEntry.prototype._toBer = function(ber) { SearchEntry.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.objectName.toString()); ber.writeString(this.objectName.toString());
ber.startSequence(); ber.startSequence();
this.attributes.forEach(function(a) { this.attributes.forEach(function (a) {
// This may or may not be an attribute // This may or may not be an attribute
ber = Attribute.toBer(a, ber); ber = Attribute.toBer(a, ber);
}); });
@ -171,6 +171,3 @@ SearchEntry.prototype._toBer = function(ber) {
return ber; return ber;
}; };

View File

@ -23,7 +23,7 @@ var parseURL = url.parse;
function SearchReference(options) { function SearchReference(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
if (options.objectName && !(options.objectName instanceof dn.DN)) if (options.objectName && !(options.objectName instanceof dn.DN))
throw new TypeError('options.objectName must be a DN'); throw new TypeError('options.objectName must be a DN');
@ -37,20 +37,20 @@ function SearchReference(options) {
this.uris = options.uris || []; this.uris = options.uris || [];
var self = this; var self = this;
this.__defineGetter__('type', function() { return 'SearchReference'; }); this.__defineGetter__('type', function () { return 'SearchReference'; });
this.__defineGetter__('object', function() { this.__defineGetter__('object', function () {
return { return {
dn: self.dn.toString(), dn: self.dn.toString(),
uris: self.uris.slice() uris: self.uris.slice()
}; };
}); });
this.__defineGetter__('_dn', function() { this.__defineGetter__('_dn', function () {
return new dn.DN(''); return new dn.DN('');
}); });
this.__defineGetter__('urls', function() { this.__defineGetter__('urls', function () {
return self.uris; return self.uris;
}); });
this.__defineSetter__('urls', function(u) { this.__defineSetter__('urls', function (u) {
self.uris = u.slice(); self.uris = u.slice();
}); });
} }
@ -58,13 +58,13 @@ util.inherits(SearchReference, LDAPMessage);
module.exports = SearchReference; module.exports = SearchReference;
SearchReference.prototype.toObject = function() { SearchReference.prototype.toObject = function () {
return this.object; return this.object;
}; };
SearchReference.prototype.fromObject = function(obj) { SearchReference.prototype.fromObject = function (obj) {
if (typeof(obj) !== 'object') if (typeof (obj) !== 'object')
throw new TypeError('object required'); throw new TypeError('object required');
this.uris = obj.uris ? obj.uris.slice() : []; this.uris = obj.uris ? obj.uris.slice() : [];
@ -72,14 +72,14 @@ SearchReference.prototype.fromObject = function(obj) {
return true; return true;
}; };
SearchReference.prototype._json = function(j) { SearchReference.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.uris = this.uris.slice(); j.uris = this.uris.slice();
return j; return j;
}; };
SearchReference.prototype._parse = function(ber, length) { SearchReference.prototype._parse = function (ber, length) {
assert.ok(ber); assert.ok(ber);
while (ber.offset < length) { while (ber.offset < length) {
@ -92,15 +92,12 @@ SearchReference.prototype._parse = function(ber, length) {
}; };
SearchReference.prototype._toBer = function(ber) { SearchReference.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
this.uris.forEach(function(u) { this.uris.forEach(function (u) {
ber.writeString(u.href || u); ber.writeString(u.href || u);
}); });
return ber; return ber;
}; };

View File

@ -24,7 +24,7 @@ var Ber = asn1.Ber;
function SearchRequest(options) { function SearchRequest(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
} else { } else {
options = {}; options = {};
@ -34,11 +34,11 @@ function SearchRequest(options) {
LDAPMessage.call(this, options); LDAPMessage.call(this, options);
var self = this; var self = this;
this.__defineGetter__('type', function() { return 'SearchRequest'; }); this.__defineGetter__('type', function () { return 'SearchRequest'; });
this.__defineGetter__('_dn', function() { this.__defineGetter__('_dn', function () {
return self.baseObject; return self.baseObject;
}); });
this.__defineGetter__('scope', function() { this.__defineGetter__('scope', function () {
switch (self._scope) { switch (self._scope) {
case Protocol.SCOPE_BASE_OBJECT: return 'base'; case Protocol.SCOPE_BASE_OBJECT: return 'base';
case Protocol.SCOPE_ONE_LEVEL: return 'one'; case Protocol.SCOPE_ONE_LEVEL: return 'one';
@ -47,8 +47,8 @@ function SearchRequest(options) {
throw new Error(self._scope + ' is an invalid search scope'); throw new Error(self._scope + ' is an invalid search scope');
} }
}); });
this.__defineSetter__('scope', function(s) { this.__defineSetter__('scope', function (s) {
if (typeof(s) === 'string') { if (typeof (s) === 'string') {
switch (s) { switch (s) {
case 'base': case 'base':
self._scope = Protocol.SCOPE_BASE_OBJECT; self._scope = Protocol.SCOPE_BASE_OBJECT;
@ -67,7 +67,7 @@ function SearchRequest(options) {
} }
}); });
this.baseObject = options.baseObject || new dn.DN([{}]); this.baseObject = options.baseObject || new dn.DN([ {} ]);
this.scope = options.scope || 'base'; this.scope = options.scope || 'base';
this.derefAliases = options.derefAliases || Protocol.NEVER_DEREF_ALIASES; this.derefAliases = options.derefAliases || Protocol.NEVER_DEREF_ALIASES;
this.sizeLimit = options.sizeLimit || 0; this.sizeLimit = options.sizeLimit || 0;
@ -80,7 +80,7 @@ util.inherits(SearchRequest, LDAPMessage);
module.exports = SearchRequest; module.exports = SearchRequest;
SearchRequest.prototype.newResult = function() { SearchRequest.prototype.newResult = function () {
var self = this; var self = this;
return new LDAPResult({ return new LDAPResult({
@ -90,7 +90,7 @@ SearchRequest.prototype.newResult = function() {
}; };
SearchRequest.prototype._parse = function(ber) { SearchRequest.prototype._parse = function (ber) {
assert.ok(ber); assert.ok(ber);
this.baseObject = dn.parse(ber.readString()); this.baseObject = dn.parse(ber.readString());
@ -114,7 +114,7 @@ SearchRequest.prototype._parse = function(ber) {
}; };
SearchRequest.prototype._toBer = function(ber) { SearchRequest.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
ber.writeString(this.baseObject.toString()); ber.writeString(this.baseObject.toString());
@ -129,7 +129,7 @@ SearchRequest.prototype._toBer = function(ber) {
ber.startSequence(Ber.Sequence | Ber.Constructor); ber.startSequence(Ber.Sequence | Ber.Constructor);
if (this.attributes && this.attributes.length) { if (this.attributes && this.attributes.length) {
this.attributes.forEach(function(a) { this.attributes.forEach(function (a) {
ber.writeString(a); ber.writeString(a);
}); });
} }
@ -139,7 +139,7 @@ SearchRequest.prototype._toBer = function(ber) {
}; };
SearchRequest.prototype._json = function(j) { SearchRequest.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
j.baseObject = this.baseObject; j.baseObject = this.baseObject;

View File

@ -19,7 +19,7 @@ var Protocol = require('../protocol');
function SearchResponse(options) { function SearchResponse(options) {
if (!options) if (!options)
options = {}; options = {};
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
options.protocolOp = Protocol.LDAP_REP_SEARCH; options.protocolOp = Protocol.LDAP_REP_SEARCH;
@ -40,12 +40,12 @@ module.exports = SearchResponse;
* @param {Boolean} nofiltering skip filtering notAttributes and '_' attributes. * @param {Boolean} nofiltering skip filtering notAttributes and '_' attributes.
* Defaults to 'false'. * Defaults to 'false'.
*/ */
SearchResponse.prototype.send = function(entry, nofiltering) { SearchResponse.prototype.send = function (entry, nofiltering) {
if (!entry || typeof(entry) !== 'object') if (!entry || typeof (entry) !== 'object')
throw new TypeError('entry (SearchEntry) required'); throw new TypeError('entry (SearchEntry) required');
if (nofiltering === undefined) if (nofiltering === undefined)
nofiltering = false; nofiltering = false;
if (typeof(nofiltering) !== 'boolean') if (typeof (nofiltering) !== 'boolean')
throw new TypeError('noFiltering must be a boolean'); throw new TypeError('noFiltering must be a boolean');
var self = this; var self = this;
@ -61,7 +61,7 @@ SearchResponse.prototype.send = function(entry, nofiltering) {
var savedAttrs = {}; var savedAttrs = {};
var all = (self.attributes.indexOf('*') !== -1); var all = (self.attributes.indexOf('*') !== -1);
Object.keys(entry.attributes).forEach(function(a) { Object.keys(entry.attributes).forEach(function (a) {
var _a = a.toLowerCase(); var _a = a.toLowerCase();
if (!nofiltering && _a.length && _a[0] === '_') { if (!nofiltering && _a.length && _a[0] === '_') {
savedAttrs[a] = entry.attributes[a]; savedAttrs[a] = entry.attributes[a];
@ -70,7 +70,7 @@ SearchResponse.prototype.send = function(entry, nofiltering) {
savedAttrs[a] = entry.attributes[a]; savedAttrs[a] = entry.attributes[a];
delete entry.attributes[a]; delete entry.attributes[a];
} else if (all) { } else if (all) {
// noop return;
} else if (self.attributes.length && self.attributes.indexOf(_a) === -1) { } else if (self.attributes.length && self.attributes.indexOf(_a) === -1) {
savedAttrs[a] = entry.attributes[a]; savedAttrs[a] = entry.attributes[a];
delete entry.attributes[a]; delete entry.attributes[a];
@ -79,7 +79,7 @@ SearchResponse.prototype.send = function(entry, nofiltering) {
var save = entry; var save = entry;
entry = new SearchEntry({ entry = new SearchEntry({
objectName: typeof(save.dn) === 'string' ? parseDN(save.dn) : save.dn, objectName: typeof (save.dn) === 'string' ? parseDN(save.dn) : save.dn,
messageID: self.messageID, messageID: self.messageID,
log4js: self.log4js log4js: self.log4js
}); });
@ -94,7 +94,7 @@ SearchResponse.prototype.send = function(entry, nofiltering) {
this.sentEntries++; this.sentEntries++;
if (self._dtraceOp && self._dtraceId) { if (self._dtraceOp && self._dtraceId) {
dtrace.fire('server-search-entry', function() { dtrace.fire('server-search-entry', function () {
var c = self.connection || {ldap: {}}; var c = self.connection || {ldap: {}};
return [ return [
self._dtraceId || 0, self._dtraceId || 0,
@ -108,7 +108,7 @@ SearchResponse.prototype.send = function(entry, nofiltering) {
} }
// Restore attributes // Restore attributes
Object.keys(savedAttrs).forEach(function(k) { Object.keys(savedAttrs).forEach(function (k) {
save.attributes[k] = savedAttrs[k]; save.attributes[k] = savedAttrs[k];
}); });
@ -120,8 +120,8 @@ SearchResponse.prototype.send = function(entry, nofiltering) {
SearchResponse.prototype.createSearchEntry = function(object) { SearchResponse.prototype.createSearchEntry = function (object) {
if (!object || typeof(object) !== 'object') if (!object || typeof (object) !== 'object')
throw new TypeError('object required'); throw new TypeError('object required');
var self = this; var self = this;
@ -137,7 +137,7 @@ SearchResponse.prototype.createSearchEntry = function(object) {
}; };
SearchResponse.prototype.createSearchReference = function(uris) { SearchResponse.prototype.createSearchReference = function (uris) {
if (!uris) if (!uris)
throw new TypeError('uris ([string]) required'); throw new TypeError('uris ([string]) required');
@ -145,7 +145,7 @@ SearchResponse.prototype.createSearchReference = function(uris) {
uris = [uris]; uris = [uris];
for (var i = 0; i < uris.length; i++) { for (var i = 0; i < uris.length; i++) {
if (typeof(uris[i]) == 'string') if (typeof (uris[i]) == 'string')
uris[i] = parseURL(uris[i]); uris[i] = parseURL(uris[i]);
} }

View File

@ -25,7 +25,7 @@ var RDN = dn.RDN;
function UnbindRequest(options) { function UnbindRequest(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
} else { } else {
options = {}; options = {};
@ -35,8 +35,8 @@ function UnbindRequest(options) {
LDAPMessage.call(this, options); LDAPMessage.call(this, options);
var self = this; var self = this;
this.__defineGetter__('type', function() { return 'UnbindRequest'; }); this.__defineGetter__('type', function () { return 'UnbindRequest'; });
this.__defineGetter__('_dn', function() { this.__defineGetter__('_dn', function () {
if (self.connection) if (self.connection)
return self.connection.ldap.bindDN; return self.connection.ldap.bindDN;
@ -47,21 +47,19 @@ util.inherits(UnbindRequest, LDAPMessage);
module.exports = UnbindRequest; module.exports = UnbindRequest;
UnbindRequest.prototype.newResult = function() { UnbindRequest.prototype.newResult = function () {
var self = this;
// This one is special, so just hack up the result object // This one is special, so just hack up the result object
function UnbindResponse(options) { function UnbindResponse(options) {
LDAPMessage.call(this, options); LDAPMessage.call(this, options);
this.__defineGetter__('type', function() { return 'UnbindResponse'; }); this.__defineGetter__('type', function () { return 'UnbindResponse'; });
} }
util.inherits(UnbindResponse, LDAPMessage); util.inherits(UnbindResponse, LDAPMessage);
UnbindResponse.prototype.end = function(status) { UnbindResponse.prototype.end = function (status) {
if (this.log.isTraceEnabled()) if (this.log.isTraceEnabled())
log.trace('%s: unbinding!', this.connection.ldap.id); this.log.trace('%s: unbinding!', this.connection.ldap.id);
this.connection.end(); this.connection.end();
}; };
UnbindResponse.prototype._json = function(j) { return j; }; UnbindResponse.prototype._json = function (j) { return j; };
return new UnbindResponse({ return new UnbindResponse({
messageID: 0, messageID: 0,
@ -71,21 +69,21 @@ UnbindRequest.prototype.newResult = function() {
}; };
UnbindRequest.prototype._parse = function(ber) { UnbindRequest.prototype._parse = function (ber) {
assert.ok(ber); assert.ok(ber);
return true; return true;
}; };
UnbindRequest.prototype._toBer = function(ber) { UnbindRequest.prototype._toBer = function (ber) {
assert.ok(ber); assert.ok(ber);
return ber; return ber;
}; };
UnbindRequest.prototype._json = function(j) { UnbindRequest.prototype._json = function (j) {
assert.ok(j); assert.ok(j);
return j; return j;

View File

@ -17,12 +17,12 @@ var Protocol = require('../protocol');
function UnbindResponse(options) { function UnbindResponse(options) {
if (!options) if (!options)
options = {}; options = {};
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
options.protocolOp = 0; options.protocolOp = 0;
LDAPMessage.call(this, options); LDAPMessage.call(this, options);
this.__defineGetter__('type', function() { return 'UnbindResponse'; }); this.__defineGetter__('type', function () { return 'UnbindResponse'; });
} }
util.inherits(UnbindResponse, LDAPMessage); util.inherits(UnbindResponse, LDAPMessage);
module.exports = UnbindResponse; module.exports = UnbindResponse;
@ -33,7 +33,7 @@ module.exports = UnbindResponse;
* *
* @param {Number} status completely ignored. * @param {Number} status completely ignored.
*/ */
UnbindResponse.prototype.end = function(status) { UnbindResponse.prototype.end = function (status) {
assert.ok(this.connection); assert.ok(this.connection);
if (this.log.isTraceEnabled()) if (this.log.isTraceEnabled())
@ -43,7 +43,7 @@ UnbindResponse.prototype.end = function(status) {
var self = this; var self = this;
if (self._dtraceOp && self._dtraceId) { if (self._dtraceOp && self._dtraceId) {
dtrace.fire('server-' + self._dtraceOp + '-done', function() { dtrace.fire('server-' + self._dtraceOp + '-done', function () {
var c = self.connection || {ldap: {}}; var c = self.connection || {ldap: {}};
return [ return [
self._dtraceId || 0, self._dtraceId || 0,
@ -58,6 +58,6 @@ UnbindResponse.prototype.end = function(status) {
}; };
UnbindResponse.prototype._json = function(j) { UnbindResponse.prototype._json = function (j) {
return j; return j;
}; };

View File

@ -1,115 +0,0 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert');
var dn = require('../dn');
var errors = require('../errors');
var logStub = require('../log_stub');
var getTransformer = require('./transform').getTransformer;
function createAddHandler(options) {
if (!options || typeof(options) !== 'object')
throw new TypeError('options (object) required');
if (!options.schema || typeof(options.schema) !== 'object')
throw new TypeError('options.schema (object) required');
var log4js = options.log4js || logStub;
var log = log4js.getLogger('SchemaAddHandler');
var schema = options.schema;
if (log.isDebugEnabled())
log.debug('Creating add schema handler with: %s',
JSON.stringify(options.schema, null, 2));
var CVErr = errors.ConstraintViolationError;
var NSAErr = errors.NoSuchAttributeError;
var OCVErr = errors.ObjectclassViolationError;
return function schemaAddHandler(req, res, next) {
var allowed = [];
var attributes = req.toObject().attributes;
var attrNames = Object.keys(attributes);
var i;
var j;
var k;
var key;
if (log.isDebugEnabled())
log.debug('%s running %j against schema', req.logId, attributes);
if (!attributes.objectclass)
return next(new OCVErr('no objectclass'));
for (i = 0; i < attributes.objectclass.length; i++) {
var oc = attributes.objectclass[i].toLowerCase();
if (!schema.objectclasses[oc])
return next(new NSAErr(oc + ' is not a known objectClass'));
// We can check required attributes right here in line. Mays we have to
// get the complete set of though. Also, to make checking much simpler,
// we just push the musts into the may list.
var must = schema.objectclasses[oc].must;
for (j = 0; j < must.length; j++) {
if (attrNames.indexOf(must[j]) === -1)
return next(new OCVErr(must[j] + ' is a required attribute'));
if (allowed.indexOf(must[j]) === -1)
allowed.push(must[j]);
}
schema.objectclasses[oc].may.forEach(function(attr) {
if (allowed.indexOf(attr) === -1)
allowed.push(attr);
});
}
// Now check that the entry's attributes are in the allowed list, and go
// ahead and transform the values as appropriate
for (i = 0; i < attrNames.length; i++) {
key = attrNames[i];
if (allowed.indexOf(key) === -1)
return next(new OCVErr(key + ' is not valid for the objectClasses ' +
attributes.objectclass.join()));
var transform = getTransformer(schema, key);
if (transform) {
for (j = 0; j < attributes[key].length; j++) {
try {
attributes[key][j] = transform(attributes[key][j]);
} catch (e) {
log.debug('%s Error parsing %s: %s', req.logId, k,
attributes[key][j],
e.stack);
return next(new CVErr(attrNames[i]));
}
}
for (j = 0; j < req.attributes.length; j++) {
if (req.attributes[j].type === key) {
req.attributes[j].vals = attributes[key];
break;
}
}
}
}
return next();
};
}
module.exports = createAddHandler;
// Now we have a modified attributes object we want to update
// "transparently" in the request.
// if (xformedValues) {
// attrNames.forEach(function(k) {
// for (var i = 0; i < req.attributes.length; i++) {
// if (req.attributes[i].type === k) {
// req.attributes[i].vals = attributes[k];
// return;
// }
// }
// });
// }

View File

@ -1,22 +0,0 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var createAddHandler = require('./add_handler');
var createModifyHandler = require('./mod_handler');
var createSearchHandler = require('./search_handler');
var parser = require('./parser');
///--- API
module.exports = {
createAddHandler: createAddHandler,
createModifyHandler: createModifyHandler,
createSearchHandler: createSearchHandler,
load: parser.load
};

View File

@ -1,59 +0,0 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert');
var dn = require('../dn');
var errors = require('../errors');
var logStub = require('../log_stub');
var getTransformer = require('./transform').getTransformer;
function createModifyHandler(options) {
if (!options || typeof(options) !== 'object')
throw new TypeError('options (object) required');
if (!options.schema || typeof(options.schema) !== 'object')
throw new TypeError('options.schema (object) required');
// TODO add a callback mechanism here so objectclass constraints can be
// enforced
var log4js = options.log4js || logStub;
var log = log4js.getLogger('SchemaModifyHandler');
var schema = options.schema;
var CVErr = errors.ConstraintViolationError;
var NSAErr = errors.NoSuchAttributeError;
var OCVErr = errors.ObjectclassViolationError;
return function schemaModifyHandler(req, res, next) {
if (log.isDebugEnabled())
log.debug('%s running %j against schema', req.logId, req.changes);
for (var i = 0; i < req.changes.length; i++) {
var mod = req.changes[i].modification;
var attribute = schema.attributes[mod.type];
if (!attribute)
return next(new NSAErr(mod.type));
if (!mod.vals || !mod.vals.length)
continue;
var transform = getTransformer(schema, mod.type);
if (transform) {
for (var j = 0; j < mod.vals.length; j++) {
try {
mod.vals[j] = transform(mod.vals[j]);
} catch (e) {
log.debug('%s Error parsing %s: %s', req.logId, mod.vals[j],
e.stack);
return next(new CVErr(mod.type + ': ' + mod.vals[j]));
}
}
}
}
return next();
}
}
module.exports = createModifyHandler;

View File

@ -1,437 +0,0 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert');
var fs = require('fs');
var dn = require('../dn');
var errors = require('../errors');
var logStub = require('../log_stub');
//// Attribute BNF
//
// AttributeTypeDescription = "(" whsp
// numericoid whsp ; AttributeType identifier
// [ "NAME" qdescrs ] ; name used in AttributeType
// [ "DESC" qdstring ] ; description
// [ "OBSOLETE" whsp ]
// [ "SUP" woid ] ; derived from this other
// ; AttributeType
// [ "EQUALITY" woid ; Matching Rule name
// [ "ORDERING" woid ; Matching Rule name
// [ "SUBSTR" woid ] ; Matching Rule name
// [ "SYNTAX" whsp noidlen whsp ] ; Syntax OID
// [ "SINGLE-VALUE" whsp ] ; default multi-valued
// [ "COLLECTIVE" whsp ] ; default not collective
// [ "NO-USER-MODIFICATION" whsp ]; default user modifiable
// [ "USAGE" whsp AttributeUsage ]; default userApplications
// whsp ")"
//
// AttributeUsage =
// "userApplications" /
// "directoryOperation" /
// "distributedOperation" / ; DSA-shared
// "dSAOperation" ; DSA-specific, value depends on server
/// Objectclass BNF
//
// ObjectClassDescription = "(" whsp
// numericoid whsp ; ObjectClass identifier
// [ "NAME" qdescrs ]
// [ "DESC" qdstring ]
// [ "OBSOLETE" whsp ]
// [ "SUP" oids ] ; Superior ObjectClasses
// [ ( "ABSTRACT" / "STRUCTURAL" / "AUXILIARY" ) whsp ]
// ; default structural
// [ "MUST" oids ] ; AttributeTypes
// [ "MAY" oids ] ; AttributeTypes
// whsp ")"
// This is some fugly code, and really not that robust, but LDAP schema
// is a pita with its optional ('s. So, whatever, it's good enough for our
// purposes (namely, dropping in the OpenLDAP schema). This took me a little
// over an hour to write, so there you go ;)
function parse(data) {
if (!data || typeof(data) !== 'string')
throw new TypeError('data (string) required');
var lines = [];
data.split('\n').forEach(function(l) {
if (/^#/.test(l) ||
/^objectidentifier/i.test(l) ||
!l.length)
return;
lines.push(l);
});
var attr;
var oc;
var syntax;
var attributes = [];
var objectclasses = [];
var depth = 0;
lines.join('\n').split(/\s+/).forEach(function(w) {
if (attr) {
if (w === '(') {
depth++;
} else if (w === ')') {
if (--depth === 0) {
if (attr._skip)
delete attr._skip;
attributes.push(attr);
attr = null;
}
return;
} else if (!attr.oid) {
attr.oid = w;
} else if (w === 'NAME') {
attr._names = [];
} else if (w === 'DESC') {
attr._desc = '';
} else if (w === 'OBSOLETE') {
attr.obsolete = true;
} else if (w === 'SUP') {
attr._sup = true;
} else if (attr._sup) {
attr.sup = w;
delete attr._sup;
} else if (w === 'EQUALITY') {
attr._equality = true;
} else if (w === 'ORDERING') {
attr._ordering = true;
} else if (w === 'SUBSTR') {
attr._substr = true;
} else if (w === 'SYNTAX') {
attr._syntax = true;
} else if (w === 'SINGLE-VALUE') {
attr.singleValue = true;
} else if (w === 'COLLECTIVE') {
attr.collective = true;
} else if (w === 'NO-USER-MODIFICATION') {
attr.noUserModification = true;
} else if (w === 'USAGE') {
attr._usage = true;
} else if (/^X-/.test(w)) {
attr._skip = true;
} else if (attr._skip) {
// noop
} else if (attr._usage) {
attr.usage = w;
delete attr._usage;
} else if (attr._syntax) {
attr.syntax = w;
delete attr._syntax;
} else if (attr._substr) {
attr.substr = w;
delete attr._substr;
} else if (attr._ordering) {
attr.ordering = w;
delete attr._ordering;
} else if (attr._equality) {
attr.equality = w;
delete attr._equality;
} else if (attr._desc !== undefined) {
attr._desc += w.replace(/\'/g, '');
if (/\'$/.test(w)) {
attr.desc = attr._desc;
delete attr._desc;
} else {
attr._desc += ' ';
}
} else if (attr._names) {
attr._names.push(w.replace(/\'/g, '').toLowerCase());
}
return;
}
if (oc) {
if (w === '(') {
depth++;
} else if (w === ')') {
if (--depth === 0) {
objectclasses.push(oc);
oc = null;
}
return;
} else if (w === '$') {
return;
} else if (!oc.oid) {
oc.oid = w;
} else if (w === 'NAME') {
oc._names = [];
} else if (w === 'DESC') {
oc._desc = '';
} else if (w === 'OBSOLETE') {
oc.obsolete = true;
} else if (w === 'SUP') {
oc._sup = [];
} else if (w === 'ABSTRACT') {
oc['abstract'] = true;
} else if (w === 'AUXILIARY') {
oc.auxiliary = true;
} else if (w === 'STRUCTURAL') {
oc.structural = true;
} else if (w === 'MUST') {
oc._must = [];
} else if (w === 'MAY') {
oc._may = [];
} else if (oc._may) {
oc._may.push(w.toLowerCase());
} else if (oc._must) {
oc._must.push(w.toLowerCase());
} else if (oc._sup) {
oc._sup.push(w.replace(/\'/g, '').toLowerCase());
} else if (oc._desc !== undefined) {
oc._desc += w.replace(/\'/g, '');
if (/\'$/.test(w)) {
oc.desc = oc._desc;
delete oc._desc;
} else {
oc._desc += ' ';
}
} else if (oc._names) {
oc._names.push(w.replace(/\'/g, '').toLowerCase());
}
return;
}
// Throw this away for now.
if (syntax) {
if (w === '(') {
depth++;
} else if (w === ')') {
if (--depth === 0) {
syntax = false;
}
}
return;
}
if (/^attributetype/i.test(w)) {
attr = {};
} else if (/^objectclass/i.test(w)) {
oc = {};
} else if (/^ldapsyntax/i.test(w)) {
syntax = true;
} else if (!w) {
// noop
} else {
throw new Error('Invalid token ' + w + ' in file ' + file);
}
});
// cleanup all the temporary arrays
var i;
for (i = 0; i < attributes.length; i++) {
if (!attributes[i]._names)
continue;
attributes[i].names = attributes[i]._names;
delete attributes[i]._names;
}
for (i = 0; i < objectclasses.length; i++) {
oc = objectclasses[i];
if (oc._names) {
oc.names = oc._names;
delete oc._names;
} else {
oc.names = [];
}
if (oc._sup) {
oc.sup = oc._sup;
delete oc._sup;
} else {
oc.sup = [];
}
if (oc._must) {
oc.must = oc._must;
delete oc._must;
} else {
oc.must = [];
}
if (oc._may) {
oc.may = oc._may;
delete oc._may;
} else {
oc.may = [];
}
}
var _attributes = {};
var _objectclasses = {};
attributes.forEach(function(a) {
for (var i = 0; i < a.names.length; i++) {
a.names[i] = a.names[i].toLowerCase();
_attributes[a.names[i]] = a;
}
});
objectclasses.forEach(function(oc) {
for (var i = 0; i < oc.names.length; i++) {
oc.names[i] = oc.names[i].toLowerCase();
_objectclasses[oc.names[i]] = oc;
}
});
return {
attributes: _attributes,
objectclasses: _objectclasses
};
}
function parseFile(file, callback) {
if (!file || typeof(file) !== 'string')
throw new TypeError('file (string) required');
if (!callback || typeof(callback) !== 'function')
throw new TypeError('callback (function) required');
fs.readFile(file, 'utf8', function(err, data) {
if (err)
return callback(new errors.OperationsError(err.message));
try {
return callback(null, parse(data));
} catch (e) {
return callback(new errors.OperationsError(e.message));
}
});
}
function _merge(child, parent) {
Object.keys(parent).forEach(function(k) {
if (Array.isArray(parent[k])) {
if (k === 'names' || k === 'sup')
return;
if (!child[k])
child[k] = [];
parent[k].forEach(function(v) {
if (child[k].indexOf(v) === -1)
child[k].push(v);
});
} else if (!child[k]) {
child[k] = parent[k];
}
});
return child;
}
function compile(attributes, objectclasses) {
assert.ok(attributes);
assert.ok(objectclasses);
var _attributes = {};
var _objectclasses = {};
Object.keys(attributes).forEach(function(k) {
_attributes[k] = attributes[k];
var sup;
if (attributes[k].sup && (sup = attributes[attributes[k].sup]))
_attributes[k] = _merge(_attributes[k], sup);
_attributes[k].names.sort();
});
Object.keys(objectclasses).forEach(function(k) {
_objectclasses[k] = objectclasses[k];
var sup;
if (objectclasses[k].sup && (sup = objectclasses[objectclasses[k].sup]))
_objectclasses[k] = _merge(_objectclasses[k], sup);
_objectclasses[k].names.sort();
_objectclasses[k].sup.sort();
_objectclasses[k].must.sort();
_objectclasses[k].may.sort();
});
return {
attributes: _attributes,
objectclasses: _objectclasses
};
}
/**
* Loads all the `.schema` files in a directory, and parses them.
*
* This method returns the set of schema from all files, and the "last one"
* wins, so don't do something stupid like have the same attribute defined
* N times with varying definitions.
*
* @param {String} directory the directory of *.schema files to load.
* @param {Function} callback of the form f(err, attributes, objectclasses).
* @throws {TypeEror} on bad input.
*/
function load(directory, callback) {
if (!directory || typeof(directory) !== 'string')
throw new TypeError('directory (string) required');
if (!callback || typeof(callback) !== 'function')
throw new TypeError('callback (function) required');
fs.readdir(directory, function(err, files) {
if (err)
return callback(new errors.OperationsError(err.message));
var finished = 0;
var attributes = {};
var objectclasses = {};
files.forEach(function(f) {
if (!/\.schema$/.test(f)) {
++finished;
return;
}
f = directory + '/' + f;
parseFile(f, function(err, schema) {
var cb = callback;
if (err) {
callback = null;
if (cb)
return cb(new errors.OperationsError(err.message));
return;
}
Object.keys(schema.attributes).forEach(function(a) {
attributes[a] = schema.attributes[a];
});
Object.keys(schema.objectclasses).forEach(function(oc) {
objectclasses[oc] = schema.objectclasses[oc];
});
if (++finished === files.length) {
if (cb) {
schema = compile(attributes, objectclasses);
return cb(null, schema);
}
}
});
});
});
}
///--- Exported API
module.exports = {
load: load,
parse: parse,
parseFile: parseFile
};

View File

@ -1,87 +0,0 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert');
var dn = require('../dn');
var errors = require('../errors');
var logStub = require('../log_stub');
var getTransformer = require('./transform').getTransformer;
function transformFilter(schema, filter) {
assert.ok(schema);
assert.ok(filter);
var attributes = schema.attributes;
switch (filter.type) {
case 'equal':
case 'approx':
case 'ge':
case 'le':
if (!attributes[filter.attribute.toLowerCase()])
throw new errors.NoSuchAttributeError(filter.attribute);
var transform = getTransformer(schema, filter.attribute);
if (transform)
filter.value = transform(filter.value) || filter.value;
break;
case 'substring':
case 'present':
if (!attributes[filter.attribute.toLowerCase()])
throw new errors.NoSuchAttributeError(filter.attribute);
break;
case 'and':
case 'or':
for (var i = 0; i < filter.filters.length; i++)
filter.filters[i] = transformFilter(schema, filter.filters[i]);
break;
case 'not':
filter.filter = trasnformFilter(schema, filter.filter);
}
return filter;
}
function createSearchHandler(options) {
if (!options || typeof(options) !== 'object')
throw new TypeError('options (object) required');
if (!options.schema || typeof(options.schema) !== 'object')
throw new TypeError('options.schema (object) required');
var log4js = options.log4js || logStub;
var log = log4js.getLogger('SchemaSearchHandler');
var schema = options.schema;
var CVErr = errors.ConstraintViolationError;
var NSAErr = errors.NoSuchAttributeError;
var OCVErr = errors.ObjectclassViolationError;
return function schemaSearchHandler(req, res, next) {
if (log.isDebugEnabled())
log.debug('%s running %j against schema', req.logId, req.filter);
try {
req.filter = transformFilter(schema, req.filter);
} catch (e) {
if (log.isDebugEnabled())
log.debug('%s error transforming filter: %s', req.logId, e.stack);
return next(e);
}
return next();
}
}
module.exports = createSearchHandler;

View File

@ -1,139 +0,0 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert');
var dn = require('../dn');
///--- API
function _getTransformer(syntax) {
assert.ok(syntax);
// TODO size enforcement
if (/\}$/.test(syntax))
syntax = syntax.replace(/\{.+\}$/, '');
switch (syntax) {
case '1.3.6.1.4.1.1466.115.121.1.27': // int
case '1.3.6.1.4.1.1466.115.121.1.36': // numeric string
return function(value) {
return parseInt(value, 10);
};
case '1.3.6.1.4.1.1466.115.121.1.7': // boolean
return function(value) {
return /^true$/i.test(value);
};
case '1.3.6.1.4.1.1466.115.121.1.5': // binary
return function(value) {
return new Buffer(value).toString('base64');
};
case '1.3.6.1.4.1.1466.115.121.1.12': // dn syntax
return function(value) {
return dn.parse(value).toString();
};
default:
// noop
}
return null;
}
function getTransformer(schema, type) {
assert.ok(schema);
assert.ok(type);
if (!schema.attributes[type] || !schema.attributes[type].syntax)
return null;
return _getTransformer(schema.attributes[type].syntax);
}
function transformValue(schema, type, value) {
assert.ok(schema);
assert.ok(type);
assert.ok(value);
if (!schema.attributes[type] || !schema.attributes[type].syntax)
return value;
var transformer = _getTransformer(schema.attributes[type].syntax);
return transformer ? transformer(value) : null;
}
function transformObject(schema, attributes, keys) {
assert.ok(schema);
assert.ok(attributes);
if (!keys)
keys = Object.keys(attributes);
var xformed = false;
keys.forEach(function(k) {
k = k.toLowerCase();
var transform = _getTransformer(schema.attributes[k].syntax);
if (transform) {
xformed = true;
var vals = attributes[k];
console.log('%s -> %j', k, vals);
for (var i = 0; i < vals.length; i++)
vals[i] = transform(vals[i]);
}
});
return xformed;
}
module.exports = {
transformObject: transformObject,
transformValue: transformValue,
getTransformer: getTransformer
};
// var syntax = schema.attributes[k].syntax;
// if (/\}$/.test(syntax))
// syntax = syntax.replace(/\{.+\}$/, '');
// switch (syntax) {
// case '1.3.6.1.4.1.1466.115.121.1.27': // int
// case '1.3.6.1.4.1.1466.115.121.1.36': // numeric string
// for (j = 0; j < attr.length; j++)
// attr[j] = parseInt(attr[j], 10);
// xformed = true;
// break;
// case '1.3.6.1.4.1.1466.115.121.1.7': // boolean
// for (j = 0; j < attr.length; j++)
// attr[j] = /^true$/i.test(attr[j]);
// xformed = true;
// break;
// case '1.3.6.1.4.1.1466.115.121.1.5': // binary
// for (j = 0; j < attr.length; j++)
// attr[j] = new Buffer(attr[j]).toString('base64');
// xformed = true;
// break;
// case '1.3.6.1.4.1.1466.115.121.1.12': // dn syntax
// for (j = 0; j < attr.length; j++)
// attr[j] = dn.parse(attr[j]).toString();
// xformed = true;
// break;
// default:
// // noop
// }

View File

@ -7,7 +7,6 @@ var tls = require('tls');
var util = require('util'); var util = require('util');
var asn1 = require('asn1'); var asn1 = require('asn1');
var sprintf = require('sprintf').sprintf;
var dn = require('./dn'); var dn = require('./dn');
var dtrace = require('./dtrace'); var dtrace = require('./dtrace');
@ -37,6 +36,8 @@ var Ber = asn1.Ber;
var BerReader = asn1.BerReader; var BerReader = asn1.BerReader;
var DN = dn.DN; var DN = dn.DN;
var sprintf = util.format;
///--- Helpers ///--- Helpers
@ -55,14 +56,14 @@ function mergeFunctionArgs(argv, start, end) {
var arr = argv[i]; var arr = argv[i];
for (var j = 0; j < arr.length; j++) { for (var j = 0; j < arr.length; j++) {
if (!(arr[j] instanceof Function)) { if (!(arr[j] instanceof Function)) {
throw new TypeError('Invalid argument type: ' + typeof(arr[j])); throw new TypeError('Invalid argument type: ' + typeof (arr[j]));
} }
handlers.push(arr[j]); handlers.push(arr[j]);
} }
} else if (argv[i] instanceof Function) { } else if (argv[i] instanceof Function) {
handlers.push(argv[i]); handlers.push(argv[i]);
} else { } else {
throw new TypeError('Invalid argument type: ' + typeof(argv[i])); throw new TypeError('Invalid argument type: ' + typeof (argv[i]));
} }
} }
@ -220,10 +221,12 @@ function fireDTraceProbe(req, res) {
case Protocol.LDAP_REQ_UNBIND: case Protocol.LDAP_REQ_UNBIND:
op = 'unbind'; op = 'unbind';
break; break;
default:
break;
} }
res._dtraceOp = op; res._dtraceOp = op;
dtrace.fire('server-' + op + '-start', function() { dtrace.fire('server-' + op + '-start', function () {
return probeArgs; return probeArgs;
}); });
} }
@ -249,15 +252,15 @@ function fireDTraceProbe(req, res) {
*/ */
function Server(options) { function Server(options) {
if (options) { if (options) {
if (typeof(options) !== 'object') if (typeof (options) !== 'object')
throw new TypeError('options (object) required'); throw new TypeError('options (object) required');
if (options.log4js && typeof(options.log4js) !== 'object') if (options.log4js && typeof (options.log4js) !== 'object')
throw new TypeError('options.log4s must be an object'); throw new TypeError('options.log4s must be an object');
if (options.certificate || options.key) { if (options.certificate || options.key) {
if (!(options.certificate && options.key) || if (!(options.certificate && options.key) ||
typeof(options.certificate) !== 'string' || typeof (options.certificate) !== 'string' ||
typeof(options.key) !== 'string') { typeof (options.key) !== 'string') {
throw new TypeError('options.certificate and options.key (string) ' + throw new TypeError('options.certificate and options.key (string) ' +
'are both required for TLS'); 'are both required for TLS');
} }
@ -296,26 +299,26 @@ function Server(options) {
config: options, config: options,
_bindDN: new DN([rdn]) _bindDN: new DN([rdn])
}; };
c.addListener('timeout', function() { c.addListener('timeout', function () {
log.trace('%s timed out', c.ldap.id); log.trace('%s timed out', c.ldap.id);
c.destroy(); c.destroy();
}); });
c.addListener('end', function() { c.addListener('end', function () {
log.trace('%s shutdown', c.ldap.id); log.trace('%s shutdown', c.ldap.id);
}); });
c.addListener('error', function(err) { c.addListener('error', function (err) {
log.warn('%s unexpected connection error', c.ldap.id, err); log.warn('%s unexpected connection error', c.ldap.id, err);
c.destroy(); c.destroy();
}); });
c.addListener('close', function(had_err) { c.addListener('close', function (had_err) {
log.trace('%s close; had_err=%j', c.ldap.id, had_err); log.trace('%s close; had_err=%j', c.ldap.id, had_err);
c.end(); c.end();
}); });
c.ldap.__defineGetter__('bindDN', function() { c.ldap.__defineGetter__('bindDN', function () {
return c.ldap._bindDN; return c.ldap._bindDN;
}); });
c.ldap.__defineSetter__('bindDN', function(val) { c.ldap.__defineSetter__('bindDN', function (val) {
if (!(val instanceof DN)) if (!(val instanceof DN))
throw new TypeError('DN required'); throw new TypeError('DN required');
@ -330,14 +333,14 @@ function Server(options) {
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace('new connection from %s', c.ldap.id); log.trace('new connection from %s', c.ldap.id);
dtrace.fire('server-connection', function() { dtrace.fire('server-connection', function () {
return [c.remoteAddress]; return [c.remoteAddress];
}); });
c.parser = new Parser({ c.parser = new Parser({
log4js: options.log4js log4js: options.log4js
}); });
c.parser.on('message', function(req) { c.parser.on('message', function (req) {
req.connection = c; req.connection = c;
req.logId = c.ldap.id + '::' + req.messageID; req.logId = c.ldap.id + '::' + req.messageID;
req.startTime = new Date().getTime(); req.startTime = new Date().getTime();
@ -359,7 +362,7 @@ function Server(options) {
var chain = self._getHandlerChain(req, res); var chain = self._getHandlerChain(req, res);
var i = 0; var i = 0;
return function(err) { return function (err) {
function sendError(err) { function sendError(err) {
res.status = err.code || errors.LDAP_OPERATIONS_ERROR; res.status = err.code || errors.LDAP_OPERATIONS_ERROR;
res.matchedDN = req.suffix ? req.suffix.toString() : ''; res.matchedDN = req.suffix ? req.suffix.toString() : '';
@ -373,7 +376,7 @@ 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 (c) {
c.call(self, req, res, next); c.call(self, req, res, next);
}); });
} }
@ -403,7 +406,7 @@ function Server(options) {
}(); }();
}); });
c.parser.on('error', function(err, message) { c.parser.on('error', function (err, message) {
log.error('Exception happened parsing for %s: %s', log.error('Exception happened parsing for %s: %s',
c.ldap.id, err.stack); c.ldap.id, err.stack);
@ -420,7 +423,7 @@ function Server(options) {
return c.end(res.toBer()); return c.end(res.toBer());
}); });
c.on('data', function(data) { c.on('data', function (data) {
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace('data on %s: %s', c.ldap.id, util.inspect(data)); log.trace('data on %s: %s', c.ldap.id, util.inspect(data));
@ -436,7 +439,7 @@ function Server(options) {
} }
}); });
}; // end newConnection } // end newConnection
this.routes = {}; this.routes = {};
if ((options.cert || options.certificate) && options.key) { if ((options.cert || options.certificate) && options.key) {
@ -449,26 +452,26 @@ function Server(options) {
this.server.ldap = { this.server.ldap = {
config: options config: options
}; };
this.server.on('close', function() { this.server.on('close', function () {
self.emit('close'); self.emit('close');
}); });
this.server.on('error', function(err) { this.server.on('error', function (err) {
self.emit('error', err); self.emit('error', err);
}); });
this.__defineGetter__('maxConnections', function() { this.__defineGetter__('maxConnections', function () {
return self.server.maxConnections; return self.server.maxConnections;
}); });
this.__defineSetter__('maxConnections', function(val) { this.__defineSetter__('maxConnections', function (val) {
self.server.maxConnections = val; self.server.maxConnections = val;
}); });
this.__defineGetter__('connections', function() { this.__defineGetter__('connections', function () {
return self.server.connections; return self.server.connections;
}); });
this.__defineGetter__('name', function() { this.__defineGetter__('name', function () {
return 'LDAPServer'; return 'LDAPServer';
}); });
this.__defineGetter__('url', function() { this.__defineGetter__('url', function () {
var str; var str;
if (this.server instanceof tls.Server) { if (this.server instanceof tls.Server) {
str = 'ldaps://'; str = 'ldaps://';
@ -495,7 +498,7 @@ module.exports = Server;
* @return {Server} this so you can chain calls. * @return {Server} this so you can chain calls.
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.add = function(name) { Server.prototype.add = function (name) {
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
return this._mount(Protocol.LDAP_REQ_ADD, name, args); return this._mount(Protocol.LDAP_REQ_ADD, name, args);
}; };
@ -511,7 +514,7 @@ Server.prototype.add = function(name) {
* @return {Server} this so you can chain calls. * @return {Server} this so you can chain calls.
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.bind = function(name) { Server.prototype.bind = function (name) {
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
return this._mount(Protocol.LDAP_REQ_BIND, name, args); return this._mount(Protocol.LDAP_REQ_BIND, name, args);
}; };
@ -527,7 +530,7 @@ Server.prototype.bind = function(name) {
* @return {Server} this so you can chain calls. * @return {Server} this so you can chain calls.
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.compare = function(name) { Server.prototype.compare = function (name) {
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
return this._mount(Protocol.LDAP_REQ_COMPARE, name, args); return this._mount(Protocol.LDAP_REQ_COMPARE, name, args);
}; };
@ -543,7 +546,7 @@ Server.prototype.compare = function(name) {
* @return {Server} this so you can chain calls. * @return {Server} this so you can chain calls.
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.del = function(name) { Server.prototype.del = function (name) {
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
return this._mount(Protocol.LDAP_REQ_DELETE, name, args); return this._mount(Protocol.LDAP_REQ_DELETE, name, args);
}; };
@ -559,7 +562,7 @@ Server.prototype.del = function(name) {
* @return {Server} this so you can chain calls. * @return {Server} this so you can chain calls.
* @throws {TypeError} on bad input. * @throws {TypeError} on bad input.
*/ */
Server.prototype.exop = function(name) { Server.prototype.exop = function (name) {
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
return this._mount(Protocol.LDAP_REQ_EXTENSION, name, args, true); return this._mount(Protocol.LDAP_REQ_EXTENSION, name, args, true);
}; };
@ -575,7 +578,7 @@ Server.prototype.exop = function(name) {
* @return {Server} this so you can chain calls. * @return {Server} this so you can chain calls.
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.modify = function(name) { Server.prototype.modify = function (name) {
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
return this._mount(Protocol.LDAP_REQ_MODIFY, name, args); return this._mount(Protocol.LDAP_REQ_MODIFY, name, args);
}; };
@ -591,7 +594,7 @@ Server.prototype.modify = function(name) {
* @return {Server} this so you can chain calls. * @return {Server} this so you can chain calls.
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.modifyDN = function(name) { Server.prototype.modifyDN = function (name) {
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
return this._mount(Protocol.LDAP_REQ_MODRDN, name, args); return this._mount(Protocol.LDAP_REQ_MODRDN, name, args);
}; };
@ -607,7 +610,7 @@ Server.prototype.modifyDN = function(name) {
* @return {Server} this so you can chain calls. * @return {Server} this so you can chain calls.
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.search = function(name) { Server.prototype.search = function (name) {
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
return this._mount(Protocol.LDAP_REQ_SEARCH, name, args); return this._mount(Protocol.LDAP_REQ_SEARCH, name, args);
}; };
@ -622,7 +625,7 @@ Server.prototype.search = function(name) {
* @return {Server} this so you can chain calls. * @return {Server} this so you can chain calls.
* @throws {TypeError} on bad input * @throws {TypeError} on bad input
*/ */
Server.prototype.unbind = function() { Server.prototype.unbind = function () {
var args = Array.prototype.slice.call(arguments, 0); var args = Array.prototype.slice.call(arguments, 0);
return this._mount(Protocol.LDAP_REQ_UNBIND, 'unbind', args, true); return this._mount(Protocol.LDAP_REQ_UNBIND, 'unbind', args, true);
}; };
@ -632,36 +635,36 @@ Server.prototype.use = function use() {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
var chain = mergeFunctionArgs(args, 0, args.length); var chain = mergeFunctionArgs(args, 0, args.length);
var self = this; var self = this;
chain.forEach(function(c) { chain.forEach(function (c) {
self._chain.push(c); self._chain.push(c);
}); });
}; };
Server.prototype.after = function() { Server.prototype.after = function () {
if (!this._postChain) if (!this._postChain)
this._postChain = []; this._postChain = [];
var self = this; var self = this;
mergeFunctionArgs(arguments).forEach(function(h) { mergeFunctionArgs(arguments).forEach(function (h) {
self._postChain.push(h); self._postChain.push(h);
}); });
}; };
// All these just reexpose the requisite net.Server APIs // All these just reexpose the requisite net.Server APIs
Server.prototype.listen = function(port, host, callback) { Server.prototype.listen = function (port, host, callback) {
if (!port) if (!port)
throw new TypeError('port (number) required'); throw new TypeError('port (number) required');
if (typeof(host) === 'function') { if (typeof (host) === 'function') {
callback = host; callback = host;
host = '0.0.0.0'; host = '0.0.0.0';
} }
var self = this; var self = this;
function _callback() { function _callback() {
if (typeof(port) === 'number') { if (typeof (port) === 'number') {
self.host = host; self.host = host;
self.port = port; self.port = port;
} else { } else {
@ -669,30 +672,30 @@ Server.prototype.listen = function(port, host, callback) {
self.port = self.server.fd; self.port = self.server.fd;
} }
if (typeof(callback) === 'function') if (typeof (callback) === 'function')
callback(); callback();
} }
if (typeof(port) === 'number') { if (typeof (port) === 'number') {
return this.server.listen(port, host, _callback); return this.server.listen(port, host, _callback);
} else { } else {
return this.server.listen(port, _callback); return this.server.listen(port, _callback);
} }
}; };
Server.prototype.listenFD = function(fd) { Server.prototype.listenFD = function (fd) {
this.host = 'unix-domain-socket'; this.host = 'unix-domain-socket';
this.port = fd; this.port = fd;
return this.server.listenFD(fd); return this.server.listenFD(fd);
}; };
Server.prototype.close = function() { Server.prototype.close = function () {
return this.server.close(); return this.server.close();
}; };
Server.prototype.address = function() { Server.prototype.address = function () {
return this.server.address(); return this.server.address();
}; };
Server.prototype._getRoute = function(_dn, backend) { Server.prototype._getRoute = function (_dn, backend) {
assert.ok(dn); assert.ok(dn);
if (!backend) if (!backend)
@ -715,7 +718,7 @@ Server.prototype._getRoute = function(_dn, backend) {
}; };
Server.prototype._getHandlerChain = function(req, res) { Server.prototype._getHandlerChain = function _getHandlerChain(req, res) {
assert.ok(req); assert.ok(req);
fireDTraceProbe(req, res); fireDTraceProbe(req, res);
@ -741,49 +744,42 @@ Server.prototype._getHandlerChain = function(req, res) {
// Special cases are abandons, exops and unbinds, handle those first. // Special cases are abandons, exops and unbinds, handle those first.
if (req.protocolOp === Protocol.LDAP_REQ_EXTENSION) { if (req.protocolOp === Protocol.LDAP_REQ_EXTENSION) {
if (r !== req.requestName) if (r === req.requestName) {
continue; return {
backend: routes.backend,
return { handlers: route[op] || [noExOpHandler]
backend: routes.backend, };
handlers: route[op] || [noExOpHandler]
};
} else if (req.protocolOp === Protocol.LDAP_REQ_UNBIND) {
function getUnbindChain() {
if (routes['unbind'] && routes['unbind'][op])
return routes['unbind'][op];
self.log.debug('%s unbind request %j', req.logId, req.json);
return [defaultNoOpHandler];
} }
} else if (req.protocolOp === Protocol.LDAP_REQ_UNBIND) {
return { return {
backend: routes['unbind'] ? routes['unbind'].backend : self, backend: routes['unbind'] ? routes['unbind'].backend : self,
handlers: getUnbindChain() handlers: function getUnbindChain() {
if (routes['unbind'] && routes['unbind'][op])
return routes['unbind'][op];
self.log.debug('%s unbind request %j', req.logId, req.json);
return [defaultNoOpHandler];
}
}; };
} else if (req.protocolOp === Protocol.LDAP_REQ_ABANDON) { } else if (req.protocolOp === Protocol.LDAP_REQ_ABANDON) {
return { return {
backend: self, backend: self,
handlers: [defaultNoOpHandler] handlers: [defaultNoOpHandler]
}; };
} else if (route[op]) {
// Otherwise, match via DN rules
assert.ok(req.dn);
assert.ok(route.dn);
if (route.dn.equals(req.dn) || route.dn.parentOf(req.dn)) {
// We should be good to go.
req.suffix = route.dn;
return {
backend: route.backend,
handlers: route[op] || [defaultHandler]
};
}
} }
if (!route[op])
continue;
// Otherwise, match via DN rules
assert.ok(req.dn);
assert.ok(route.dn);
if (!route.dn.equals(req.dn) && !route.dn.parentOf(req.dn))
continue;
// We should be good to go.
req.suffix = route.dn;
return {
backend: route.backend,
handlers: route[op] || [defaultHandler]
};
} }
// We're here, so nothing matched. // We're here, so nothing matched.
@ -795,12 +791,12 @@ Server.prototype._getHandlerChain = function(req, res) {
}; };
Server.prototype._mount = function(op, name, argv, notDN) { Server.prototype._mount = function (op, name, argv, notDN) {
assert.ok(op); assert.ok(op);
assert.ok(name !== undefined); assert.ok(name !== undefined);
assert.ok(argv); assert.ok(argv);
if (typeof(name) !== 'string') if (typeof (name) !== 'string')
throw new TypeError('name (string) required'); throw new TypeError('name (string) required');
if (!argv.length) if (!argv.length)
throw new Error('at least one handler required'); throw new Error('at least one handler required');
@ -808,14 +804,14 @@ Server.prototype._mount = function(op, name, argv, notDN) {
var backend = this; var backend = this;
var index = 0; var index = 0;
if (typeof(argv[0]) === 'object' && !Array.isArray(argv[0])) { if (typeof (argv[0]) === 'object' && !Array.isArray(argv[0])) {
backend = argv[0]; backend = argv[0];
index = 1; index = 1;
} }
var route = this._getRoute(notDN ? name : dn.parse(name), backend); var route = this._getRoute(notDN ? name : dn.parse(name), backend);
var chain = this._chain.slice(); var chain = this._chain.slice();
argv.slice(index).forEach(function(a) { argv.slice(index).forEach(function (a) {
chain.push(a); chain.push(a);
}); });
route['0x' + op.toString(16)] = mergeFunctionArgs(chain); route['0x' + op.toString(16)] = mergeFunctionArgs(chain);

View File

@ -10,7 +10,7 @@ var dn = require('./dn');
module.exports = { module.exports = {
parse: function(urlStr, parseDN) { parse: function (urlStr, parseDN) {
var u = url.parse(urlStr); var u = url.parse(urlStr);
if (!u.protocol || !(u.protocol === 'ldap:' || u.protocol === 'ldaps:')) if (!u.protocol || !(u.protocol === 'ldap:' || u.protocol === 'ldaps:'))
throw new TypeError(urlStr + ' is an invalid LDAP url (protocol)'); throw new TypeError(urlStr + ' is an invalid LDAP url (protocol)');
@ -36,7 +36,7 @@ module.exports = {
var tmp = u.search.substr(1).split('?'); var tmp = u.search.substr(1).split('?');
if (tmp && tmp.length) { if (tmp && tmp.length) {
if (tmp[0]) { if (tmp[0]) {
tmp[0].split(',').forEach(function(a) { tmp[0].split(',').forEach(function (a) {
u.attributes.push(querystring.unescape(a.trim())); u.attributes.push(querystring.unescape(a.trim()));
}); });
} }

View File

@ -9,7 +9,7 @@
"name": "ldapjs", "name": "ldapjs",
"homepage": "http://ldapjs.org", "homepage": "http://ldapjs.org",
"description": "LDAP client and server APIs", "description": "LDAP client and server APIs",
"version": "0.4.8", "version": "0.5.0",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/mcavage/node-ldapjs.git" "url": "git://github.com/mcavage/node-ldapjs.git"
@ -20,17 +20,17 @@
"lib": "./lib" "lib": "./lib"
}, },
"engines": { "engines": {
"node": ">=0.4" "node": ">=0.6"
}, },
"dependencies": { "dependencies": {
"asn1": "0.1.11", "asn1": "0.1.11",
"buffertools": "1.0.6", "buffertools": "1.0.7",
"dtrace-provider": "0.0.3", "bunyan": "0.6.3",
"nopt": "1.0.10", "dtrace-provider": "0.0.6",
"sprintf": "0.1.1" "nopt": "1.0.10"
}, },
"devDependencies": { "devDependencies": {
"tap": "0.1.4", "tap": "0.2",
"node-uuid": "1.3.3" "node-uuid": "1.3.3"
}, },
"scripts": { "scripts": {

View File

@ -14,20 +14,20 @@ var Attribute;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
Attribute = require('../lib/index').Attribute; Attribute = require('../lib/index').Attribute;
t.ok(Attribute); t.ok(Attribute);
t.end(); t.end();
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new Attribute()); t.ok(new Attribute());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var attr = new Attribute({ var attr = new Attribute({
type: 'cn', type: 'cn',
vals: ['foo', 'bar'] vals: ['foo', 'bar']
@ -43,7 +43,7 @@ test('new with args', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var attr = new Attribute({ var attr = new Attribute({
type: 'cn', type: 'cn',
vals: ['foo', 'bar'] vals: ['foo', 'bar']
@ -61,7 +61,7 @@ test('toBer', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.startSequence(); ber.startSequence();
ber.writeString('cn'); ber.writeString('cn');

View File

@ -15,7 +15,7 @@ var Change;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
Attribute = require('../lib/index').Attribute; Attribute = require('../lib/index').Attribute;
Change = require('../lib/index').Change; Change = require('../lib/index').Change;
t.ok(Attribute); t.ok(Attribute);
@ -24,13 +24,13 @@ test('load library', function(t) {
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new Change()); t.ok(new Change());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var change = new Change({ var change = new Change({
operation: 0x00, operation: 0x00,
modification: new Attribute({ modification: new Attribute({
@ -50,16 +50,15 @@ test('new with args', function(t) {
}); });
test('GH-31 (multiple attributes per Change)', function(t) { test('GH-31 (multiple attributes per Change)', function (t) {
try { try {
new Change({ t.notOk(new Change({
operation: 'replace', operation: 'replace',
modification: { modification: {
cn: 'foo', cn: 'foo',
sn: 'bar' sn: 'bar'
} }
}); }), 'should have thrown');
t.fail('should have thrown');
} catch (e) { } catch (e) {
t.ok(e); t.ok(e);
t.end(); t.end();
@ -67,7 +66,7 @@ test('GH-31 (multiple attributes per Change)', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var change = new Change({ var change = new Change({
operation: 'Add', operation: 'Add',
modification: new Attribute({ modification: new Attribute({
@ -91,7 +90,7 @@ test('toBer', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.startSequence(); ber.startSequence();
ber.writeEnumeration(0x00); ber.writeEnumeration(0x00);

View File

@ -21,7 +21,7 @@ var server;
///--- Tests ///--- Tests
test('setup', function(t) { test('setup', function (t) {
ldap = require('../lib/index'); ldap = require('../lib/index');
t.ok(ldap); t.ok(ldap);
t.ok(ldap.createClient); t.ok(ldap.createClient);
@ -35,7 +35,7 @@ test('setup', function(t) {
server = ldap.createServer(); server = ldap.createServer();
t.ok(server); t.ok(server);
server.bind(BIND_DN, function(req, res, next) { server.bind(BIND_DN, function (req, res, next) {
if (req.credentials !== BIND_PW) if (req.credentials !== BIND_PW)
return next(new ldap.InvalidCredentialsError('Invalid password')); return next(new ldap.InvalidCredentialsError('Invalid password'));
@ -43,43 +43,43 @@ test('setup', function(t) {
return next(); return next();
}); });
server.add(SUFFIX, function(req, res, next) { server.add(SUFFIX, function (req, res, next) {
res.end(); res.end();
return next(); return next();
}); });
server.compare(SUFFIX, function(req, res, next) { server.compare(SUFFIX, function (req, res, next) {
res.end(req.value === 'test'); res.end(req.value === 'test');
return next(); return next();
}); });
server.del(SUFFIX, function(req, res, next) { server.del(SUFFIX, function (req, res, next) {
res.end(); res.end();
return next(); return next();
}); });
// LDAP whoami // LDAP whoami
server.exop('1.3.6.1.4.1.4203.1.11.3', function(req, res, next) { server.exop('1.3.6.1.4.1.4203.1.11.3', function (req, res, next) {
res.value = 'u:xxyyz@EXAMPLE.NET'; res.value = 'u:xxyyz@EXAMPLE.NET';
res.end(); res.end();
return next(); return next();
}); });
server.modify(SUFFIX, function(req, res, next) { server.modify(SUFFIX, function (req, res, next) {
res.end(); res.end();
return next(); return next();
}); });
server.modifyDN(SUFFIX, function(req, res, next) { server.modifyDN(SUFFIX, function (req, res, next) {
res.end(); res.end();
return next(); return next();
}); });
server.search('dc=timeout', function(req, res, next) { server.search('dc=timeout', function (req, res, next) {
// Haha client! // Haha client!
}); });
server.search(SUFFIX, function(req, res, next) { server.search(SUFFIX, function (req, res, next) {
if (req.dn.equals('cn=ref,' + SUFFIX)) { if (req.dn.equals('cn=ref,' + SUFFIX)) {
res.send(res.createSearchReference('ldap://localhost')); res.send(res.createSearchReference('ldap://localhost'));
@ -109,7 +109,7 @@ test('setup', function(t) {
return next(); return next();
}); });
server.search('dc=empty', function(req, res, next) { server.search('dc=empty', function (req, res, next) {
res.send({ res.send({
dn: 'dc=empty', dn: 'dc=empty',
attributes: { attributes: {
@ -121,12 +121,12 @@ test('setup', function(t) {
return next(); return next();
}); });
server.unbind(function(req, res, next) { server.unbind(function (req, res, next) {
res.end(); res.end();
return next(); return next();
}); });
server.listen(SOCKET, function() { server.listen(SOCKET, function () {
client = ldap.createClient({ client = ldap.createClient({
socketPath: SOCKET, socketPath: SOCKET,
reconnect: false // turn this off for unit testing reconnect: false // turn this off for unit testing
@ -140,8 +140,8 @@ test('setup', function(t) {
}); });
test('simple bind success', function(t) { test('simple bind success', function (t) {
client.bind(BIND_DN, BIND_PW, function(err, res) { client.bind(BIND_DN, BIND_PW, function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -150,8 +150,8 @@ test('simple bind success', function(t) {
}); });
test('simple bind failure', function(t) { test('simple bind failure', function (t) {
client.bind(BIND_DN, uuid(), function(err, res) { client.bind(BIND_DN, uuid(), function (err, res) {
t.ok(err); t.ok(err);
t.notOk(res); t.notOk(res);
@ -166,14 +166,14 @@ test('simple bind failure', function(t) {
}); });
test('add success', function(t) { test('add success', function (t) {
var attrs = [ var attrs = [
new Attribute({ new Attribute({
type: 'cn', type: 'cn',
vals: ['test'] vals: ['test']
}) })
]; ];
client.add('cn=add, ' + SUFFIX, attrs, function(err, res) { client.add('cn=add, ' + SUFFIX, attrs, function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -182,12 +182,12 @@ test('add success', function(t) {
}); });
test('add success with object', function(t) { test('add success with object', function (t) {
var entry = { var entry = {
cn: ['unit', 'add'], cn: ['unit', 'add'],
sn: 'test' sn: 'test'
}; };
client.add('cn=add, ' + SUFFIX, entry, function(err, res) { client.add('cn=add, ' + SUFFIX, entry, function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -196,8 +196,8 @@ test('add success with object', function(t) {
}); });
test('compare success', function(t) { test('compare success', function (t) {
client.compare('cn=compare, ' + SUFFIX, 'cn', 'test', function(err, client.compare('cn=compare, ' + SUFFIX, 'cn', 'test', function (err,
matched, matched,
res) { res) {
t.ifError(err); t.ifError(err);
@ -208,8 +208,8 @@ test('compare success', function(t) {
}); });
test('compare false', function(t) { test('compare false', function (t) {
client.compare('cn=compare, ' + SUFFIX, 'cn', 'foo', function(err, client.compare('cn=compare, ' + SUFFIX, 'cn', 'foo', function (err,
matched, matched,
res) { res) {
t.ifError(err); t.ifError(err);
@ -220,8 +220,8 @@ test('compare false', function(t) {
}); });
test('compare bad suffix', function(t) { test('compare bad suffix', function (t) {
client.compare('cn=' + uuid(), 'cn', 'foo', function(err, client.compare('cn=' + uuid(), 'cn', 'foo', function (err,
matched, matched,
res) { res) {
t.ok(err); t.ok(err);
@ -233,8 +233,8 @@ test('compare bad suffix', function(t) {
}); });
test('delete success', function(t) { test('delete success', function (t) {
client.del('cn=delete, ' + SUFFIX, function(err, res) { client.del('cn=delete, ' + SUFFIX, function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
t.end(); t.end();
@ -242,8 +242,8 @@ test('delete success', function(t) {
}); });
test('exop success', function(t) { test('exop success', function (t) {
client.exop('1.3.6.1.4.1.4203.1.11.3', function(err, value, res) { client.exop('1.3.6.1.4.1.4203.1.11.3', function (err, value, res) {
t.ifError(err); t.ifError(err);
t.ok(value); t.ok(value);
t.ok(res); t.ok(res);
@ -253,8 +253,8 @@ test('exop success', function(t) {
}); });
test('exop invalid', function(t) { test('exop invalid', function (t) {
client.exop('1.2.3.4', function(err, res) { client.exop('1.2.3.4', function (err, res) {
t.ok(err); t.ok(err);
t.ok(err instanceof ldap.ProtocolError); t.ok(err instanceof ldap.ProtocolError);
t.notOk(res); t.notOk(res);
@ -263,15 +263,15 @@ test('exop invalid', function(t) {
}); });
test('bogus exop (GH-17)', function(t) { test('bogus exop (GH-17)', function (t) {
client.exop('cn=root', function(err, value) { client.exop('cn=root', function (err, value) {
t.ok(err); t.ok(err);
t.end(); t.end();
}); });
}); });
test('modify success', function(t) { test('modify success', function (t) {
var change = new Change({ var change = new Change({
type: 'Replace', type: 'Replace',
modification: new Attribute({ modification: new Attribute({
@ -279,7 +279,7 @@ test('modify success', function(t) {
vals: ['test'] vals: ['test']
}) })
}); });
client.modify('cn=modify, ' + SUFFIX, change, function(err, res) { client.modify('cn=modify, ' + SUFFIX, change, function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -288,14 +288,14 @@ test('modify success', function(t) {
}); });
test('modify change plain object success', function(t) { test('modify change plain object success', function (t) {
var change = new Change({ var change = new Change({
type: 'Replace', type: 'Replace',
modification: { modification: {
cn: 'test' cn: 'test'
} }
}); });
client.modify('cn=modify, ' + SUFFIX, change, function(err, res) { client.modify('cn=modify, ' + SUFFIX, change, function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -304,7 +304,7 @@ test('modify change plain object success', function(t) {
}); });
test('modify array success', function(t) { test('modify array success', function (t) {
var changes = [ var changes = [
new Change({ new Change({
operation: 'Replace', operation: 'Replace',
@ -320,7 +320,7 @@ test('modify array success', function(t) {
}) })
}) })
]; ];
client.modify('cn=modify, ' + SUFFIX, changes, function(err, res) { client.modify('cn=modify, ' + SUFFIX, changes, function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -329,7 +329,7 @@ test('modify array success', function(t) {
}); });
test('modify change plain object success (GH-31)', function(t) { test('modify change plain object success (GH-31)', function (t) {
var change = { var change = {
type: 'replace', type: 'replace',
modification: { modification: {
@ -337,7 +337,7 @@ test('modify change plain object success (GH-31)', function(t) {
sn: 'bar' sn: 'bar'
} }
}; };
client.modify('cn=modify, ' + SUFFIX, change, function(err, res) { client.modify('cn=modify, ' + SUFFIX, change, function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -346,8 +346,8 @@ test('modify change plain object success (GH-31)', function(t) {
}); });
test('modify DN new RDN only', function(t) { test('modify DN new RDN only', function (t) {
client.modifyDN('cn=old, ' + SUFFIX, 'cn=new', function(err, res) { client.modifyDN('cn=old, ' + SUFFIX, 'cn=new', function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -356,8 +356,8 @@ test('modify DN new RDN only', function(t) {
}); });
test('modify DN new superior', function(t) { test('modify DN new superior', function (t) {
client.modifyDN('cn=old, ' + SUFFIX, 'cn=new, dc=foo', function(err, res) { client.modifyDN('cn=old, ' + SUFFIX, 'cn=new, dc=foo', function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -366,12 +366,12 @@ test('modify DN new superior', function(t) {
}); });
test('search basic', function(t) { test('search basic', function (t) {
client.search('cn=test, ' + SUFFIX, '(objectclass=*)', function(err, res) { client.search('cn=test, ' + SUFFIX, '(objectclass=*)', function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
var gotEntry = 0; var gotEntry = 0;
res.on('searchEntry', function(entry) { res.on('searchEntry', function (entry) {
t.ok(entry); t.ok(entry);
t.ok(entry instanceof ldap.SearchEntry); t.ok(entry instanceof ldap.SearchEntry);
t.equal(entry.dn.toString(), 'cn=test, ' + SUFFIX); t.equal(entry.dn.toString(), 'cn=test, ' + SUFFIX);
@ -382,10 +382,10 @@ test('search basic', function(t) {
t.ok(entry.object); t.ok(entry.object);
gotEntry++; gotEntry++;
}); });
res.on('error', function(err) { res.on('error', function (err) {
t.fail(err); t.fail(err);
}); });
res.on('end', function(res) { res.on('end', function (res) {
t.ok(res); t.ok(res);
t.ok(res instanceof ldap.SearchResponse); t.ok(res instanceof ldap.SearchResponse);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -396,26 +396,26 @@ test('search basic', function(t) {
}); });
test('search referral', function(t) { test('search referral', function (t) {
client.search('cn=ref, ' + SUFFIX, '(objectclass=*)', function(err, res) { client.search('cn=ref, ' + SUFFIX, '(objectclass=*)', function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
var gotEntry = 0; var gotEntry = 0;
var gotReferral = false; var gotReferral = false;
res.on('searchEntry', function(entry) { res.on('searchEntry', function (entry) {
gotEntry++; gotEntry++;
}); });
res.on('searchReference', function(referral) { res.on('searchReference', function (referral) {
gotReferral = true; gotReferral = true;
t.ok(referral); t.ok(referral);
t.ok(referral instanceof ldap.SearchReference); t.ok(referral instanceof ldap.SearchReference);
t.ok(referral.uris); t.ok(referral.uris);
t.ok(referral.uris.length); t.ok(referral.uris.length);
}); });
res.on('error', function(err) { res.on('error', function (err) {
t.fail(err); t.fail(err);
}); });
res.on('end', function(res) { res.on('end', function (res) {
t.ok(res); t.ok(res);
t.ok(res instanceof ldap.SearchResponse); t.ok(res instanceof ldap.SearchResponse);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -427,12 +427,12 @@ test('search referral', function(t) {
}); });
test('search empty attribute', function(t) { test('search empty attribute', function (t) {
client.search('dc=empty', '(objectclass=*)', function(err, res) { client.search('dc=empty', '(objectclass=*)', function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
var gotEntry = 0; var gotEntry = 0;
res.on('searchEntry', function(entry) { res.on('searchEntry', function (entry) {
var obj = entry.toObject(); var obj = entry.toObject();
t.equal('dc=empty', obj.dn); t.equal('dc=empty', obj.dn);
t.ok(obj.member); t.ok(obj.member);
@ -441,10 +441,10 @@ test('search empty attribute', function(t) {
t.ok(obj['member;range=0-1'].length); t.ok(obj['member;range=0-1'].length);
gotEntry++; gotEntry++;
}); });
res.on('error', function(err) { res.on('error', function (err) {
t.fail(err); t.fail(err);
}); });
res.on('end', function(res) { res.on('end', function (res) {
t.ok(res); t.ok(res);
t.ok(res instanceof ldap.SearchResponse); t.ok(res instanceof ldap.SearchResponse);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -455,14 +455,14 @@ test('search empty attribute', function(t) {
}); });
test('GH-21 binary attributes', function(t) { test('GH-21 binary attributes', function (t) {
client.search('cn=bin, ' + SUFFIX, '(objectclass=*)', function(err, res) { client.search('cn=bin, ' + SUFFIX, '(objectclass=*)', function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
var gotEntry = 0; var gotEntry = 0;
var expect = new Buffer('\u00bd + \u00bc = \u00be', 'utf8'); var expect = new Buffer('\u00bd + \u00bc = \u00be', 'utf8');
var expect2 = new Buffer([0xB5, 0xE7, 0xCA, 0xD3, 0xBB, 0xFA]); var expect2 = new Buffer([0xB5, 0xE7, 0xCA, 0xD3, 0xBB, 0xFA]);
res.on('searchEntry', function(entry) { res.on('searchEntry', function (entry) {
t.ok(entry); t.ok(entry);
t.ok(entry instanceof ldap.SearchEntry); t.ok(entry instanceof ldap.SearchEntry);
t.equal(entry.dn.toString(), 'cn=bin, ' + SUFFIX); t.equal(entry.dn.toString(), 'cn=bin, ' + SUFFIX);
@ -482,10 +482,10 @@ test('GH-21 binary attributes', function(t) {
t.ok(entry.object); t.ok(entry.object);
gotEntry++; gotEntry++;
}); });
res.on('error', function(err) { res.on('error', function (err) {
t.fail(err); t.fail(err);
}); });
res.on('end', function(res) { res.on('end', function (res) {
t.ok(res); t.ok(res);
t.ok(res instanceof ldap.SearchResponse); t.ok(res instanceof ldap.SearchResponse);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -496,16 +496,16 @@ test('GH-21 binary attributes', function(t) {
}); });
test('GH-23 case insensitive attribute filtering', function(t) { test('GH-23 case insensitive attribute filtering', function (t) {
var opts = { var opts = {
filter: '(objectclass=*)', filter: '(objectclass=*)',
attributes: ['Cn'] attributes: ['Cn']
}; };
client.search('cn=test, ' + SUFFIX, opts, function(err, res) { client.search('cn=test, ' + SUFFIX, opts, function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
var gotEntry = 0; var gotEntry = 0;
res.on('searchEntry', function(entry) { res.on('searchEntry', function (entry) {
t.ok(entry); t.ok(entry);
t.ok(entry instanceof ldap.SearchEntry); t.ok(entry instanceof ldap.SearchEntry);
t.equal(entry.dn.toString(), 'cn=test, ' + SUFFIX); t.equal(entry.dn.toString(), 'cn=test, ' + SUFFIX);
@ -515,10 +515,10 @@ test('GH-23 case insensitive attribute filtering', function(t) {
t.ok(entry.object); t.ok(entry.object);
gotEntry++; gotEntry++;
}); });
res.on('error', function(err) { res.on('error', function (err) {
t.fail(err); t.fail(err);
}); });
res.on('end', function(res) { res.on('end', function (res) {
t.ok(res); t.ok(res);
t.ok(res instanceof ldap.SearchResponse); t.ok(res instanceof ldap.SearchResponse);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -529,16 +529,16 @@ test('GH-23 case insensitive attribute filtering', function(t) {
}); });
test('GH-24 attribute selection of *', function(t) { test('GH-24 attribute selection of *', function (t) {
var opts = { var opts = {
filter: '(objectclass=*)', filter: '(objectclass=*)',
attributes: ['*'] attributes: ['*']
}; };
client.search('cn=test, ' + SUFFIX, opts, function(err, res) { client.search('cn=test, ' + SUFFIX, opts, function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
var gotEntry = 0; var gotEntry = 0;
res.on('searchEntry', function(entry) { res.on('searchEntry', function (entry) {
t.ok(entry); t.ok(entry);
t.ok(entry instanceof ldap.SearchEntry); t.ok(entry instanceof ldap.SearchEntry);
t.equal(entry.dn.toString(), 'cn=test, ' + SUFFIX); t.equal(entry.dn.toString(), 'cn=test, ' + SUFFIX);
@ -549,10 +549,10 @@ test('GH-24 attribute selection of *', function(t) {
t.ok(entry.object); t.ok(entry.object);
gotEntry++; gotEntry++;
}); });
res.on('error', function(err) { res.on('error', function (err) {
t.fail(err); t.fail(err);
}); });
res.on('end', function(res) { res.on('end', function (res) {
t.ok(res); t.ok(res);
t.ok(res instanceof ldap.SearchResponse); t.ok(res instanceof ldap.SearchResponse);
t.equal(res.status, 0); t.equal(res.status, 0);
@ -563,34 +563,34 @@ test('GH-24 attribute selection of *', function(t) {
}); });
test('abandon (GH-27)', function(t) { test('abandon (GH-27)', function (t) {
client.abandon(401876543, function(err) { client.abandon(401876543, function (err) {
t.ifError(err); t.ifError(err);
t.end(); t.end();
}); });
}); });
test('unbind (GH-30)', function(t) { test('unbind (GH-30)', function (t) {
client.unbind(function(err) { client.unbind(function (err) {
t.ifError(err); t.ifError(err);
t.end(); t.end();
}); });
}); });
test('search timeout (GH-51)', function(t) { test('search timeout (GH-51)', function (t) {
client.timeout = 250; client.timeout = 250;
client.search('dc=timeout', 'objectclass=*', function(err, res) { client.search('dc=timeout', 'objectclass=*', function (err, res) {
t.ok(err); t.ok(err);
t.end(); t.end();
}); });
}); });
test('shutdown', function(t) { test('shutdown', function (t) {
client.unbind(function(err) { client.unbind(function (err) {
server.on('close', function() { server.on('close', function () {
t.end(); t.end();
}); });
server.close(); server.close();

View File

@ -15,7 +15,7 @@ var getControl;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
Control = require('../../lib/index').Control; Control = require('../../lib/index').Control;
t.ok(Control); t.ok(Control);
getControl = require('../../lib/index').getControl; getControl = require('../../lib/index').getControl;
@ -24,13 +24,13 @@ test('load library', function(t) {
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new Control()); t.ok(new Control());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var c = new Control({ var c = new Control({
type: '2.16.840.1.113730.3.4.2', type: '2.16.840.1.113730.3.4.2',
criticality: true criticality: true
@ -42,7 +42,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.startSequence(); ber.startSequence();
ber.writeString('2.16.840.1.113730.3.4.2'); ber.writeString('2.16.840.1.113730.3.4.2');
@ -60,7 +60,7 @@ test('parse', function(t) {
}); });
test('parse no value', function(t) { test('parse no value', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.startSequence(); ber.startSequence();
ber.writeString('2.16.840.1.113730.3.4.2'); ber.writeString('2.16.840.1.113730.3.4.2');

View File

@ -13,7 +13,7 @@ var EntryChangeNotificationControl;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
EntryChangeNotificationControl = EntryChangeNotificationControl =
require('../../lib').EntryChangeNotificationControl; require('../../lib').EntryChangeNotificationControl;
t.ok(EntryChangeNotificationControl); t.ok(EntryChangeNotificationControl);
@ -23,13 +23,13 @@ test('load library', function(t) {
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new EntryChangeNotificationControl()); t.ok(new EntryChangeNotificationControl());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var c = new EntryChangeNotificationControl({ var c = new EntryChangeNotificationControl({
type: '2.16.840.1.113730.3.4.7', type: '2.16.840.1.113730.3.4.7',
criticality: true, criticality: true,
@ -62,7 +62,7 @@ test('new with args', function(t) {
t.end(); t.end();
}); });
test('tober', function(t) { test('tober', function (t) {
var psc = new EntryChangeNotificationControl({ var psc = new EntryChangeNotificationControl({
type: '2.16.840.1.113730.3.4.7', type: '2.16.840.1.113730.3.4.7',
criticality: true, criticality: true,

View File

@ -13,7 +13,7 @@ var PersistentSearchControl;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
PersistentSearchControl = require('../../lib').PersistentSearchControl; PersistentSearchControl = require('../../lib').PersistentSearchControl;
t.ok(PersistentSearchControl); t.ok(PersistentSearchControl);
getControl = require('../../lib').getControl; getControl = require('../../lib').getControl;
@ -22,13 +22,13 @@ test('load library', function(t) {
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new PersistentSearchControl()); t.ok(new PersistentSearchControl());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var c = new PersistentSearchControl({ var c = new PersistentSearchControl({
type: '2.16.840.1.113730.3.4.3', type: '2.16.840.1.113730.3.4.3',
criticality: true, criticality: true,
@ -61,23 +61,13 @@ test('new with args', function(t) {
t.end(); t.end();
}); });
test('getControl with args', function(t) { test('getControl with args', function (t) {
var buf = new Buffer([ var buf = new Buffer([
0x30, 0x26, 0x04, 0x17, 0x32, 0x2e, 0x31, 0x36, 0x2e, 0x38, 0x34, 0x30, 0x30, 0x26, 0x04, 0x17, 0x32, 0x2e, 0x31, 0x36, 0x2e, 0x38, 0x34, 0x30,
0x2e, 0x31, 0x2e, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2e, 0x33, 0x2e, 0x2e, 0x31, 0x2e, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2e, 0x33, 0x2e,
0x34, 0x2e, 0x33, 0x04, 0x0b, 0x30, 0x09, 0x02, 0x01, 0x0f, 0x01, 0x01, 0x34, 0x2e, 0x33, 0x04, 0x0b, 0x30, 0x09, 0x02, 0x01, 0x0f, 0x01, 0x01,
0xff, 0x01, 0x01, 0xff]); 0xff, 0x01, 0x01, 0xff]);
var options = {
type: '2.16.840.1.113730.3.4.3',
criticality: false,
value: {
changeTypes: 15,
changesOnly: true,
returnECs: true
}
};
var ber = new BerReader(buf); var ber = new BerReader(buf);
var psc = getControl(ber); var psc = getControl(ber);
t.ok(psc); t.ok(psc);
@ -89,7 +79,7 @@ test('getControl with args', function(t) {
t.end(); t.end();
}); });
test('tober', function(t) { test('tober', function (t) {
var psc = new PersistentSearchControl({ var psc = new PersistentSearchControl({
type: '2.16.840.1.113730.3.4.3', type: '2.16.840.1.113730.3.4.3',
criticality: true, criticality: true,

View File

@ -12,74 +12,74 @@ var dn;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
dn = require('../lib/index').dn; dn = require('../lib/index').dn;
t.ok(dn); t.ok(dn);
t.end(); t.end();
}); });
test('parse basic', function(t) { test('parse basic', function (t) {
var DN_STR = 'cn=mark, ou=people, o=joyent'; var DN_STR = 'cn=mark, ou=people, o=joyent';
var name = dn.parse(DN_STR); var name = dn.parse(DN_STR);
t.ok(name); t.ok(name);
t.ok(name.rdns); t.ok(name.rdns);
t.ok(Array.isArray(name.rdns)); t.ok(Array.isArray(name.rdns));
t.equal(3, name.rdns.length); t.equal(3, name.rdns.length);
name.rdns.forEach(function(rdn) { name.rdns.forEach(function (rdn) {
t.equal('object', typeof(rdn)); t.equal('object', typeof (rdn));
}); });
t.equal(name.toString(), DN_STR); t.equal(name.toString(), DN_STR);
t.end(); t.end();
}); });
test('parse escaped', function(t) { test('parse escaped', function (t) {
var DN_STR = 'cn=m\\,ark, ou=people, o=joyent'; var DN_STR = 'cn=m\\,ark, ou=people, o=joyent';
var name = dn.parse(DN_STR); var name = dn.parse(DN_STR);
t.ok(name); t.ok(name);
t.ok(name.rdns); t.ok(name.rdns);
t.ok(Array.isArray(name.rdns)); t.ok(Array.isArray(name.rdns));
t.equal(3, name.rdns.length); t.equal(3, name.rdns.length);
name.rdns.forEach(function(rdn) { name.rdns.forEach(function (rdn) {
t.equal('object', typeof(rdn)); t.equal('object', typeof (rdn));
}); });
t.equal(name.toString(), DN_STR); t.equal(name.toString(), DN_STR);
t.end(); t.end();
}); });
test('parse compound', function(t) { test('parse compound', function (t) {
var DN_STR = 'cn=mark+sn=cavage, ou=people, o=joyent'; var DN_STR = 'cn=mark+sn=cavage, ou=people, o=joyent';
var name = dn.parse(DN_STR); var name = dn.parse(DN_STR);
t.ok(name); t.ok(name);
t.ok(name.rdns); t.ok(name.rdns);
t.ok(Array.isArray(name.rdns)); t.ok(Array.isArray(name.rdns));
t.equal(3, name.rdns.length); t.equal(3, name.rdns.length);
name.rdns.forEach(function(rdn) { name.rdns.forEach(function (rdn) {
t.equal('object', typeof(rdn)); t.equal('object', typeof (rdn));
}); });
t.equal(name.toString(), DN_STR); t.equal(name.toString(), DN_STR);
t.end(); t.end();
}); });
test('parse quoted', function(t) { test('parse quoted', function (t) {
var DN_STR = 'cn="mark+sn=cavage", ou=people, o=joyent'; var DN_STR = 'cn="mark+sn=cavage", ou=people, o=joyent';
var name = dn.parse(DN_STR); var name = dn.parse(DN_STR);
t.ok(name); t.ok(name);
t.ok(name.rdns); t.ok(name.rdns);
t.ok(Array.isArray(name.rdns)); t.ok(Array.isArray(name.rdns));
t.equal(3, name.rdns.length); t.equal(3, name.rdns.length);
name.rdns.forEach(function(rdn) { name.rdns.forEach(function (rdn) {
t.equal('object', typeof(rdn)); t.equal('object', typeof (rdn));
}); });
t.equal(name.toString(), DN_STR); t.equal(name.toString(), DN_STR);
t.end(); t.end();
}); });
test('equals', function(t) { test('equals', function (t) {
var dn1 = dn.parse('cn=foo, dc=bar'); var dn1 = dn.parse('cn=foo, dc=bar');
t.ok(dn1.equals('cn=foo, dc=bar')); t.ok(dn1.equals('cn=foo, dc=bar'));
t.ok(!dn1.equals('cn=foo1, dc=bar')); t.ok(!dn1.equals('cn=foo1, dc=bar'));
@ -89,7 +89,7 @@ test('equals', function(t) {
}); });
test('child of', function(t) { test('child of', function (t) {
var dn1 = dn.parse('cn=foo, dc=bar'); var dn1 = dn.parse('cn=foo, dc=bar');
t.ok(dn1.childOf('dc=bar')); t.ok(dn1.childOf('dc=bar'));
t.ok(!dn1.childOf('dc=moo')); t.ok(!dn1.childOf('dc=moo'));
@ -101,7 +101,7 @@ test('child of', function(t) {
}); });
test('parent of', function(t) { test('parent of', function (t) {
var dn1 = dn.parse('cn=foo, dc=bar'); var dn1 = dn.parse('cn=foo, dc=bar');
t.ok(dn1.parentOf('cn=moo, cn=foo, dc=bar')); t.ok(dn1.parentOf('cn=moo, cn=foo, dc=bar'));
t.ok(!dn1.parentOf('cn=moo, cn=bar, dc=foo')); t.ok(!dn1.parentOf('cn=moo, cn=bar, dc=foo'));
@ -112,7 +112,7 @@ test('parent of', function(t) {
}); });
test('empty DNs GH-16', function(t) { test('empty DNs GH-16', function (t) {
var _dn = dn.parse(''); var _dn = dn.parse('');
var _dn2 = dn.parse('cn=foo'); var _dn2 = dn.parse('cn=foo');
t.notOk(_dn.equals('cn=foo')); t.notOk(_dn.equals('cn=foo'));
@ -125,7 +125,7 @@ test('empty DNs GH-16', function(t) {
}); });
test('case insensitive attribute names GH-20', function(t) { test('case insensitive attribute names GH-20', function (t) {
var dn1 = dn.parse('CN=foo, dc=bar'); var dn1 = dn.parse('CN=foo, dc=bar');
t.ok(dn1.equals('cn=foo, dc=bar')); t.ok(dn1.equals('cn=foo, dc=bar'));
t.ok(dn1.equals(dn.parse('cn=foo, DC=bar'))); t.ok(dn1.equals(dn.parse('cn=foo, DC=bar')));

View File

@ -14,7 +14,7 @@ var AndFilter;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
var filters = require('../../lib/index').filters; var filters = require('../../lib/index').filters;
t.ok(filters); t.ok(filters);
EqualityFilter = filters.EqualityFilter; EqualityFilter = filters.EqualityFilter;
@ -25,13 +25,13 @@ test('load library', function(t) {
}); });
test('Construct no args', function(t) { test('Construct no args', function (t) {
t.ok(new AndFilter()); t.ok(new AndFilter());
t.end(); t.end();
}); });
test('Construct args', function(t) { test('Construct args', function (t) {
var f = new AndFilter(); var f = new AndFilter();
f.addFilter(new EqualityFilter({ f.addFilter(new EqualityFilter({
attribute: 'foo', attribute: 'foo',
@ -47,7 +47,7 @@ test('Construct args', function(t) {
}); });
test('match true', function(t) { test('match true', function (t) {
var f = new AndFilter(); var f = new AndFilter();
f.addFilter(new EqualityFilter({ f.addFilter(new EqualityFilter({
attribute: 'foo', attribute: 'foo',
@ -63,7 +63,7 @@ test('match true', function(t) {
}); });
test('match false', function(t) { test('match false', function (t) {
var f = new AndFilter(); var f = new AndFilter();
f.addFilter(new EqualityFilter({ f.addFilter(new EqualityFilter({
attribute: 'foo', attribute: 'foo',
@ -77,5 +77,3 @@ test('match false', function(t) {
t.ok(!f.matches({ foo: 'bar', zig: 'zonk' })); t.ok(!f.matches({ foo: 'bar', zig: 'zonk' }));
t.end(); t.end();
}); });

View File

@ -15,7 +15,7 @@ var BerWriter = asn1.BerWriter;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
var filters = require('../../lib/index').filters; var filters = require('../../lib/index').filters;
t.ok(filters); t.ok(filters);
ApproximateFilter = filters.ApproximateFilter; ApproximateFilter = filters.ApproximateFilter;
@ -24,7 +24,7 @@ test('load library', function(t) {
}); });
test('Construct no args', function(t) { test('Construct no args', function (t) {
var f = new ApproximateFilter(); var f = new ApproximateFilter();
t.ok(f); t.ok(f);
t.ok(!f.attribute); t.ok(!f.attribute);
@ -33,7 +33,7 @@ test('Construct no args', function(t) {
}); });
test('Construct args', function(t) { test('Construct args', function (t) {
var f = new ApproximateFilter({ var f = new ApproximateFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -46,7 +46,7 @@ test('Construct args', function(t) {
}); });
test('match true', function(t) { test('match true', function (t) {
var f = new ApproximateFilter({ var f = new ApproximateFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -57,7 +57,7 @@ test('match true', function(t) {
}); });
test('match multiple', function(t) { test('match multiple', function (t) {
var f = new ApproximateFilter({ var f = new ApproximateFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -68,7 +68,7 @@ test('match multiple', function(t) {
t.end(); t.end();
}); });
test('match false', function(t) { test('match false', function (t) {
var f = new ApproximateFilter({ var f = new ApproximateFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -79,7 +79,7 @@ test('match false', function(t) {
}); });
test('parse ok', function(t) { test('parse ok', function (t) {
var writer = new BerWriter(); var writer = new BerWriter();
writer.writeString('foo'); writer.writeString('foo');
writer.writeString('bar'); writer.writeString('bar');
@ -92,7 +92,7 @@ test('parse ok', function(t) {
}); });
test('parse bad', function(t) { test('parse bad', function (t) {
var writer = new BerWriter(); var writer = new BerWriter();
writer.writeString('foo'); writer.writeString('foo');
writer.writeInt(20); writer.writeInt(20);

View File

@ -15,7 +15,7 @@ var BerWriter = asn1.BerWriter;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
var filters = require('../../lib/index').filters; var filters = require('../../lib/index').filters;
t.ok(filters); t.ok(filters);
EqualityFilter = filters.EqualityFilter; EqualityFilter = filters.EqualityFilter;
@ -24,7 +24,7 @@ test('load library', function(t) {
}); });
test('Construct no args', function(t) { test('Construct no args', function (t) {
var f = new EqualityFilter(); var f = new EqualityFilter();
t.ok(f); t.ok(f);
t.ok(!f.attribute); t.ok(!f.attribute);
@ -33,7 +33,7 @@ test('Construct no args', function(t) {
}); });
test('Construct args', function(t) { test('Construct args', function (t) {
var f = new EqualityFilter({ var f = new EqualityFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -46,7 +46,7 @@ test('Construct args', function(t) {
}); });
test('match true', function(t) { test('match true', function (t) {
var f = new EqualityFilter({ var f = new EqualityFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -57,7 +57,7 @@ test('match true', function(t) {
}); });
test('match multiple', function(t) { test('match multiple', function (t) {
var f = new EqualityFilter({ var f = new EqualityFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -68,7 +68,7 @@ test('match multiple', function(t) {
}); });
test('match false', function(t) { test('match false', function (t) {
var f = new EqualityFilter({ var f = new EqualityFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -79,7 +79,7 @@ test('match false', function(t) {
}); });
test('parse ok', function(t) { test('parse ok', function (t) {
var writer = new BerWriter(); var writer = new BerWriter();
writer.writeString('foo'); writer.writeString('foo');
writer.writeString('bar'); writer.writeString('bar');
@ -92,7 +92,7 @@ test('parse ok', function(t) {
}); });
test('parse bad', function(t) { test('parse bad', function (t) {
var writer = new BerWriter(); var writer = new BerWriter();
writer.writeString('foo'); writer.writeString('foo');
writer.writeInt(20); writer.writeInt(20);

View File

@ -15,7 +15,7 @@ var filters;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
filters = require('../../lib/index').filters; filters = require('../../lib/index').filters;
t.ok(filters); t.ok(filters);
ExtensibleFilter = filters.ExtensibleFilter; ExtensibleFilter = filters.ExtensibleFilter;
@ -24,14 +24,14 @@ test('load library', function(t) {
}); });
test('Construct no args', function(t) { test('Construct no args', function (t) {
var f = new ExtensibleFilter(); var f = new ExtensibleFilter();
t.ok(f); t.ok(f);
t.end(); t.end();
}); });
test('Construct args', function(t) { test('Construct args', function (t) {
var f = new ExtensibleFilter({ var f = new ExtensibleFilter({
matchType: 'foo', matchType: 'foo',
value: 'bar' value: 'bar'
@ -44,7 +44,7 @@ test('Construct args', function(t) {
}); });
test('parse RFC example 1', function(t) { test('parse RFC example 1', function (t) {
var f = filters.parseString('(cn:caseExactMatch:=Fred Flintstone)'); var f = filters.parseString('(cn:caseExactMatch:=Fred Flintstone)');
t.ok(f); t.ok(f);
t.equal(f.matchType, 'cn'); t.equal(f.matchType, 'cn');
@ -55,7 +55,7 @@ test('parse RFC example 1', function(t) {
}); });
test('parse RFC example 2', function(t) { test('parse RFC example 2', function (t) {
var f = filters.parseString('(cn:=Betty Rubble)'); var f = filters.parseString('(cn:=Betty Rubble)');
t.ok(f); t.ok(f);
t.equal(f.matchType, 'cn'); t.equal(f.matchType, 'cn');
@ -66,7 +66,7 @@ test('parse RFC example 2', function(t) {
}); });
test('parse RFC example 3', function(t) { test('parse RFC example 3', function (t) {
var f = filters.parseString('(sn:dn:2.4.6.8.10:=Barney Rubble)'); var f = filters.parseString('(sn:dn:2.4.6.8.10:=Barney Rubble)');
t.ok(f); t.ok(f);
t.equal(f.matchType, 'sn'); t.equal(f.matchType, 'sn');
@ -77,7 +77,7 @@ test('parse RFC example 3', function(t) {
}); });
test('parse RFC example 3', function(t) { test('parse RFC example 3', function (t) {
var f = filters.parseString('(o:dn:=Ace Industry)'); var f = filters.parseString('(o:dn:=Ace Industry)');
t.ok(f); t.ok(f);
t.equal(f.matchType, 'o'); t.equal(f.matchType, 'o');
@ -88,7 +88,7 @@ test('parse RFC example 3', function(t) {
}); });
test('parse RFC example 4', function(t) { test('parse RFC example 4', function (t) {
var f = filters.parseString('(:1.2.3:=Wilma Flintstone)'); var f = filters.parseString('(:1.2.3:=Wilma Flintstone)');
t.ok(f); t.ok(f);
t.notOk(f.matchType); t.notOk(f.matchType);
@ -99,7 +99,7 @@ test('parse RFC example 4', function(t) {
}); });
test('parse RFC example 5', function(t) { test('parse RFC example 5', function (t) {
var f = filters.parseString('(:DN:2.4.6.8.10:=Dino)'); var f = filters.parseString('(:DN:2.4.6.8.10:=Dino)');
t.ok(f); t.ok(f);
t.notOk(f.matchType); t.notOk(f.matchType);
@ -108,4 +108,3 @@ test('parse RFC example 5', function(t) {
t.ok(f.dnAttributes); t.ok(f.dnAttributes);
t.end(); t.end();
}); });

View File

@ -15,7 +15,7 @@ var BerWriter = asn1.BerWriter;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
var filters = require('../../lib/index').filters; var filters = require('../../lib/index').filters;
t.ok(filters); t.ok(filters);
GreaterThanEqualsFilter = filters.GreaterThanEqualsFilter; GreaterThanEqualsFilter = filters.GreaterThanEqualsFilter;
@ -24,7 +24,7 @@ test('load library', function(t) {
}); });
test('Construct no args', function(t) { test('Construct no args', function (t) {
var f = new GreaterThanEqualsFilter(); var f = new GreaterThanEqualsFilter();
t.ok(f); t.ok(f);
t.ok(!f.attribute); t.ok(!f.attribute);
@ -33,7 +33,7 @@ test('Construct no args', function(t) {
}); });
test('Construct args', function(t) { test('Construct args', function (t) {
var f = new GreaterThanEqualsFilter({ var f = new GreaterThanEqualsFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -46,7 +46,7 @@ test('Construct args', function(t) {
}); });
test('match true', function(t) { test('match true', function (t) {
var f = new GreaterThanEqualsFilter({ var f = new GreaterThanEqualsFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -57,7 +57,7 @@ test('match true', function(t) {
}); });
test('match multiple', function(t) { test('match multiple', function (t) {
var f = new GreaterThanEqualsFilter({ var f = new GreaterThanEqualsFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -67,7 +67,7 @@ test('match multiple', function(t) {
t.end(); t.end();
}); });
test('match false', function(t) { test('match false', function (t) {
var f = new GreaterThanEqualsFilter({ var f = new GreaterThanEqualsFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -78,7 +78,7 @@ test('match false', function(t) {
}); });
test('parse ok', function(t) { test('parse ok', function (t) {
var writer = new BerWriter(); var writer = new BerWriter();
writer.writeString('foo'); writer.writeString('foo');
writer.writeString('bar'); writer.writeString('bar');
@ -91,7 +91,7 @@ test('parse ok', function(t) {
}); });
test('parse bad', function(t) { test('parse bad', function (t) {
var writer = new BerWriter(); var writer = new BerWriter();
writer.writeString('foo'); writer.writeString('foo');
writer.writeInt(20); writer.writeInt(20);

View File

@ -15,7 +15,7 @@ var BerWriter = asn1.BerWriter;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
var filters = require('../../lib/index').filters; var filters = require('../../lib/index').filters;
t.ok(filters); t.ok(filters);
LessThanEqualsFilter = filters.LessThanEqualsFilter; LessThanEqualsFilter = filters.LessThanEqualsFilter;
@ -24,7 +24,7 @@ test('load library', function(t) {
}); });
test('Construct no args', function(t) { test('Construct no args', function (t) {
var f = new LessThanEqualsFilter(); var f = new LessThanEqualsFilter();
t.ok(f); t.ok(f);
t.ok(!f.attribute); t.ok(!f.attribute);
@ -33,7 +33,7 @@ test('Construct no args', function(t) {
}); });
test('Construct args', function(t) { test('Construct args', function (t) {
var f = new LessThanEqualsFilter({ var f = new LessThanEqualsFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -46,7 +46,7 @@ test('Construct args', function(t) {
}); });
test('match true', function(t) { test('match true', function (t) {
var f = new LessThanEqualsFilter({ var f = new LessThanEqualsFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -57,7 +57,7 @@ test('match true', function(t) {
}); });
test('match multiple', function(t) { test('match multiple', function (t) {
var f = new LessThanEqualsFilter({ var f = new LessThanEqualsFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -68,7 +68,7 @@ test('match multiple', function(t) {
}); });
test('match false', function(t) { test('match false', function (t) {
var f = new LessThanEqualsFilter({ var f = new LessThanEqualsFilter({
attribute: 'foo', attribute: 'foo',
value: 'bar' value: 'bar'
@ -79,7 +79,7 @@ test('match false', function(t) {
}); });
test('parse ok', function(t) { test('parse ok', function (t) {
var writer = new BerWriter(); var writer = new BerWriter();
writer.writeString('foo'); writer.writeString('foo');
writer.writeString('bar'); writer.writeString('bar');
@ -92,7 +92,7 @@ test('parse ok', function(t) {
}); });
test('parse bad', function(t) { test('parse bad', function (t) {
var writer = new BerWriter(); var writer = new BerWriter();
writer.writeString('foo'); writer.writeString('foo');
writer.writeInt(20); writer.writeInt(20);

View File

@ -14,7 +14,7 @@ var NotFilter;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
var filters = require('../../lib/index').filters; var filters = require('../../lib/index').filters;
t.ok(filters); t.ok(filters);
EqualityFilter = filters.EqualityFilter; EqualityFilter = filters.EqualityFilter;
@ -25,13 +25,13 @@ test('load library', function(t) {
}); });
test('Construct no args', function(t) { test('Construct no args', function (t) {
t.ok(new NotFilter()); t.ok(new NotFilter());
t.end(); t.end();
}); });
test('Construct args', function(t) { test('Construct args', function (t) {
var f = new NotFilter({ var f = new NotFilter({
filter: new EqualityFilter({ filter: new EqualityFilter({
attribute: 'foo', attribute: 'foo',
@ -44,7 +44,7 @@ test('Construct args', function(t) {
}); });
test('match true', function(t) { test('match true', function (t) {
var f = new NotFilter({ var f = new NotFilter({
filter: new EqualityFilter({ filter: new EqualityFilter({
attribute: 'foo', attribute: 'foo',
@ -57,7 +57,7 @@ test('match true', function(t) {
}); });
test('match false', function(t) { test('match false', function (t) {
var f = new NotFilter({ var f = new NotFilter({
filter: new EqualityFilter({ filter: new EqualityFilter({
attribute: 'foo', attribute: 'foo',
@ -68,5 +68,3 @@ test('match false', function(t) {
t.ok(!f.matches({ foo: 'bar' })); t.ok(!f.matches({ foo: 'bar' }));
t.end(); t.end();
}); });

View File

@ -14,7 +14,7 @@ var OrFilter;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
var filters = require('../../lib/index').filters; var filters = require('../../lib/index').filters;
t.ok(filters); t.ok(filters);
EqualityFilter = filters.EqualityFilter; EqualityFilter = filters.EqualityFilter;
@ -25,13 +25,13 @@ test('load library', function(t) {
}); });
test('Construct no args', function(t) { test('Construct no args', function (t) {
t.ok(new OrFilter()); t.ok(new OrFilter());
t.end(); t.end();
}); });
test('Construct args', function(t) { test('Construct args', function (t) {
var f = new OrFilter(); var f = new OrFilter();
f.addFilter(new EqualityFilter({ f.addFilter(new EqualityFilter({
attribute: 'foo', attribute: 'foo',
@ -47,7 +47,7 @@ test('Construct args', function(t) {
}); });
test('match true', function(t) { test('match true', function (t) {
var f = new OrFilter(); var f = new OrFilter();
f.addFilter(new EqualityFilter({ f.addFilter(new EqualityFilter({
attribute: 'foo', attribute: 'foo',
@ -63,7 +63,7 @@ test('match true', function(t) {
}); });
test('match false', function(t) { test('match false', function (t) {
var f = new OrFilter(); var f = new OrFilter();
f.addFilter(new EqualityFilter({ f.addFilter(new EqualityFilter({
attribute: 'foo', attribute: 'foo',
@ -77,5 +77,3 @@ test('match false', function(t) {
t.ok(!f.matches({ foo: 'baz', zig: 'zonk' })); t.ok(!f.matches({ foo: 'baz', zig: 'zonk' }));
t.end(); t.end();
}); });

View File

@ -6,20 +6,20 @@ var parse = require('../../lib/index').parseFilter;
test('GH-48 XML Strings in filter', function(t) { test('GH-48 XML Strings in filter', function (t) {
var str = '(&(CentralUIEnrollments=\\<mydoc\\>*)(objectClass=User))'; var str = '(&(CentralUIEnrollments=\\<mydoc\\>*)(objectClass=User))';
var f = parse(str); var f = parse(str);
t.ok(f); t.ok(f);
t.ok(f.filters); t.ok(f.filters);
t.equal(f.filters.length, 2); t.equal(f.filters.length, 2);
f.filters.forEach(function(filter) { f.filters.forEach(function (filter) {
t.ok(filter.attribute); t.ok(filter.attribute);
}); });
t.end(); t.end();
}); });
test('GH-50 = in filter', function(t) { test('GH-50 = in filter', function (t) {
var str = '(uniquemember=uuid=930896af-bf8c-48d4-885c-6573a94b1853, ' + var str = '(uniquemember=uuid=930896af-bf8c-48d4-885c-6573a94b1853, ' +
'ou=users, o=smartdc)'; 'ou=users, o=smartdc)';
var f = parse(str); var f = parse(str);
@ -31,7 +31,7 @@ test('GH-50 = in filter', function(t) {
}); });
test('( in filter', function(t) { test('( in filter', function (t) {
var str = '(foo=bar\\()'; var str = '(foo=bar\\()';
var f = parse(str); var f = parse(str);
t.ok(f); t.ok(f);
@ -41,7 +41,7 @@ test('( in filter', function(t) {
}); });
test(') in filter', function(t) { test(') in filter', function (t) {
var str = '(foo=bar\\))'; var str = '(foo=bar\\))';
var f = parse(str); var f = parse(str);
t.ok(f); t.ok(f);
@ -51,7 +51,7 @@ test(') in filter', function(t) {
}); });
test('\\ in filter', function(t) { test('\\ in filter', function (t) {
var str = '(foo=bar\\\\)'; var str = '(foo=bar\\\\)';
var f = parse(str); var f = parse(str);
t.ok(f); t.ok(f);
@ -61,7 +61,7 @@ test('\\ in filter', function(t) {
}); });
test('* in equality filter', function(t) { test('* in equality filter', function (t) {
var str = '(foo=bar\\*)'; var str = '(foo=bar\\*)';
var f = parse(str); var f = parse(str);
t.ok(f); t.ok(f);
@ -71,7 +71,7 @@ test('* in equality filter', function(t) {
}); });
test('* substr filter (prefix)', function(t) { test('* substr filter (prefix)', function (t) {
var str = '(foo=bar*)'; var str = '(foo=bar*)';
var f = parse(str); var f = parse(str);
t.ok(f); t.ok(f);
@ -81,7 +81,7 @@ test('* substr filter (prefix)', function(t) {
}); });
test('GH-53 NotFilter', function(t) { test('GH-53 NotFilter', function (t) {
var str = '(&(objectClass=person)(!(objectClass=shadowAccount)))'; var str = '(&(objectClass=person)(!(objectClass=shadowAccount)))';
var f = parse(str); var f = parse(str);
t.ok(f); t.ok(f);

View File

@ -15,7 +15,7 @@ var BerWriter = asn1.BerWriter;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
var filters = require('../../lib/index').filters; var filters = require('../../lib/index').filters;
t.ok(filters); t.ok(filters);
PresenceFilter = filters.PresenceFilter; PresenceFilter = filters.PresenceFilter;
@ -24,7 +24,7 @@ test('load library', function(t) {
}); });
test('Construct no args', function(t) { test('Construct no args', function (t) {
var f = new PresenceFilter(); var f = new PresenceFilter();
t.ok(f); t.ok(f);
t.ok(!f.attribute); t.ok(!f.attribute);
@ -32,7 +32,7 @@ test('Construct no args', function(t) {
}); });
test('Construct args', function(t) { test('Construct args', function (t) {
var f = new PresenceFilter({ var f = new PresenceFilter({
attribute: 'foo' attribute: 'foo'
}); });
@ -43,7 +43,7 @@ test('Construct args', function(t) {
}); });
test('match true', function(t) { test('match true', function (t) {
var f = new PresenceFilter({ var f = new PresenceFilter({
attribute: 'foo' attribute: 'foo'
}); });
@ -53,7 +53,7 @@ test('match true', function(t) {
}); });
test('match false', function(t) { test('match false', function (t) {
var f = new PresenceFilter({ var f = new PresenceFilter({
attribute: 'foo' attribute: 'foo'
}); });
@ -63,7 +63,7 @@ test('match false', function(t) {
}); });
test('parse ok', function(t) { test('parse ok', function (t) {
var writer = new BerWriter(); var writer = new BerWriter();
writer.writeString('foo', 0x87); writer.writeString('foo', 0x87);

View File

@ -15,7 +15,7 @@ var BerWriter = asn1.BerWriter;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
var filters = require('../../lib/index').filters; var filters = require('../../lib/index').filters;
t.ok(filters); t.ok(filters);
SubstringFilter = filters.SubstringFilter; SubstringFilter = filters.SubstringFilter;
@ -24,7 +24,7 @@ test('load library', function(t) {
}); });
test('Construct no args', function(t) { test('Construct no args', function (t) {
var f = new SubstringFilter(); var f = new SubstringFilter();
t.ok(f); t.ok(f);
t.ok(!f.attribute); t.ok(!f.attribute);
@ -33,7 +33,7 @@ test('Construct no args', function(t) {
}); });
test('Construct args', function(t) { test('Construct args', function (t) {
var f = new SubstringFilter({ var f = new SubstringFilter({
attribute: 'foo', attribute: 'foo',
initial: 'bar', initial: 'bar',
@ -52,7 +52,7 @@ test('Construct args', function(t) {
}); });
test('match true', function(t) { test('match true', function (t) {
var f = new SubstringFilter({ var f = new SubstringFilter({
attribute: 'foo', attribute: 'foo',
initial: 'bar', initial: 'bar',
@ -65,7 +65,7 @@ test('match true', function(t) {
}); });
test('match false', function(t) { test('match false', function (t) {
var f = new SubstringFilter({ var f = new SubstringFilter({
attribute: 'foo', attribute: 'foo',
initial: 'bar', initial: 'bar',
@ -78,7 +78,7 @@ test('match false', function(t) {
}); });
test('match any', function(t) { test('match any', function (t) {
var f = new SubstringFilter({ var f = new SubstringFilter({
attribute: 'foo', attribute: 'foo',
initial: 'bar' initial: 'bar'
@ -88,7 +88,7 @@ test('match any', function(t) {
t.end(); t.end();
}); });
test('parse ok', function(t) { test('parse ok', function (t) {
var writer = new BerWriter(); var writer = new BerWriter();
writer.writeString('foo'); writer.writeString('foo');
writer.startSequence(); writer.startSequence();
@ -104,7 +104,7 @@ test('parse ok', function(t) {
}); });
test('parse bad', function(t) { test('parse bad', function (t) {
var writer = new BerWriter(); var writer = new BerWriter();
writer.writeString('foo'); writer.writeString('foo');
writer.writeInt(20); writer.writeInt(20);

View File

@ -19,20 +19,20 @@ var server;
///--- Helper ///--- Helper
function search(t, options, callback) { function search(t, options, callback) {
client.search(SUFFIX, options, function(err, res) { client.search(SUFFIX, options, function (err, res) {
t.ifError(err); t.ifError(err);
t.ok(res); t.ok(res);
var found = false; var found = false;
res.on('searchEntry', function(entry) { res.on('searchEntry', function (entry) {
t.ok(entry); t.ok(entry);
found = true; found = true;
}); });
res.on('end', function() { res.on('end', function () {
t.ok(found); t.ok(found);
if (callback) if (callback)
return callback(); return callback();
t.end(); return t.end();
}); });
}); });
} }
@ -41,10 +41,10 @@ function search(t, options, callback) {
///--- Tests ///--- Tests
test('setup', function(t) { test('setup', function (t) {
server = ldap.createServer(); server = ldap.createServer();
t.ok(server); t.ok(server);
server.listen(SOCKET, function() { server.listen(SOCKET, function () {
client = ldap.createClient({ client = ldap.createClient({
socketPath: SOCKET socketPath: SOCKET
}); });
@ -52,11 +52,11 @@ test('setup', function(t) {
t.end(); t.end();
}); });
server.bind('cn=root', function(req, res, next) { server.bind('cn=root', function (req, res, next) {
res.end(); res.end();
return next(); return next();
}); });
server.search(SUFFIX, function(req, res, next) { server.search(SUFFIX, function (req, res, next) {
var entry = { var entry = {
dn: 'cn=foo, ' + SUFFIX, dn: 'cn=foo, ' + SUFFIX,
attributes: { attributes: {
@ -76,7 +76,7 @@ test('setup', function(t) {
}); });
test('Evolution search filter (GH-3)', function(t) { test('Evolution search filter (GH-3)', function (t) {
// This is what Evolution sends, when searching for a contact 'ogo'. Wow. // This is what Evolution sends, when searching for a contact 'ogo'. Wow.
var filter = var filter =
'(|(cn=ogo*)(givenname=ogo*)(sn=ogo*)(mail=ogo*)(member=ogo*)' + '(|(cn=ogo*)(givenname=ogo*)(sn=ogo*)(mail=ogo*)(member=ogo*)' +
@ -100,7 +100,7 @@ test('Evolution search filter (GH-3)', function(t) {
}); });
test('GH-49 Client errors on bad attributes', function(t) { test('GH-49 Client errors on bad attributes', function (t) {
var searchOpts = { var searchOpts = {
filter: 'cn=*ogo*', filter: 'cn=*ogo*',
scope: 'one', scope: 'one',
@ -110,19 +110,19 @@ test('GH-49 Client errors on bad attributes', function(t) {
}); });
test('GH-55 Client emits connect multiple times', function(t) { test('GH-55 Client emits connect multiple times', function (t) {
var c = ldap.createClient({ var c = ldap.createClient({
socketPath: SOCKET socketPath: SOCKET
}); });
var count = 0; var count = 0;
c.on('connect', function(socket) { c.on('connect', function (socket) {
t.ok(socket); t.ok(socket);
count++; count++;
}); });
c.bind('cn=root', 'secret', function(err, res) { c.bind('cn=root', 'secret', function (err, res) {
t.ifError(err); t.ifError(err);
c.unbind(function() { c.unbind(function () {
t.equal(count, 1); t.equal(count, 1);
t.end(); t.end();
}); });
@ -130,9 +130,9 @@ test('GH-55 Client emits connect multiple times', function(t) {
}); });
test('shutdown', function(t) { test('shutdown', function (t) {
client.unbind(function() { client.unbind(function () {
server.on('close', function() { server.on('close', function () {
t.end(); t.end();
}); });
server.close(); server.close();

View File

@ -15,7 +15,7 @@ var dn;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
AddRequest = require('../../lib/index').AddRequest; AddRequest = require('../../lib/index').AddRequest;
Attribute = require('../../lib/index').Attribute; Attribute = require('../../lib/index').Attribute;
dn = require('../../lib/index').dn; dn = require('../../lib/index').dn;
@ -26,13 +26,13 @@ test('load library', function(t) {
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new AddRequest()); t.ok(new AddRequest());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var req = new AddRequest({ var req = new AddRequest({
entry: dn.parse('cn=foo, o=test'), entry: dn.parse('cn=foo, o=test'),
attributes: [new Attribute({type: 'cn', vals: ['foo']}), attributes: [new Attribute({type: 'cn', vals: ['foo']}),
@ -49,7 +49,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeString('cn=foo,o=test'); ber.writeString('cn=foo,o=test');
@ -83,7 +83,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var req = new AddRequest({ var req = new AddRequest({
messageID: 123, messageID: 123,
entry: dn.parse('cn=foo, o=test'), entry: dn.parse('cn=foo, o=test'),
@ -115,7 +115,7 @@ test('toBer', function(t) {
}); });
test('toObject', function(t) { test('toObject', function (t) {
var req = new AddRequest({ var req = new AddRequest({
entry: dn.parse('cn=foo, o=test'), entry: dn.parse('cn=foo, o=test'),
attributes: [new Attribute({type: 'cn', vals: ['foo', 'bar']}), attributes: [new Attribute({type: 'cn', vals: ['foo', 'bar']}),

View File

@ -14,20 +14,20 @@ var AddResponse;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
AddResponse = require('../../lib/index').AddResponse; AddResponse = require('../../lib/index').AddResponse;
t.ok(AddResponse); t.ok(AddResponse);
t.end(); t.end();
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new AddResponse()); t.ok(new AddResponse());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var res = new AddResponse({ var res = new AddResponse({
messageID: 123, messageID: 123,
status: 0 status: 0
@ -39,7 +39,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeEnumeration(0); ber.writeEnumeration(0);
ber.writeString('cn=root'); ber.writeString('cn=root');
@ -54,7 +54,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var res = new AddResponse({ var res = new AddResponse({
messageID: 123, messageID: 123,
status: 3, status: 3,

View File

@ -14,7 +14,7 @@ var dn;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
BindRequest = require('../../lib/index').BindRequest; BindRequest = require('../../lib/index').BindRequest;
dn = require('../../lib/index').dn; dn = require('../../lib/index').dn;
t.ok(BindRequest); t.ok(BindRequest);
@ -23,13 +23,13 @@ test('load library', function(t) {
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new BindRequest()); t.ok(new BindRequest());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var req = new BindRequest({ var req = new BindRequest({
version: 3, version: 3,
name: dn.parse('cn=root'), name: dn.parse('cn=root'),
@ -43,7 +43,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeInt(3); ber.writeInt(3);
ber.writeString('cn=root'); ber.writeString('cn=root');
@ -60,7 +60,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var req = new BindRequest({ var req = new BindRequest({
messageID: 123, messageID: 123,
version: 3, version: 3,

View File

@ -14,20 +14,20 @@ var BindResponse;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
BindResponse = require('../../lib/index').BindResponse; BindResponse = require('../../lib/index').BindResponse;
t.ok(BindResponse); t.ok(BindResponse);
t.end(); t.end();
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new BindResponse()); t.ok(new BindResponse());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var res = new BindResponse({ var res = new BindResponse({
messageID: 123, messageID: 123,
status: 0 status: 0
@ -39,7 +39,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeEnumeration(0); ber.writeEnumeration(0);
ber.writeString('cn=root'); ber.writeString('cn=root');
@ -54,7 +54,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var res = new BindResponse({ var res = new BindResponse({
messageID: 123, messageID: 123,
status: 3, status: 3,

View File

@ -14,7 +14,7 @@ var dn;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
CompareRequest = require('../../lib/index').CompareRequest; CompareRequest = require('../../lib/index').CompareRequest;
dn = require('../../lib/index').dn; dn = require('../../lib/index').dn;
t.ok(CompareRequest); t.ok(CompareRequest);
@ -23,13 +23,13 @@ test('load library', function(t) {
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new CompareRequest()); t.ok(new CompareRequest());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var req = new CompareRequest({ var req = new CompareRequest({
entry: dn.parse('cn=foo, o=test'), entry: dn.parse('cn=foo, o=test'),
attribute: 'sn', attribute: 'sn',
@ -43,7 +43,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeString('cn=foo,o=test'); ber.writeString('cn=foo,o=test');
@ -62,7 +62,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var req = new CompareRequest({ var req = new CompareRequest({
messageID: 123, messageID: 123,
entry: dn.parse('cn=foo, o=test'), entry: dn.parse('cn=foo, o=test'),

View File

@ -14,20 +14,20 @@ var CompareResponse;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
CompareResponse = require('../../lib/index').CompareResponse; CompareResponse = require('../../lib/index').CompareResponse;
t.ok(CompareResponse); t.ok(CompareResponse);
t.end(); t.end();
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new CompareResponse()); t.ok(new CompareResponse());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var res = new CompareResponse({ var res = new CompareResponse({
messageID: 123, messageID: 123,
status: 0 status: 0
@ -39,7 +39,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeEnumeration(0); ber.writeEnumeration(0);
ber.writeString('cn=root'); ber.writeString('cn=root');
@ -54,7 +54,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var res = new CompareResponse({ var res = new CompareResponse({
messageID: 123, messageID: 123,
status: 3, status: 3,

View File

@ -15,7 +15,7 @@ var dn;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
DeleteRequest = require('../../lib/index').DeleteRequest; DeleteRequest = require('../../lib/index').DeleteRequest;
dn = require('../../lib/index').dn; dn = require('../../lib/index').dn;
t.ok(DeleteRequest); t.ok(DeleteRequest);
@ -23,13 +23,13 @@ test('load library', function(t) {
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new DeleteRequest()); t.ok(new DeleteRequest());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var req = new DeleteRequest({ var req = new DeleteRequest({
entry: dn.parse('cn=test') entry: dn.parse('cn=test')
}); });
@ -39,7 +39,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeString('cn=test', 0x4a); ber.writeString('cn=test', 0x4a);
@ -52,7 +52,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var req = new DeleteRequest({ var req = new DeleteRequest({
messageID: 123, messageID: 123,
entry: dn.parse('cn=test') entry: dn.parse('cn=test')

View File

@ -14,20 +14,20 @@ var DeleteResponse;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
DeleteResponse = require('../../lib/index').DeleteResponse; DeleteResponse = require('../../lib/index').DeleteResponse;
t.ok(DeleteResponse); t.ok(DeleteResponse);
t.end(); t.end();
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new DeleteResponse()); t.ok(new DeleteResponse());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var res = new DeleteResponse({ var res = new DeleteResponse({
messageID: 123, messageID: 123,
status: 0 status: 0
@ -39,7 +39,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeEnumeration(0); ber.writeEnumeration(0);
ber.writeString('cn=root'); ber.writeString('cn=root');
@ -54,7 +54,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var res = new DeleteResponse({ var res = new DeleteResponse({
messageID: 123, messageID: 123,
status: 3, status: 3,

View File

@ -14,7 +14,7 @@ var dn;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
ExtendedRequest = require('../../lib/index').ExtendedRequest; ExtendedRequest = require('../../lib/index').ExtendedRequest;
dn = require('../../lib/index').dn; dn = require('../../lib/index').dn;
t.ok(ExtendedRequest); t.ok(ExtendedRequest);
@ -23,13 +23,13 @@ test('load library', function(t) {
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new ExtendedRequest()); t.ok(new ExtendedRequest());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var req = new ExtendedRequest({ var req = new ExtendedRequest({
requestName: '1.2.3.4', requestName: '1.2.3.4',
requestValue: 'test' requestValue: 'test'
@ -41,7 +41,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeString('1.2.3.4', 0x80); ber.writeString('1.2.3.4', 0x80);
ber.writeString('test', 0x81); ber.writeString('test', 0x81);
@ -55,7 +55,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var req = new ExtendedRequest({ var req = new ExtendedRequest({
messageID: 123, messageID: 123,
requestName: '1.2.3.4', requestName: '1.2.3.4',

View File

@ -14,20 +14,20 @@ var ExtendedResponse;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
ExtendedResponse = require('../../lib/index').ExtendedResponse; ExtendedResponse = require('../../lib/index').ExtendedResponse;
t.ok(ExtendedResponse); t.ok(ExtendedResponse);
t.end(); t.end();
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new ExtendedResponse()); t.ok(new ExtendedResponse());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var res = new ExtendedResponse({ var res = new ExtendedResponse({
messageID: 123, messageID: 123,
status: 0, status: 0,
@ -43,7 +43,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeEnumeration(0); ber.writeEnumeration(0);
ber.writeString('cn=root'); ber.writeString('cn=root');
@ -62,7 +62,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var res = new ExtendedResponse({ var res = new ExtendedResponse({
messageID: 123, messageID: 123,
status: 3, status: 3,

View File

@ -14,7 +14,7 @@ var dn;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
ModifyDNRequest = require('../../lib/index').ModifyDNRequest; ModifyDNRequest = require('../../lib/index').ModifyDNRequest;
dn = require('../../lib/index').dn; dn = require('../../lib/index').dn;
t.ok(ModifyDNRequest); t.ok(ModifyDNRequest);
@ -23,13 +23,13 @@ test('load library', function(t) {
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new ModifyDNRequest()); t.ok(new ModifyDNRequest());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var req = new ModifyDNRequest({ var req = new ModifyDNRequest({
entry: dn.parse('cn=foo, o=test'), entry: dn.parse('cn=foo, o=test'),
newRdn: dn.parse('cn=foo2'), newRdn: dn.parse('cn=foo2'),
@ -43,7 +43,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeString('cn=foo,o=test'); ber.writeString('cn=foo,o=test');
ber.writeString('cn=foo2'); ber.writeString('cn=foo2');
@ -59,7 +59,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var req = new ModifyDNRequest({ var req = new ModifyDNRequest({
messageID: 123, messageID: 123,
entry: dn.parse('cn=foo, o=test'), entry: dn.parse('cn=foo, o=test'),

View File

@ -14,20 +14,20 @@ var ModifyDNResponse;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
ModifyDNResponse = require('../../lib/index').ModifyDNResponse; ModifyDNResponse = require('../../lib/index').ModifyDNResponse;
t.ok(ModifyDNResponse); t.ok(ModifyDNResponse);
t.end(); t.end();
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new ModifyDNResponse()); t.ok(new ModifyDNResponse());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var res = new ModifyDNResponse({ var res = new ModifyDNResponse({
messageID: 123, messageID: 123,
status: 0 status: 0
@ -39,7 +39,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeEnumeration(0); ber.writeEnumeration(0);
ber.writeString('cn=root'); ber.writeString('cn=root');
@ -54,7 +54,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var res = new ModifyDNResponse({ var res = new ModifyDNResponse({
messageID: 123, messageID: 123,
status: 3, status: 3,

View File

@ -16,7 +16,7 @@ var dn;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
ModifyRequest = require('../../lib/index').ModifyRequest; ModifyRequest = require('../../lib/index').ModifyRequest;
Attribute = require('../../lib/index').Attribute; Attribute = require('../../lib/index').Attribute;
Change = require('../../lib/index').Change; Change = require('../../lib/index').Change;
@ -29,13 +29,13 @@ test('load library', function(t) {
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new ModifyRequest()); t.ok(new ModifyRequest());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var req = new ModifyRequest({ var req = new ModifyRequest({
object: dn.parse('cn=foo, o=test'), object: dn.parse('cn=foo, o=test'),
changes: [new Change({ changes: [new Change({
@ -53,7 +53,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeString('cn=foo,o=test'); ber.writeString('cn=foo,o=test');
ber.startSequence(); ber.startSequence();
@ -83,7 +83,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var req = new ModifyRequest({ var req = new ModifyRequest({
messageID: 123, messageID: 123,
object: dn.parse('cn=foo, o=test'), object: dn.parse('cn=foo, o=test'),

View File

@ -14,20 +14,20 @@ var ModifyResponse;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
ModifyResponse = require('../../lib/index').ModifyResponse; ModifyResponse = require('../../lib/index').ModifyResponse;
t.ok(ModifyResponse); t.ok(ModifyResponse);
t.end(); t.end();
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new ModifyResponse()); t.ok(new ModifyResponse());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var res = new ModifyResponse({ var res = new ModifyResponse({
messageID: 123, messageID: 123,
status: 0 status: 0
@ -39,7 +39,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeEnumeration(0); ber.writeEnumeration(0);
ber.writeString('cn=root'); ber.writeString('cn=root');
@ -54,7 +54,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var res = new ModifyResponse({ var res = new ModifyResponse({
messageID: 123, messageID: 123,
status: 3, status: 3,

View File

@ -15,7 +15,7 @@ var dn;
///--- Tests ///--- Tests
test('load library', function(t) { test('load library', function (t) {
SearchEntry = require('../../lib/index').SearchEntry; SearchEntry = require('../../lib/index').SearchEntry;
Attribute = require('../../lib/index').Attribute; Attribute = require('../../lib/index').Attribute;
dn = require('../../lib/index').dn; dn = require('../../lib/index').dn;
@ -26,13 +26,13 @@ test('load library', function(t) {
}); });
test('new no args', function(t) { test('new no args', function (t) {
t.ok(new SearchEntry()); t.ok(new SearchEntry());
t.end(); t.end();
}); });
test('new with args', function(t) { test('new with args', function (t) {
var res = new SearchEntry({ var res = new SearchEntry({
messageID: 123, messageID: 123,
objectName: dn.parse('cn=foo, o=test'), objectName: dn.parse('cn=foo, o=test'),
@ -51,7 +51,7 @@ test('new with args', function(t) {
}); });
test('parse', function(t) { test('parse', function (t) {
var ber = new BerWriter(); var ber = new BerWriter();
ber.writeString('cn=foo, o=test'); ber.writeString('cn=foo, o=test');
@ -85,7 +85,7 @@ test('parse', function(t) {
}); });
test('toBer', function(t) { test('toBer', function (t) {
var res = new SearchEntry({ var res = new SearchEntry({
messageID: 123, messageID: 123,
objectName: dn.parse('cn=foo, o=test'), objectName: dn.parse('cn=foo, o=test'),

Some files were not shown because too many files have changed in this diff Show More