From d9b2b1378e4dc5eac7f4d0548493994340a99fe8 Mon Sep 17 00:00:00 2001 From: Patrick Mooney Date: Fri, 6 Jun 2014 14:05:08 -0500 Subject: [PATCH] Properly dispatch unbind requests Fix mcavage/node-ldapjs#197 --- lib/server.js | 21 +++++++++++---------- test/server.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/lib/server.js b/lib/server.js index 2fe3cfd..c4e3a1d 100644 --- a/lib/server.js +++ b/lib/server.js @@ -795,16 +795,17 @@ Server.prototype._getHandlerChain = function _getHandlerChain(req, res) { } } else if (req.protocolOp === Protocol.LDAP_REQ_UNBIND) { route = routes['unbind']; - return { - backend: route ? route.backend : self, - handlers: function getUnbindChain() { - if (route && route[op]) - return route[op]; - - self.log.debug('%s unbind request %j', req.logId, req.json); - return [defaultNoOpHandler]; - } - }; + if (route) { + return { + backend: route.backend, + handlers: route[op] + }; + } else { + return { + backend: self, + handlers: [defaultNoOpHandler] + }; + } } else if (req.protocolOp === Protocol.LDAP_REQ_ABANDON) { return { backend: self, diff --git a/test/server.test.js b/test/server.test.js index 1e6b336..0a8e9e2 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -169,3 +169,28 @@ test('route absent', function (t) { }); }); }); + +test('route unbind', function (t) { + t.plan(4); + server = ldap.createServer(); + sock = getSock(); + + server.unbind(function (req, res, next) { + t.ok(true, 'server unbind successful'); + res.end(); + return next(); + }); + + server.listen(sock, function () { + t.ok(true, 'server startup'); + client = ldap.createClient({ socketPath: sock }); + client.bind('', '', function (err) { + t.ifError(err, 'client bind error'); + client.unbind(function (err) { + t.ifError(err, 'client unbind error'); + server.close(); + t.end(); + }); + }); + }); +});