First commit
This commit is contained in:
9
node_modules/@ldapjs/attribute/.eslintrc
generated
vendored
Normal file
9
node_modules/@ldapjs/attribute/.eslintrc
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest"
|
||||
},
|
||||
|
||||
"extends": [
|
||||
"standard"
|
||||
]
|
||||
}
|
||||
10
node_modules/@ldapjs/attribute/.github/workflows/main.yml
generated
vendored
Normal file
10
node_modules/@ldapjs/attribute/.github/workflows/main.yml
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
name: "CI"
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
call-core-ci:
|
||||
uses: ldapjs/.github/.github/workflows/node-ci.yml@main
|
||||
5
node_modules/@ldapjs/attribute/.taprc.yaml
generated
vendored
Normal file
5
node_modules/@ldapjs/attribute/.taprc.yaml
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
reporter: terse
|
||||
coverage-map: coverage-map.js
|
||||
|
||||
files:
|
||||
- 'index.test.js'
|
||||
54
node_modules/@ldapjs/attribute/CHANGES.md
generated
vendored
Normal file
54
node_modules/@ldapjs/attribute/CHANGES.md
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
# ldap-filter
|
||||
|
||||
> ### Important
|
||||
> This file is no longer maintained. For changes, please read
|
||||
> the releases page: https://github.com/ldapjs/filter/releases
|
||||
|
||||
## 0.3.3
|
||||
|
||||
- Assert that NOT filters are closed by a parentheses
|
||||
|
||||
## 0.3.2
|
||||
|
||||
- Perform better checks for trailing characters
|
||||
- Improve test coverage
|
||||
- Change \*Filter.json to work recursively for child filters
|
||||
- Bump assert-plus dependency to 1.0.0
|
||||
|
||||
## 0.3.1
|
||||
|
||||
- Tolerate underscores in attribute names
|
||||
|
||||
## 0.3.0
|
||||
|
||||
- Enforce stricter output escaping for buffer values
|
||||
- **BREAKING** Rename `NotFilter.addfilter` to `NotFilter.setFilter`
|
||||
- **BREAKING** Rewrite filter parser to be more strict about input.
|
||||
This _significantly_ changes the sort of filters which the parser files
|
||||
acceptable. While the old parser would tolerate unescaped characters in
|
||||
the `()\*` set, the new parser requires them to be escaped via the `\XX`
|
||||
hex notation. This is in keeping with
|
||||
[RFC 4514](http://tools.ietf.org/search/rfc4515)
|
||||
- Perform better escaping for values which are not UTF-8
|
||||
|
||||
## 0.2.3
|
||||
- Update dev dependencies
|
||||
- Clean up asserts and prototypes
|
||||
|
||||
## 0.2.2
|
||||
|
||||
- Fix nested paren handling in parser
|
||||
|
||||
## 0.2.1
|
||||
|
||||
- Fix AndFilter per RFC4526
|
||||
|
||||
## 0.2.0
|
||||
|
||||
- Add 'attribute' accessor for ExtFilter matchType
|
||||
- Improve API for custom match functions
|
||||
- Support other value types in EqualityFilter
|
||||
|
||||
## 0.1.0
|
||||
|
||||
- Initial import from ldapjs
|
||||
21
node_modules/@ldapjs/attribute/LICENSE
generated
vendored
Normal file
21
node_modules/@ldapjs/attribute/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
Copyright (c) 2014 Patrick Mooney. All rights reserved.
|
||||
Copyright (c) 2014 Mark Cavage, Inc. All rights reserved.
|
||||
Copyright (c) 2022 The LDAPJS Collaborators.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE
|
||||
8
node_modules/@ldapjs/attribute/README.md
generated
vendored
Normal file
8
node_modules/@ldapjs/attribute/README.md
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# @ldapjs/attribute
|
||||
|
||||
Provides a class for representing LDAP entry attributes as described in
|
||||
[RFC 4512 §2.5](https://www.rfc-editor.org/rfc/rfc4512#section-2.5).
|
||||
|
||||
## License
|
||||
|
||||
MIT.
|
||||
3
node_modules/@ldapjs/attribute/coverage-map.js
generated
vendored
Normal file
3
node_modules/@ldapjs/attribute/coverage-map.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = testFile => testFile.replace(/\.test\.js$/, '.js')
|
||||
344
node_modules/@ldapjs/attribute/index.js
generated
vendored
Normal file
344
node_modules/@ldapjs/attribute/index.js
generated
vendored
Normal file
@ -0,0 +1,344 @@
|
||||
'use strict'
|
||||
|
||||
const { core: { LBER_SET } } = require('@ldapjs/protocol')
|
||||
const {
|
||||
BerTypes,
|
||||
BerReader,
|
||||
BerWriter
|
||||
} = require('@ldapjs/asn1')
|
||||
const warning = require('./lib/deprecations')
|
||||
|
||||
/**
|
||||
* Represents an LDAP attribute and its associated values as defined by
|
||||
* https://www.rfc-editor.org/rfc/rfc4512#section-2.5.
|
||||
*/
|
||||
class Attribute {
|
||||
#buffers = []
|
||||
#type
|
||||
|
||||
/**
|
||||
* @param {object} options
|
||||
* @param {string} [options.type=''] The name of the attribute, e.g. "cn" for
|
||||
* the common name attribute. For binary attributes, include the `;binary`
|
||||
* option, e.g. `foo;binary`.
|
||||
* @param {string|string[]} [options.values] Either a single value for the
|
||||
* attribute, or a set of values for the attribute.
|
||||
*/
|
||||
constructor (options = {}) {
|
||||
if (options.type && typeof (options.type) !== 'string') {
|
||||
throw TypeError('options.type must be a string')
|
||||
}
|
||||
this.type = options.type || ''
|
||||
|
||||
const values = options.values || options.vals || []
|
||||
if (options.vals) {
|
||||
warning.emit('LDAP_ATTRIBUTE_DEP_001')
|
||||
}
|
||||
this.values = values
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag] () {
|
||||
return 'LdapAttribute'
|
||||
}
|
||||
|
||||
/**
|
||||
* A copy of the buffers that represent the values for the attribute.
|
||||
*
|
||||
* @returns {Buffer[]}
|
||||
*/
|
||||
get buffers () {
|
||||
return this.#buffers.slice(0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the attribute to a plain JavaScript object representation.
|
||||
*
|
||||
* @returns {object}
|
||||
*/
|
||||
get pojo () {
|
||||
return {
|
||||
type: this.type,
|
||||
values: this.values
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The attribute name as provided during construction.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
get type () {
|
||||
return this.#type
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the attribute name.
|
||||
*
|
||||
* @param {string} name
|
||||
*/
|
||||
set type (name) {
|
||||
this.#type = name
|
||||
}
|
||||
|
||||
/**
|
||||
* The set of attribute values as strings.
|
||||
*
|
||||
* @returns {string[]}
|
||||
*/
|
||||
get values () {
|
||||
const encoding = _bufferEncoding(this.#type)
|
||||
return this.#buffers.map(function (v) {
|
||||
return v.toString(encoding)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the attribute's associated values. This will replace any values set
|
||||
* at construction time.
|
||||
*
|
||||
* @param {string|string[]} vals
|
||||
*/
|
||||
set values (vals) {
|
||||
if (Array.isArray(vals) === false) {
|
||||
return this.addValue(vals)
|
||||
}
|
||||
for (const value of vals) {
|
||||
this.addValue(value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link values} instead.
|
||||
*
|
||||
* @deprecated
|
||||
* @returns {string[]}
|
||||
*/
|
||||
get vals () {
|
||||
warning.emit('LDAP_ATTRIBUTE_DEP_003')
|
||||
return this.values
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link values} instead.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {string|string[]} values
|
||||
*/
|
||||
set vals (values) {
|
||||
warning.emit('LDAP_ATTRIBUTE_DEP_003')
|
||||
this.values = values
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a new value, or set of values, to the current set of values
|
||||
* associated with the attributes.
|
||||
*
|
||||
* @param {string|string[]} value
|
||||
*/
|
||||
addValue (value) {
|
||||
if (Buffer.isBuffer(value)) {
|
||||
this.#buffers.push(value)
|
||||
} else {
|
||||
this.#buffers.push(
|
||||
Buffer.from(value + '', _bufferEncoding(this.#type))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces instance properties with those found in a given BER.
|
||||
*
|
||||
* @param {import('@ldapjs/asn1').BerReader} ber
|
||||
*
|
||||
* @deprecated Use {@link fromBer} instead.
|
||||
*/
|
||||
parse (ber) {
|
||||
const attr = Attribute.fromBer(ber)
|
||||
this.#type = attr.type
|
||||
this.values = attr.values
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the {@link Attribute} instance to a {@link BerReader} capable of
|
||||
* being used in an LDAP message.
|
||||
*
|
||||
* @returns {BerReader}
|
||||
*/
|
||||
toBer () {
|
||||
const ber = new BerWriter()
|
||||
|
||||
ber.startSequence()
|
||||
ber.writeString(this.type)
|
||||
ber.startSequence(LBER_SET)
|
||||
|
||||
if (this.#buffers.length > 0) {
|
||||
for (const buffer of this.#buffers) {
|
||||
ber.writeByte(BerTypes.OctetString)
|
||||
ber.writeLength(buffer.length)
|
||||
ber.appendBuffer(buffer)
|
||||
}
|
||||
} else {
|
||||
ber.writeStringArray([])
|
||||
}
|
||||
ber.endSequence()
|
||||
ber.endSequence()
|
||||
|
||||
return new BerReader(ber.buffer)
|
||||
}
|
||||
|
||||
toJSON () {
|
||||
return this.pojo
|
||||
}
|
||||
|
||||
/**
|
||||
* Given two {@link Attribute} instances, determine if they are equal or
|
||||
* different.
|
||||
*
|
||||
* @param {Attribute} attr1 The first object to compare.
|
||||
* @param {Attribute} attr2 The second object to compare.
|
||||
*
|
||||
* @returns {number} `0` if the attributes are equal in value, `-1` if
|
||||
* `attr1` should come before `attr2` when sorted, and `1` if `attr2` should
|
||||
* come before `attr1` when sorted.
|
||||
*
|
||||
* @throws When either input object is not an {@link Attribute}.
|
||||
*/
|
||||
static compare (attr1, attr2) {
|
||||
if (Attribute.isAttribute(attr1) === false || Attribute.isAttribute(attr2) === false) {
|
||||
throw TypeError('can only compare Attribute instances')
|
||||
}
|
||||
|
||||
if (attr1.type < attr2.type) return -1
|
||||
if (attr1.type > attr2.type) return 1
|
||||
|
||||
const aValues = attr1.values
|
||||
const bValues = attr2.values
|
||||
if (aValues.length < bValues.length) return -1
|
||||
if (aValues.length > bValues.length) return 1
|
||||
|
||||
for (let i = 0; i < aValues.length; i++) {
|
||||
if (aValues[i] < bValues[i]) return -1
|
||||
if (aValues[i] > bValues[i]) return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a BER representation of an attribute, and its values, and
|
||||
* create a new {@link Attribute} instance. The BER must start
|
||||
* at the beginning of a sequence.
|
||||
*
|
||||
* @param {import('@ldapjs/asn1').BerReader} ber
|
||||
*
|
||||
* @returns {Attribute}
|
||||
*/
|
||||
static fromBer (ber) {
|
||||
ber.readSequence()
|
||||
|
||||
const type = ber.readString()
|
||||
const values = []
|
||||
|
||||
// If the next byte represents a BER "SET" sequence...
|
||||
if (ber.peek() === LBER_SET) {
|
||||
// .. read that sequence ...
|
||||
/* istanbul ignore else */
|
||||
if (ber.readSequence(LBER_SET)) {
|
||||
const end = ber.offset + ber.length
|
||||
// ... and read all values in that set.
|
||||
while (ber.offset < end) {
|
||||
values.push(
|
||||
ber.readString(BerTypes.OctetString, true)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const result = new Attribute({
|
||||
type,
|
||||
values
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an object of attribute types mapping to attribute values, construct
|
||||
* a set of Attributes.
|
||||
*
|
||||
* @param {object} obj Each key is an attribute type, and each value is an
|
||||
* attribute value or set of values.
|
||||
*
|
||||
* @returns {Attribute[]}
|
||||
*
|
||||
* @throws If an attribute cannot be constructed correctly.
|
||||
*/
|
||||
static fromObject (obj) {
|
||||
const attributes = []
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (Array.isArray(value) === true) {
|
||||
attributes.push(new Attribute({
|
||||
type: key,
|
||||
values: value
|
||||
}))
|
||||
} else {
|
||||
attributes.push(new Attribute({
|
||||
type: key,
|
||||
values: [value]
|
||||
}))
|
||||
}
|
||||
}
|
||||
return attributes
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an object represents an {@link Attribute}.
|
||||
*
|
||||
* @param {object} attr The object to check. It can be an instance of
|
||||
* {@link Attribute} or a plain JavaScript object that looks like an
|
||||
* {@link Attribute} and can be passed to the constructor to create one.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static isAttribute (attr) {
|
||||
if (typeof attr !== 'object') {
|
||||
return false
|
||||
}
|
||||
|
||||
if (Object.prototype.toString.call(attr) === '[object LdapAttribute]') {
|
||||
return true
|
||||
}
|
||||
|
||||
const typeOk = typeof attr.type === 'string'
|
||||
let valuesOk = Array.isArray(attr.values)
|
||||
if (valuesOk === true) {
|
||||
for (const val of attr.values) {
|
||||
if (typeof val !== 'string' && Buffer.isBuffer(val) === false) {
|
||||
valuesOk = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeOk === true && valuesOk === true) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Attribute
|
||||
|
||||
/**
|
||||
* Determine the encoding for values based upon whether the binary
|
||||
* option is set on the attribute.
|
||||
*
|
||||
* @param {string} type
|
||||
*
|
||||
* @returns {string} Either "utf8" for a plain string value, or "base64" for
|
||||
* a binary attribute.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _bufferEncoding (type) {
|
||||
return /;binary$/.test(type) ? 'base64' : 'utf8'
|
||||
}
|
||||
403
node_modules/@ldapjs/attribute/index.test.js
generated
vendored
Normal file
403
node_modules/@ldapjs/attribute/index.test.js
generated
vendored
Normal file
@ -0,0 +1,403 @@
|
||||
'use strict'
|
||||
|
||||
const tap = require('tap')
|
||||
const {
|
||||
BerReader,
|
||||
BerWriter
|
||||
} = require('@ldapjs/asn1')
|
||||
const { core: { LBER_SET } } = require('@ldapjs/protocol')
|
||||
const warning = require('./lib/deprecations')
|
||||
const Attribute = require('./')
|
||||
|
||||
// Silence the standard warning logs. We will test the messages explicitly.
|
||||
process.removeAllListeners('warning')
|
||||
|
||||
tap.test('constructor', t => {
|
||||
t.test('new no args', async t => {
|
||||
t.ok(new Attribute())
|
||||
// TODO: verify attributes
|
||||
})
|
||||
|
||||
t.test('new with args', async t => {
|
||||
let attr = new Attribute({
|
||||
type: 'cn',
|
||||
values: ['foo', 'bar']
|
||||
})
|
||||
|
||||
t.ok(attr)
|
||||
|
||||
attr.addValue('baz')
|
||||
t.equal(attr.type, 'cn')
|
||||
const values = attr.values
|
||||
t.equal(values.length, 3)
|
||||
t.equal(values[0], 'foo')
|
||||
t.equal(values[1], 'bar')
|
||||
t.equal(values[2], 'baz')
|
||||
|
||||
t.throws(function () {
|
||||
const typeThatIsNotAString = 1
|
||||
attr = new Attribute({
|
||||
type: typeThatIsNotAString
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
t.test('supports binary attributes', async t => {
|
||||
const attr = new Attribute({
|
||||
type: 'foo;binary',
|
||||
values: ['bar']
|
||||
})
|
||||
t.strictSame(attr.pojo, {
|
||||
type: 'foo;binary',
|
||||
values: ['bao=']
|
||||
})
|
||||
})
|
||||
|
||||
t.test('warns for vals', t => {
|
||||
process.on('warning', handler)
|
||||
t.teardown(async () => {
|
||||
process.removeListener('warning', handler)
|
||||
warning.emitted.set('LDAP_MESSAGE_DEP_001', false)
|
||||
})
|
||||
|
||||
const attr = new Attribute({
|
||||
type: 'foo',
|
||||
vals: ['bar']
|
||||
})
|
||||
t.ok(attr)
|
||||
|
||||
function handler (error) {
|
||||
t.equal(
|
||||
error.message,
|
||||
'options.vals is deprecated. Use options.values instead.'
|
||||
)
|
||||
t.end()
|
||||
}
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tap.test('.values', t => {
|
||||
t.test('adds an array of strings', async t => {
|
||||
const attr = new Attribute({ type: 'foo' })
|
||||
attr.values = ['bar', 'baz']
|
||||
t.strictSame(attr.pojo, {
|
||||
type: 'foo',
|
||||
values: ['bar', 'baz']
|
||||
})
|
||||
})
|
||||
|
||||
t.test('adds a single string', async t => {
|
||||
const attr = new Attribute({ type: 'foo' })
|
||||
attr.values = 'bar'
|
||||
t.strictSame(attr.pojo, {
|
||||
type: 'foo',
|
||||
values: ['bar']
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tap.test('.vals', t => {
|
||||
t.beforeEach(async t => {
|
||||
process.on('warning', handler)
|
||||
t.context.handler = handler
|
||||
|
||||
function handler (error) {
|
||||
t.equal(
|
||||
error.message,
|
||||
'Instance property .vals is deprecated. Use property .values instead.'
|
||||
)
|
||||
t.end()
|
||||
}
|
||||
})
|
||||
|
||||
t.afterEach(async (t) => {
|
||||
process.removeListener('warning', t.context.handler)
|
||||
warning.emitted.set('LDAP_ATTRIBUTE_DEP_003', false)
|
||||
})
|
||||
|
||||
t.test('adds an array of strings', async t => {
|
||||
const attr = new Attribute({ type: 'foo' })
|
||||
attr.vals = ['bar', 'baz']
|
||||
t.strictSame(attr.pojo, {
|
||||
type: 'foo',
|
||||
values: ['bar', 'baz']
|
||||
})
|
||||
})
|
||||
|
||||
t.test('adds a single string', async t => {
|
||||
const attr = new Attribute({ type: 'foo' })
|
||||
attr.vals = 'bar'
|
||||
t.strictSame(attr.pojo, {
|
||||
type: 'foo',
|
||||
values: ['bar']
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tap.test('.buffers', t => {
|
||||
t.test('returns underlying buffers', async t => {
|
||||
const attr = new Attribute({
|
||||
type: 'foo',
|
||||
values: ['bar', 'baz']
|
||||
})
|
||||
const buffers = attr.buffers
|
||||
|
||||
t.equal(buffers.length, 2)
|
||||
|
||||
let expected = Buffer.from('bar', 'utf8')
|
||||
t.equal(expected.compare(buffers[0]), 0)
|
||||
|
||||
expected = Buffer.from('baz', 'utf8')
|
||||
t.equal(expected.compare(buffers[1]), 0)
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tap.test('.type', t => {
|
||||
t.test('gets and sets', async t => {
|
||||
const attr = new Attribute(({
|
||||
type: 'foo',
|
||||
values: ['bar']
|
||||
}))
|
||||
|
||||
t.equal(attr.type, 'foo')
|
||||
attr.type = 'bar'
|
||||
t.equal(attr.type, 'bar')
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tap.test('toBer', async t => {
|
||||
t.test('renders type with values', async t => {
|
||||
const attr = new Attribute({
|
||||
type: 'cn',
|
||||
values: ['foo', 'bar']
|
||||
})
|
||||
const reader = attr.toBer()
|
||||
t.ok(reader.readSequence())
|
||||
t.equal(reader.readString(), 'cn')
|
||||
t.equal(reader.readSequence(LBER_SET), LBER_SET)
|
||||
t.equal(reader.readString(), 'foo')
|
||||
t.equal(reader.readString(), 'bar')
|
||||
})
|
||||
|
||||
t.test('renders type without values', async t => {
|
||||
const attr = new Attribute({ type: 'cn' })
|
||||
const reader = attr.toBer()
|
||||
t.ok(reader.readSequence())
|
||||
t.equal(reader.readString(), 'cn')
|
||||
t.equal(reader.readSequence(LBER_SET), LBER_SET)
|
||||
t.equal(reader.remain, 0)
|
||||
})
|
||||
})
|
||||
|
||||
tap.test('parse', t => {
|
||||
t.beforeEach(async t => {
|
||||
process.on('warning', handler)
|
||||
t.teardown(async () => {
|
||||
process.removeListener('warning', handler)
|
||||
warning.emitted.set('LDAP_MESSAGE_DEP_002', false)
|
||||
})
|
||||
|
||||
function handler (error) {
|
||||
t.equal(
|
||||
error.message,
|
||||
'Instance method .parse is deprecated. Use static .fromBer instead.'
|
||||
)
|
||||
t.end()
|
||||
}
|
||||
})
|
||||
|
||||
t.test('parse', async t => {
|
||||
const ber = new BerWriter()
|
||||
ber.startSequence()
|
||||
ber.writeString('cn')
|
||||
ber.startSequence(0x31)
|
||||
ber.writeStringArray(['foo', 'bar'])
|
||||
ber.endSequence()
|
||||
ber.endSequence()
|
||||
|
||||
const attr = new Attribute()
|
||||
attr.parse(new BerReader(ber.buffer))
|
||||
|
||||
t.equal(attr.type, 'cn')
|
||||
t.equal(attr.vals.length, 2)
|
||||
t.equal(attr.vals[0], 'foo')
|
||||
t.equal(attr.vals[1], 'bar')
|
||||
})
|
||||
|
||||
t.test('parse - without 0x31', async t => {
|
||||
const ber = new BerWriter()
|
||||
ber.startSequence()
|
||||
ber.writeString('sn')
|
||||
ber.endSequence()
|
||||
|
||||
const attr = new Attribute()
|
||||
attr.parse(new BerReader(ber.buffer))
|
||||
|
||||
t.equal(attr.type, 'sn')
|
||||
t.equal(attr.vals.length, 0)
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tap.test('pojo / toJSON', t => {
|
||||
t.test('returns an object', async t => {
|
||||
const expected = {
|
||||
type: 'foo',
|
||||
values: ['bar']
|
||||
}
|
||||
const attr = new Attribute(expected)
|
||||
|
||||
t.strictSame(attr.pojo, expected)
|
||||
t.strictSame(JSON.stringify(attr), JSON.stringify(expected))
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tap.test('#fromBer', t => {
|
||||
const attributeWithValuesBytes = [
|
||||
0x30, 0x1c, // start first attribute sequence, 28 bytes
|
||||
|
||||
0x04, 0x0b, // string, 11 bytes
|
||||
0x6f, 0x62, 0x6a, 0x65, // "objectClass"
|
||||
0x63, 0x74, 0x43, 0x6c,
|
||||
0x61, 0x73, 0x73,
|
||||
0x31, 0x0d, // start value sequence, 13 bytes
|
||||
0x04, 0x03, 0x74, 0x6f, 0x70, // string: "top"
|
||||
0x04, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e // string: "domain"
|
||||
]
|
||||
|
||||
t.test('parses an attribute with values', async t => {
|
||||
const ber = new BerReader(Buffer.from(attributeWithValuesBytes))
|
||||
const attr = Attribute.fromBer(ber)
|
||||
|
||||
t.equal(attr.type, 'objectClass')
|
||||
t.equal(attr.vals[0], 'top')
|
||||
t.equal(attr.vals[1], 'domain')
|
||||
})
|
||||
|
||||
t.test('parses an attribute without values', async t => {
|
||||
const ber = new BerWriter()
|
||||
ber.startSequence()
|
||||
ber.writeString('sn')
|
||||
ber.endSequence()
|
||||
|
||||
const attr = Attribute.fromBer(new BerReader(ber.buffer))
|
||||
t.equal(attr.type, 'sn')
|
||||
t.strictSame(attr.vals, [])
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tap.test('#fromObject', t => {
|
||||
t.test('handles basic object', async t => {
|
||||
const attrs = Attribute.fromObject({
|
||||
foo: ['foo'],
|
||||
bar: 'bar',
|
||||
'baz;binary': Buffer.from([0x00])
|
||||
})
|
||||
for (const attr of attrs) {
|
||||
t.equal(Object.prototype.toString.call(attr), '[object LdapAttribute]')
|
||||
}
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tap.test('#isAttribute', t => {
|
||||
t.test('rejects non-object', async t => {
|
||||
t.equal(Attribute.isAttribute(42), false)
|
||||
})
|
||||
|
||||
t.test('accepts Attribute instances', async t => {
|
||||
const input = new Attribute({
|
||||
type: 'cn',
|
||||
values: ['foo']
|
||||
})
|
||||
t.equal(Attribute.isAttribute(input), true)
|
||||
})
|
||||
|
||||
t.test('accepts attribute-like objects', async t => {
|
||||
const input = {
|
||||
type: 'cn',
|
||||
values: [
|
||||
'foo',
|
||||
Buffer.from('bar')
|
||||
]
|
||||
}
|
||||
t.equal(Attribute.isAttribute(input), true)
|
||||
})
|
||||
|
||||
t.test('rejects non-attribute-like objects', async t => {
|
||||
let input = {
|
||||
foo: 'foo',
|
||||
values: 'bar'
|
||||
}
|
||||
t.equal(Attribute.isAttribute(input), false)
|
||||
|
||||
input = {
|
||||
type: 'cn',
|
||||
values: [42]
|
||||
}
|
||||
t.equal(Attribute.isAttribute(input), false)
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tap.test('compare', async t => {
|
||||
const comp = Attribute.compare
|
||||
let a = new Attribute({
|
||||
type: 'foo',
|
||||
values: ['bar']
|
||||
})
|
||||
const b = new Attribute({
|
||||
type: 'foo',
|
||||
values: ['bar']
|
||||
})
|
||||
const notAnAttribute = 'this is not an attribute'
|
||||
|
||||
t.throws(
|
||||
() => comp(a, notAnAttribute),
|
||||
Error('can only compare Attribute instances')
|
||||
)
|
||||
t.throws(
|
||||
() => comp(notAnAttribute, b),
|
||||
Error('can only compare Attribute instances')
|
||||
)
|
||||
|
||||
t.equal(comp(a, b), 0)
|
||||
|
||||
// Different types
|
||||
a = new Attribute({ type: 'boo' })
|
||||
t.equal(comp(a, b), -1)
|
||||
t.equal(comp(b, a), 1)
|
||||
|
||||
// Different value counts
|
||||
a = new Attribute({
|
||||
type: 'foo',
|
||||
values: ['bar', 'bar']
|
||||
})
|
||||
t.equal(comp(a, b), 1)
|
||||
t.equal(comp(b, a), -1)
|
||||
|
||||
// Different value contents (same count)
|
||||
a = new Attribute({
|
||||
type: 'foo',
|
||||
values: ['baz']
|
||||
})
|
||||
t.equal(comp(a, b), 1)
|
||||
t.equal(comp(b, a), -1)
|
||||
})
|
||||
10
node_modules/@ldapjs/attribute/lib/deprecations.js
generated
vendored
Normal file
10
node_modules/@ldapjs/attribute/lib/deprecations.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const warning = require('process-warning')()
|
||||
const clazz = 'LdapjsAttributeWarning'
|
||||
|
||||
warning.create(clazz, 'LDAP_ATTRIBUTE_DEP_001', 'options.vals is deprecated. Use options.values instead.')
|
||||
warning.create(clazz, 'LDAP_ATTRIBUTE_DEP_002', 'Instance method .parse is deprecated. Use static .fromBer instead.')
|
||||
warning.create(clazz, 'LDAP_ATTRIBUTE_DEP_003', 'Instance property .vals is deprecated. Use property .values instead.')
|
||||
|
||||
module.exports = warning
|
||||
47
node_modules/@ldapjs/attribute/package.json
generated
vendored
Normal file
47
node_modules/@ldapjs/attribute/package.json
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"originalAuthor": "Patrick Mooney",
|
||||
"originalContributors": [
|
||||
"Mark Cavage <mcavage@gmail.com>",
|
||||
"Cody Peter Mello <cody.mello@joyent.com>"
|
||||
],
|
||||
"name": "@ldapjs/attribute",
|
||||
"homepage": "https://github.com/ldapjs/attribute",
|
||||
"description": "API for handling LDAP entry attributes",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:ldapjs/attribute.git"
|
||||
},
|
||||
"main": "index.js",
|
||||
"directories": {
|
||||
"lib": "./lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ldapjs/asn1": "2.0.0",
|
||||
"@ldapjs/protocol": "^1.2.1",
|
||||
"process-warning": "^2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fastify/pre-commit": "^2.0.2",
|
||||
"eslint": "^8.34.0",
|
||||
"eslint-config-standard": "^17.0.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-n": "^15.6.1",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"tap": "^16.3.4"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"lint:ci": "eslint .",
|
||||
"test": "tap --no-coverage-report",
|
||||
"test:cov": "tap",
|
||||
"test:cov:html": "tap --coverage-report=html",
|
||||
"test:watch": "tap -w --no-coverage-report"
|
||||
},
|
||||
"precommit": [
|
||||
"lint",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user