diff --git a/lib/messages/search_response.js b/lib/messages/search_response.js index 058615b..7de79d3 100644 --- a/lib/messages/search_response.js +++ b/lib/messages/search_response.js @@ -60,11 +60,14 @@ SearchResponse.prototype.send = function(entry, nofiltering) { // Rip out anything that either the client didn't ask for, the server // wants to strip, or 'private' vars that are prefixed with '_' - if (!nofiltering) { + if (!nofiltering && + self.attributes && + self.attributes.length && + self.attributes.indexOf('*') === -1) { + Object.keys(entry.attributes).forEach(function(a) { var _a = a.toLowerCase(); - if ((self.attributes.length && - self.attributes.indexOf(_a) === -1) || + if (self.attributes.indexOf(_a) === -1 || (self.notAttributes.length && self.notAttributes.indexOf(_a) !== -1) || (_a.length && _a.charAt(0) === '_')) { diff --git a/tst/client.test.js b/tst/client.test.js index 979553b..6d744d8 100644 --- a/tst/client.test.js +++ b/tst/client.test.js @@ -77,7 +77,16 @@ test('setup', function(t) { 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')); + } else if (req.dn.equals('cn=bin,' + SUFFIX)) { + res.send(res.createSearchEntry({ + objectName: req.dn, + attributes: { + 'foo;binary': '\u00bd + \u00bc = \u00be' + } + })); + } else { var e = res.createSearchEntry({ objectName: req.dn, attributes: { @@ -87,10 +96,9 @@ test('setup', function(t) { }); res.send(e); res.send(e); - } else { - res.send(res.createSearchReference('ldap://localhost')); } + res.end(); return next(); }); @@ -455,6 +463,41 @@ test('GH-23 case insensitive attribute filtering', function(t) { }); }); + +test('GH-24 attribute selection of *', function(t) { + var opts = { + filter: '(objectclass=*)', + attributes: ['*'] + }; + client.search('cn=test, ' + SUFFIX, opts, function(err, res) { + t.ifError(err); + t.ok(res); + var gotEntry = 0; + res.on('searchEntry', function(entry) { + t.ok(entry); + t.ok(entry instanceof ldap.SearchEntry); + t.equal(entry.dn.toString(), 'cn=test, ' + SUFFIX); + t.ok(entry.attributes); + t.ok(entry.attributes.length); + t.equal(entry.attributes[0].type, 'cn'); + t.equal(entry.attributes[1].type, 'SN'); + t.ok(entry.object); + gotEntry++; + }); + res.on('error', function(err) { + t.fail(err); + }); + res.on('end', function(res) { + t.ok(res); + t.ok(res instanceof ldap.SearchResponse); + t.equal(res.status, 0); + t.equal(gotEntry, 2); + t.end(); + }); + }); +}); + + test('shutdown', function(t) { client.unbind(function() { server.on('close', function() {