Refactor search_response.send() so that hidden variable magic works

This commit is contained in:
Mark Cavage 2011-10-17 16:37:09 -07:00
parent 52452f63ed
commit ccff51804a
4 changed files with 21 additions and 24 deletions

View File

@ -677,7 +677,7 @@ Client.prototype._newConnection = function() {
if (self._bindDN && self._credentials) { // reconnect case
self.bind(self._bindDN, self._credentials, [], function(err) {
if(err) {
if (err) {
log.trace('%s error rebinding: %s', c.ldap.id, err.stack);
return c.end();
}
@ -757,4 +757,4 @@ Client.prototype._newConnection = function() {
});
return c;
}
};

View File

@ -44,6 +44,8 @@ SearchResponse.prototype.send = function(entry, nofiltering) {
throw new TypeError('entry (SearchEntry) required');
if (nofiltering === undefined)
nofiltering = false;
if (typeof(nofiltering) !== 'boolean')
throw new TypeError('noFiltering must be a boolean');
var self = this;
@ -56,26 +58,21 @@ SearchResponse.prototype.send = function(entry, nofiltering) {
if (!entry.attributes)
throw new Error('entry.attributes required');
var all = (self.attributes.indexOf('*') !== -1);
Object.keys(entry.attributes).forEach(function(a) {
var _a = a.toLowerCase();
if (!nofiltering && _a.length && _a[0] === '_') {
delete entry.attributes[a];
} else if (self.notAttributes.indexOf(_a) !== -1) {
delete entry.attributes[a];
} else if (all) {
// noop
} else if (self.attributes.length && self.attributes.indexOf(_a) === -1) {
delete entry.attributes[a];
}
});
var save = entry;
// 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 &&
self.attributes &&
self.attributes.length &&
self.attributes.indexOf('*') === -1) {
Object.keys(entry.attributes).forEach(function(a) {
var _a = a.toLowerCase();
if (self.attributes.indexOf(_a) === -1 ||
(self.notAttributes.length &&
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,
@ -94,10 +91,10 @@ SearchResponse.prototype.send = function(entry, nofiltering) {
this.log.warn('%s failure to write message %j: %s',
this.connection.ldap.id, this.json, e.toString());
}
};
SearchResponse.prototype.createSearchEntry = function(object) {
if (!object || typeof(object) !== 'object')
throw new TypeError('object required');

View File

@ -3,7 +3,7 @@
"name": "ldapjs",
"homepage": "http://ldapjs.org",
"description": "LDAP client and server APIs",
"version": "0.2.0",
"version": "0.2.1",
"repository": {
"type": "git",
"url": "git://github.com/mcavage/node-ldapjs.git"

View File

@ -110,7 +110,7 @@ test('setup', function(t) {
dn: 'dc=empty',
attributes: {
member: [],
'member;range=0-1': ['cn=user1, dc=empty','cn=user2, dc=empty']
'member;range=0-1': ['cn=user1, dc=empty', 'cn=user2, dc=empty']
}
});
res.end();