diff --git a/lib/messages/search_response.js b/lib/messages/search_response.js index 438458b..058615b 100644 --- a/lib/messages/search_response.js +++ b/lib/messages/search_response.js @@ -62,15 +62,17 @@ SearchResponse.prototype.send = function(entry, nofiltering) { // wants to strip, or 'private' vars that are prefixed with '_' if (!nofiltering) { Object.keys(entry.attributes).forEach(function(a) { + var _a = a.toLowerCase(); if ((self.attributes.length && - self.attributes.indexOf(a) === -1) || + self.attributes.indexOf(_a) === -1) || (self.notAttributes.length && - self.notAttributes.indexOf(a) !== -1) || - (a.length && a.charAt(0) === '_')) { + self.notAttributes.indexOf(_a) !== -1) || + (_a.length && _a.charAt(0) === '_')) { delete entry.attributes[a]; } }); } + entry = new SearchEntry({ objectName: typeof(save.dn) === 'string' ? parseDN(save.dn) : save.dn, messageID: self.messageID, diff --git a/tst/client.test.js b/tst/client.test.js index 3a968c5..979553b 100644 --- a/tst/client.test.js +++ b/tst/client.test.js @@ -423,6 +423,38 @@ test('search empty attribute', function(t) { }); +test('GH-23 case insensitive attribute filtering', function(t) { + var opts = { + filter: '(objectclass=*)', + attributes: ['Cn'] + }; + 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.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() {