GH-23 case insensitive attribute filtering in searchResponse.send()

This commit is contained in:
Mark Cavage 2011-10-11 10:43:27 -07:00
parent 7763cf3789
commit 7dbeca1fdd
2 changed files with 37 additions and 3 deletions

View File

@ -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,

View File

@ -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() {