dn parentof/childof fixes
This commit is contained in:
parent
c8ea58fc60
commit
51f944d834
20
lib/dn.js
20
lib/dn.js
|
@ -206,7 +206,7 @@ DN.prototype.childOf = function(dn) {
|
||||||
if (!(dn instanceof DN))
|
if (!(dn instanceof DN))
|
||||||
dn = parse(dn);
|
dn = parse(dn);
|
||||||
|
|
||||||
if (this.rdns.length < dn.rdns.length)
|
if (this.rdns.length <= dn.rdns.length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var diff = this.rdns.length - dn.rdns.length;
|
var diff = this.rdns.length - dn.rdns.length;
|
||||||
|
@ -229,11 +229,25 @@ DN.prototype.parentOf = function(dn) {
|
||||||
if (!(dn instanceof DN))
|
if (!(dn instanceof DN))
|
||||||
dn = parse(dn);
|
dn = parse(dn);
|
||||||
|
|
||||||
var parent = DN.prototype.childOf.call(dn, this);
|
if (this.rdns.length >= dn.rdns.length)
|
||||||
|
return false;
|
||||||
|
|
||||||
return parent;
|
var diff = dn.rdns.length - this.rdns.length;
|
||||||
|
for (var i = this.rdns.length - 1; i >= 0; i--) {
|
||||||
|
var rdn = this.rdns[i];
|
||||||
|
for (var k in rdn) {
|
||||||
|
if (rdn.hasOwnProperty(k)) {
|
||||||
|
var theirRdn = dn.rdns[i + diff];
|
||||||
|
if (theirRdn[k] !== rdn[k])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
DN.prototype.equals = function(dn) {
|
DN.prototype.equals = function(dn) {
|
||||||
if (!(dn instanceof DN))
|
if (!(dn instanceof DN))
|
||||||
dn = parse(dn);
|
dn = parse(dn);
|
||||||
|
|
|
@ -66,8 +66,8 @@ module.exports = {
|
||||||
Control: Control,
|
Control: Control,
|
||||||
|
|
||||||
log4js: logStub,
|
log4js: logStub,
|
||||||
_schema: schema,
|
url: url,
|
||||||
url: url
|
parseURL: url.parse
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -77,3 +77,36 @@ test('parse quoted', function(t) {
|
||||||
t.equal(name.toString(), DN_STR);
|
t.equal(name.toString(), DN_STR);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('equals', function(t) {
|
||||||
|
var dn1 = dn.parse('cn=foo, dc=bar');
|
||||||
|
t.ok(dn1.equals('cn=foo, dc=bar'));
|
||||||
|
t.ok(!dn1.equals('cn=foo1, dc=bar'));
|
||||||
|
t.ok(dn1.equals(dn.parse('cn=foo, dc=bar')));
|
||||||
|
t.ok(!dn1.equals(dn.parse('cn=foo2, dc=bar')));
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('child of', function(t) {
|
||||||
|
var dn1 = dn.parse('cn=foo, dc=bar');
|
||||||
|
t.ok(dn1.childOf('dc=bar'));
|
||||||
|
t.ok(!dn1.childOf('dc=moo'));
|
||||||
|
t.ok(!dn1.childOf('dc=foo'));
|
||||||
|
t.ok(!dn1.childOf('cn=foo, dc=bar'));
|
||||||
|
|
||||||
|
t.ok(dn1.childOf(dn.parse('dc=bar')));
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('parent of', function(t) {
|
||||||
|
var dn1 = dn.parse('cn=foo, dc=bar');
|
||||||
|
t.ok(dn1.parentOf('cn=moo, cn=foo, dc=bar'));
|
||||||
|
t.ok(!dn1.parentOf('cn=moo, cn=bar, dc=foo'));
|
||||||
|
t.ok(!dn1.parentOf('cn=foo, dc=bar'));
|
||||||
|
|
||||||
|
t.ok(dn1.parentOf(dn.parse('cn=moo, cn=foo, dc=bar')));
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue