Add automatic bind support to client

The pooled client would automatically bind when initializing connections
if bindDN and bindCredentials were passed to during construction.
This convenience should be supported in the plain client too.
This commit is contained in:
Patrick Mooney 2014-07-08 21:44:01 -05:00
parent 643999f370
commit 6607d83b86
2 changed files with 46 additions and 0 deletions

View File

@ -179,6 +179,7 @@ function Client(options) {
EventEmitter.call(this, options);
var self = this;
var _url;
if (options.url)
_url = url.parse(options.url);
@ -213,6 +214,21 @@ function Client(options) {
this.queue.freeze();
}
// Implicitly configure setup action to bind the client if bindDN and
// bindCredentials are passed in. This will more closely mimic PooledClient
// auto-login behavior.
if (options.bindDN !== undefined &&
options.bindCredentials !== undefined) {
this.on('setup', function (clt, cb) {
clt.bind(options.bindDN, options.bindCredentials, function (err) {
if (err) {
self.emit('error', err);
}
cb(err);
});
});
}
this.socket = null;
this.connected = false;
this._connect();

View File

@ -191,6 +191,36 @@ test('simple bind success', function (t) {
});
test('auto-bind bad credentials', function (t) {
var clt = ldap.createClient({
socketPath: SOCKET,
bindDN: BIND_DN,
bindCredentials: 'totallybogus',
log: LOG
});
clt.once('error', function (err) {
t.equal(err.code, ldap.LDAP_INVALID_CREDENTIALS);
clt.destroy();
t.end();
});
});
test('auto-bind success', function (t) {
var clt = ldap.createClient({
socketPath: SOCKET,
bindDN: BIND_DN,
bindCredentials: BIND_PW,
log: LOG
});
clt.once('connect', function () {
t.ok(clt);
clt.destroy();
t.end();
});
});
test('add success', function (t) {
var attrs = [
new Attribute({