Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit ec062d3

Browse files
committed
Improve empty DN handling
- Use more strict comparisons for client input asserts - Fix baseObject comparison in SearchRequest initialization - Alter default error for server route fallthrough
1 parent 19f2c16 commit ec062d3

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

lib/client/client.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ Client.prototype.abandon = function abandon(messageID, controls, callback) {
407407
* @throws {TypeError} on invalid input.
408408
*/
409409
Client.prototype.add = function add(name, entry, controls, callback) {
410-
assert.ok(name, 'name');
410+
assert.ok(name !== undefined, 'name');
411411
assert.object(entry, 'entry');
412412
if (typeof (controls) === 'function') {
413413
callback = controls;
@@ -500,7 +500,7 @@ Client.prototype.compare = function compare(name,
500500
value,
501501
controls,
502502
callback) {
503-
assert.ok(name, 'name');
503+
assert.ok(name !== undefined, 'name');
504504
assert.string(attr, 'attr');
505505
assert.string(value, 'value');
506506
if (typeof (controls) === 'function') {
@@ -536,7 +536,7 @@ Client.prototype.compare = function compare(name,
536536
* @throws {TypeError} on invalid input.
537537
*/
538538
Client.prototype.del = function del(name, controls, callback) {
539-
assert.ok(name, 'name');
539+
assert.ok(name !== undefined, 'name');
540540
if (typeof (controls) === 'function') {
541541
callback = controls;
542542
controls = [];
@@ -609,7 +609,7 @@ Client.prototype.exop = function exop(name, value, controls, callback) {
609609
* @throws {TypeError} on invalid input.
610610
*/
611611
Client.prototype.modify = function modify(name, change, controls, callback) {
612-
assert.ok(name, 'name');
612+
assert.ok(name !== undefined, 'name');
613613
assert.object(change, 'change');
614614

615615
var changes = [];
@@ -691,7 +691,7 @@ Client.prototype.modifyDN = function modifyDN(name,
691691
newName,
692692
controls,
693693
callback) {
694-
assert.ok(name, 'name');
694+
assert.ok(name !== undefined, 'name');
695695
assert.string(newName, 'newName');
696696
if (typeof (controls) === 'function') {
697697
callback = controls;
@@ -750,7 +750,7 @@ Client.prototype.search = function search(base,
750750
controls,
751751
callback,
752752
_bypass) {
753-
assert.ok(base, 'base');
753+
assert.ok(base !== undefined, 'search base');
754754
if (Array.isArray(options) || (options instanceof Control)) {
755755
controls = options;
756756
options = {};

lib/messages/search_request.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ function SearchRequest(options) {
6464
}
6565
});
6666

67-
this.baseObject = options.baseObject || new DN([ {} ]);
67+
if (options.baseObject !== undefined) {
68+
this.baseObject = options.baseObject;
69+
} else {
70+
this.baseObject = dn.parse('');
71+
}
6872
this.scope = options.scope || 'base';
6973
this.derefAliases = options.derefAliases || Protocol.NEVER_DEREF_ALIASES;
7074
this.sizeLimit = options.sizeLimit || 0;

lib/server.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,13 @@ Server.prototype._getHandlerChain = function _getHandlerChain(req, res) {
868868
handlers: route[op]
869869
};
870870
} else {
871-
// We found a valid suffix but not a valid operation.
872-
// There might be a more generic suffix with a legitimate operation.
873-
fallbackHandler = [defaultHandler];
871+
if (suffix === '') {
872+
break;
873+
} else {
874+
// We found a valid suffix but not a valid operation.
875+
// There might be a more generic suffix with a legitimate operation.
876+
fallbackHandler = [defaultHandler];
877+
}
874878
}
875879
}
876880
}

test/client.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,23 @@ test('setup', function (t) {
231231
next(new ldap.BusyError('too much to do'));
232232
});
233233

234+
server.search('', function (req, res, next) {
235+
if (req.dn.toString() === '') {
236+
res.send({
237+
dn: '',
238+
attributes: {
239+
objectclass: ['RootDSE', 'top']
240+
}
241+
});
242+
res.end();
243+
} else {
244+
// Turn away any other requests (since '' is the fallthrough route)
245+
res.errorMessage = 'No tree found for: ' + req.dn.toString();
246+
res.end(ldap.LDAP_NO_SUCH_OBJECT);
247+
}
248+
return next();
249+
});
250+
234251
server.unbind(function (req, res, next) {
235252
res.end();
236253
return next();
@@ -274,6 +291,7 @@ test('simple bind success', function (t) {
274291
});
275292
});
276293

294+
277295
test('simple anonymous bind (empty credentials)', function (t) {
278296
client.bind('', '', function (err, res) {
279297
t.ifError(err);
@@ -283,6 +301,7 @@ test('simple anonymous bind (empty credentials)', function (t) {
283301
});
284302
});
285303

304+
286305
test('auto-bind bad credentials', function (t) {
287306
var clt = ldap.createClient({
288307
socketPath: SOCKET,
@@ -710,6 +729,29 @@ test('search referral', function (t) {
710729
});
711730

712731

732+
test('search rootDSE', function (t) {
733+
client.search('', '(objectclass=*)', function (err, res) {
734+
t.ifError(err);
735+
t.ok(res);
736+
res.on('searchEntry', function (entry) {
737+
t.ok(entry);
738+
t.equal(entry.dn.toString(), '');
739+
t.ok(entry.attributes);
740+
t.ok(entry.object);
741+
});
742+
res.on('error', function (err) {
743+
t.fail(err);
744+
});
745+
res.on('end', function (res) {
746+
t.ok(res);
747+
t.ok(res instanceof ldap.SearchResponse);
748+
t.equal(res.status, 0);
749+
t.end();
750+
});
751+
});
752+
});
753+
754+
713755
test('search empty attribute', function (t) {
714756
client.search('dc=empty', '(objectclass=*)', function (err, res) {
715757
t.ifError(err);

0 commit comments

Comments
 (0)