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

Commit 84ac654

Browse files
chastaborCharles Tabor
and
Charles Tabor
authored
Allow for AD range attribute option (#9)
* Allow for AD range attribute option * Add ActiveDirectory non-standard range search extension support comment * Verify non-standard AD range option in separate test --------- Co-authored-by: Charles Tabor <[email protected]>
1 parent 62682f5 commit 84ac654

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/messages/search-request.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ const isValidAttributeString = str => {
3434
if (/^@[a-zA-Z][\w\d.-]*$/.test(str) === true) {
3535
return true
3636
}
37-
// ascii attribute names
37+
// ascii attribute names per RFC 4512 §2.5
3838
if (/^[a-zA-Z][\w\d.;-]*$/.test(str) === true) {
3939
return true
4040
}
41+
// Matches the non-standard `range=<low>-<high>` ActiveDirectory
42+
// extension as described in §3.1.1.3.1.3.3 (revision 57.0) of
43+
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/d2435927-0999-4c62-8c6d-13ba31a52e1a.
44+
if (/^[a-zA-Z][\w\d.-]*(;[\w\d.-]+)*;range=\d+-(\d+|\*)(;[\w\d.-]+)*$/.test(str) === true) {
45+
return true
46+
}
4147
return false
4248
}
4349

lib/messages/search-request.test.js

+34
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,40 @@ tap.test('.attributes', t => {
111111
t.strictSame(req.attributes, ['a'])
112112
})
113113

114+
t.test('supports multiple attribute options', async t => {
115+
const req = new SearchRequest({
116+
attributes: ['abc;lang-en;lang-es']
117+
})
118+
t.strictSame(req.attributes, ['abc;lang-en;lang-es'])
119+
})
120+
121+
t.test('supports range options', async t => {
122+
const req = new SearchRequest({
123+
attributes: [
124+
'a;range=0-*',
125+
'abc;range=100-200',
126+
'def;range=0-5;lang-en',
127+
'ghi;lang-en;range=6-10',
128+
'jkl;lang-en;range=11-15;lang-es'
129+
]
130+
})
131+
t.strictSame(req.attributes, [
132+
'a;range=0-*',
133+
'abc;range=100-200',
134+
'def;range=0-5;lang-en',
135+
'ghi;lang-en;range=6-10',
136+
'jkl;lang-en;range=11-15;lang-es'
137+
])
138+
})
139+
140+
t.test('throws if array contains an invalid range', async t => {
141+
const input = ['a;range=*-100']
142+
t.throws(
143+
() => new SearchRequest({ attributes: input }),
144+
'attribute must be a valid string'
145+
)
146+
})
147+
114148
t.test('skip empty attribute name', async t => {
115149
process.on('warning', handler)
116150
t.teardown(async () => {

0 commit comments

Comments
 (0)