diff --git a/lib/client/client.js b/lib/client/client.js index 0df8e1a..ffb7b41 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -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(); diff --git a/test/client.test.js b/test/client.test.js index 160d575..451ae4c 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -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({