Match objectClass case-insensitively in EqualityFilter

Fix mcavage/node-ldapjs#277
This commit is contained in:
Patrick Mooney 2015-06-29 20:20:06 -05:00
parent 000959d888
commit acc1ca8f43
2 changed files with 38 additions and 1 deletions

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert'); var assert = require('assert-plus');
var util = require('util'); var util = require('util');
var ASN1 = require('asn1').Ber; var ASN1 = require('asn1').Ber;
@ -20,6 +20,29 @@ Filter.mixin(EqualityFilter);
module.exports = EqualityFilter; module.exports = EqualityFilter;
EqualityFilter.prototype.matches = function (target, strictAttrCase) {
assert.object(target, 'target');
var tv = parents.getAttrValue(target, this.attribute, strictAttrCase);
var value = this.value;
if (this.attribute.toLowerCase() === 'objectclass') {
/*
* Perform case-insensitive match for objectClass since nearly every LDAP
* implementation behaves in this manner.
*/
value = value.toLowerCase();
return parents.testValues(function (v) {
return value === v.toLowerCase();
}, tv);
} else {
return parents.testValues(function (v) {
return value === v;
}, tv);
}
};
EqualityFilter.prototype.parse = function (ber) { EqualityFilter.prototype.parse = function (ber) {
assert.ok(ber); assert.ok(ber);

View File

@ -182,3 +182,17 @@ test('handle values passed via buffer', function (t) {
} }
t.end(); t.end();
}); });
test('GH-277 objectClass should be case-insensitive', function (t) {
var f = new EqualityFilter({
attribute: 'objectClass',
value: 'CaseInsensitiveObj'
});
t.ok(f);
t.ok(f.matches({ objectClass: 'CaseInsensitiveObj' }));
t.ok(f.matches({ OBJECTCLASS: 'CASEINSENSITIVEOBJ' }));
t.ok(f.matches({ objectclass: 'caseinsensitiveobj' }));
t.ok(!f.matches({ objectclass: 'matchless' }));
t.end();
});