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

Commit

Permalink
Allow for AD range attribute option (#9)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
chastabor and Charles Tabor authored Nov 9, 2023
1 parent 62682f5 commit 84ac654
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/messages/search-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ const isValidAttributeString = str => {
if (/^@[a-zA-Z][\w\d.-]*$/.test(str) === true) {
return true
}
// ascii attribute names
// ascii attribute names per RFC 4512 §2.5
if (/^[a-zA-Z][\w\d.;-]*$/.test(str) === true) {
return true
}
// Matches the non-standard `range=<low>-<high>` ActiveDirectory
// extension as described in §3.1.1.3.1.3.3 (revision 57.0) of
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/d2435927-0999-4c62-8c6d-13ba31a52e1a.
if (/^[a-zA-Z][\w\d.-]*(;[\w\d.-]+)*;range=\d+-(\d+|\*)(;[\w\d.-]+)*$/.test(str) === true) {
return true
}
return false
}

Expand Down
34 changes: 34 additions & 0 deletions lib/messages/search-request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,40 @@ tap.test('.attributes', t => {
t.strictSame(req.attributes, ['a'])
})

t.test('supports multiple attribute options', async t => {
const req = new SearchRequest({
attributes: ['abc;lang-en;lang-es']
})
t.strictSame(req.attributes, ['abc;lang-en;lang-es'])
})

t.test('supports range options', async t => {
const req = new SearchRequest({
attributes: [
'a;range=0-*',
'abc;range=100-200',
'def;range=0-5;lang-en',
'ghi;lang-en;range=6-10',
'jkl;lang-en;range=11-15;lang-es'
]
})
t.strictSame(req.attributes, [
'a;range=0-*',
'abc;range=100-200',
'def;range=0-5;lang-en',
'ghi;lang-en;range=6-10',
'jkl;lang-en;range=11-15;lang-es'
])
})

t.test('throws if array contains an invalid range', async t => {
const input = ['a;range=*-100']
t.throws(
() => new SearchRequest({ attributes: input }),
'attribute must be a valid string'
)
})

t.test('skip empty attribute name', async t => {
process.on('warning', handler)
t.teardown(async () => {
Expand Down

0 comments on commit 84ac654

Please sign in to comment.