GH-14: Support null/empty attribute values
This commit is contained in:
parent
bef40915e6
commit
01a6cfb77e
|
@ -88,11 +88,9 @@ Attribute.prototype.toBer = function(ber) {
|
|||
|
||||
ber.startSequence();
|
||||
ber.writeString(this.type);
|
||||
if (this.vals && this.vals.length) {
|
||||
ber.startSequence(Protocol.LBER_SET);
|
||||
ber.writeStringArray(this.vals);
|
||||
ber.endSequence();
|
||||
}
|
||||
ber.startSequence(Protocol.LBER_SET);
|
||||
ber.writeStringArray(this.vals && this.vals.length ? this.vals : []);
|
||||
ber.endSequence();
|
||||
ber.endSequence();
|
||||
|
||||
return ber;
|
||||
|
|
|
@ -43,7 +43,15 @@ function SearchEntry(options) {
|
|||
dn: self.dn.toString()
|
||||
};
|
||||
self.attributes.forEach(function(a) {
|
||||
obj[a.type] = a.vals.length > 1 ? a.vals.slice() : a.vals[0];
|
||||
if (a.vals && a.vals.length) {
|
||||
if (a.vals.length > 1) {
|
||||
obj[a.type] = a.vals.slice();
|
||||
} else {
|
||||
obj[a.type] = a.vals[0];
|
||||
}
|
||||
} else {
|
||||
obj[a.type] = [];
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
});
|
||||
|
|
|
@ -241,7 +241,9 @@ function Server(options) {
|
|||
|
||||
EventEmitter.call(this, options);
|
||||
|
||||
this.log = options.log4js.getLogger('Server');
|
||||
this.log4js = options.log4js;
|
||||
this.log = this.log4js.getLogger('Server');
|
||||
|
||||
var log = this.log;
|
||||
|
||||
function setupConnection(c) {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "ldapjs",
|
||||
"homepage": "http://ldapjs.org",
|
||||
"description": "LDAP client and server APIs",
|
||||
"version": "0.1.8",
|
||||
"version": "0.1.9",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mcavage/node-ldapjs.git"
|
||||
|
|
|
@ -95,6 +95,18 @@ test('setup', function(t) {
|
|||
return next();
|
||||
});
|
||||
|
||||
server.search('dc=empty', function(req, res, next) {
|
||||
res.send({
|
||||
dn: 'dc=empty',
|
||||
attributes: {
|
||||
member: [],
|
||||
'member;range=0-1': ['cn=user1, dc=empty','cn=user2, dc=empty']
|
||||
}
|
||||
});
|
||||
res.end();
|
||||
return next();
|
||||
});
|
||||
|
||||
server.unbind(function(req, res, next) {
|
||||
res.end();
|
||||
return next();
|
||||
|
@ -381,6 +393,34 @@ test('search referral', function(t) {
|
|||
});
|
||||
|
||||
|
||||
test('search empty attribute', function(t) {
|
||||
client.search('dc=empty', '(objectclass=*)', function(err, res) {
|
||||
t.ifError(err);
|
||||
t.ok(res);
|
||||
var gotEntry = 0;
|
||||
res.on('searchEntry', function(entry) {
|
||||
var obj = entry.toObject();
|
||||
t.equal('dc=empty', obj.dn);
|
||||
t.ok(obj.member);
|
||||
t.equal(obj.member.length, 0);
|
||||
t.ok(obj['member;range=0-1']);
|
||||
t.ok(obj['member;range=0-1'].length);
|
||||
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, 1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('shutdown', function(t) {
|
||||
client.unbind(function() {
|
||||
server.on('close', function() {
|
||||
|
|
Loading…
Reference in New Issue