diff --git a/lib/filters/equality_filter.js b/lib/filters/equality_filter.js index a72ac94..dd5edea 100644 --- a/lib/filters/equality_filter.js +++ b/lib/filters/equality_filter.js @@ -1,6 +1,6 @@ // Copyright 2011 Mark Cavage, Inc. All rights reserved. -var assert = require('assert'); +var assert = require('assert-plus'); var util = require('util'); var ASN1 = require('asn1').Ber; @@ -20,6 +20,29 @@ Filter.mixin(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) { assert.ok(ber); diff --git a/test/filters/eq.test.js b/test/filters/eq.test.js index d14b457..c30d5a6 100644 --- a/test/filters/eq.test.js +++ b/test/filters/eq.test.js @@ -182,3 +182,17 @@ test('handle values passed via buffer', function (t) { } 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(); +});