Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit acc1ca8

Browse files
committed
Match objectClass case-insensitively in EqualityFilter
Fix #277
1 parent 000959d commit acc1ca8

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/filters/equality_filter.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
22

3-
var assert = require('assert');
3+
var assert = require('assert-plus');
44
var util = require('util');
55

66
var ASN1 = require('asn1').Ber;
@@ -20,6 +20,29 @@ Filter.mixin(EqualityFilter);
2020
module.exports = EqualityFilter;
2121

2222

23+
EqualityFilter.prototype.matches = function (target, strictAttrCase) {
24+
assert.object(target, 'target');
25+
26+
var tv = parents.getAttrValue(target, this.attribute, strictAttrCase);
27+
var value = this.value;
28+
29+
if (this.attribute.toLowerCase() === 'objectclass') {
30+
/*
31+
* Perform case-insensitive match for objectClass since nearly every LDAP
32+
* implementation behaves in this manner.
33+
*/
34+
value = value.toLowerCase();
35+
return parents.testValues(function (v) {
36+
return value === v.toLowerCase();
37+
}, tv);
38+
} else {
39+
return parents.testValues(function (v) {
40+
return value === v;
41+
}, tv);
42+
}
43+
};
44+
45+
2346
EqualityFilter.prototype.parse = function (ber) {
2447
assert.ok(ber);
2548

test/filters/eq.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,17 @@ test('handle values passed via buffer', function (t) {
182182
}
183183
t.end();
184184
});
185+
186+
187+
test('GH-277 objectClass should be case-insensitive', function (t) {
188+
var f = new EqualityFilter({
189+
attribute: 'objectClass',
190+
value: 'CaseInsensitiveObj'
191+
});
192+
t.ok(f);
193+
t.ok(f.matches({ objectClass: 'CaseInsensitiveObj' }));
194+
t.ok(f.matches({ OBJECTCLASS: 'CASEINSENSITIVEOBJ' }));
195+
t.ok(f.matches({ objectclass: 'caseinsensitiveobj' }));
196+
t.ok(!f.matches({ objectclass: 'matchless' }));
197+
t.end();
198+
});

0 commit comments

Comments
 (0)