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

Commit

Permalink
Verify non-standard AD range option in separate test
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Tabor authored and jsumners committed Nov 9, 2023
1 parent 3872e63 commit 7fbc219
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
17 changes: 8 additions & 9 deletions lib/messages/search-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ const isValidAttributeString = str => {
if (/^@[a-zA-Z][\w\d.-]*$/.test(str) === true) {
return true
}
/**
* ascii attribute names
*
* Validation inclusion of (=) and (*) characters supports 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.;=*-]*$/.test(str) === true) {
// 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
31 changes: 29 additions & 2 deletions lib/messages/search-request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,38 @@ 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-*']
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-*'])
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 => {
Expand Down

0 comments on commit 7fbc219

Please sign in to comment.