Socket
Socket
Sign inDemoInstall

ldapts

Package Overview
Dependencies
8
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.10.0 to 2.0.0

4

Attribute.js

@@ -12,3 +12,3 @@ "use strict";

writer.startSequence();
let type = this.type;
let { type } = this;
const isBinaryType = this._isBinaryType();

@@ -56,3 +56,3 @@ // If the value is a buffer and the type does not end in ;binary, append it

_isBinaryType() {
return /;binary$/.test(this.type);
return this.type.endsWith(';binary');
}

@@ -59,0 +59,0 @@ }

@@ -0,1 +1,8 @@

### 2.0.0
* Drop support for nodejs v8
* Update to Typescript 3.7
* Fix exop response overwriting status and error message. Fixes #52
* Update npms
* Improve documentation. Lots of :heart: for ldapjs docs, [ldapwiki](https://ldapwiki.com/), and [ldap.com](https://ldap.com/ldapv3-wire-protocol-reference/) docs. Fix #31
### 1.10.0

@@ -26,5 +33,5 @@ * Include original error message with exceptions. Fix #36

* Do not throw "Size limit exceeded" error if `sizeLimit` is defined and the server responds with `4` (Size limit exceeded).
- Note: It seems that items are returned even though the return status is `4` (Size limit exceeded).
I'm not really sure what to do in that case. At this time, I decided against throwing an error and instead
- Note: It seems that items are returned even though the return status is `4` (Size limit exceeded).
I'm not really sure what to do in that case. At this time, I decided against throwing an error and instead
just returning the results returned thus far. That approach works with JumpCloud and forumsys' ldap servers

@@ -88,7 +95,7 @@

* Adjust parsing & and | in filters
* Add more filter parsing tests
* Add more filter parsing tests
### 1.1.0
* Add client.add() and client.modify()
* Add client.add() and client.modify()

@@ -95,0 +102,0 @@ ### 1.0.6

@@ -96,3 +96,3 @@ /// <reference types="node" />

constructor(options: ClientOptions);
readonly isConnected: boolean;
get isConnected(): boolean;
/**

@@ -108,3 +108,3 @@ * Performs a simple authentication against the server.

* @param {string|DN} dn - The DN of the entry to add
* @param {Attribute[]|Object} attributes - Array of attributes or object where keys are the name of each attribute
* @param {Attribute[]|object} attributes - Array of attributes or object where keys are the name of each attribute
* @param {Control|Control[]} [controls]

@@ -194,5 +194,7 @@ */

* Sends request message to the ldap server over the connected socket.
* Each message request is given a unique id (messageId), used to identify the associated response when it is sent back over the socket.
Each message request is given a unique id (messageId), used to identify the associated response when it is sent back over the socket.
*
* @returns {Promise<Message>}
* @private
* @param {object} message
*/

@@ -199,0 +201,0 @@ private _send;

@@ -25,3 +25,3 @@ "use strict";

const filters_1 = require("./filters");
const MAX_MESSAGE_ID = Math.pow(2, 31) - 1;
const MAX_MESSAGE_ID = (2 ** 31) - 1;
const logDebug = debug_1.default('ldapts');

@@ -62,3 +62,4 @@ class Client {

delete this.messageDetailsByMessageId[err.messageDetails.messageId.toString()];
return messageDetails.reject(err);
messageDetails.reject(err);
return;
}

@@ -84,3 +85,2 @@ }

if (controls && !Array.isArray(controls)) {
// tslint:disable-next-line:no-parameter-reassignment
controls = [controls];

@@ -102,3 +102,3 @@ }

* @param {string|DN} dn - The DN of the entry to add
* @param {Attribute[]|Object} attributes - Array of attributes or object where keys are the name of each attribute
* @param {Attribute[]|object} attributes - Array of attributes or object where keys are the name of each attribute
* @param {Control|Control[]} [controls]

@@ -111,3 +111,2 @@ */

if (controls && !Array.isArray(controls)) {
// tslint:disable-next-line:no-parameter-reassignment
controls = [controls];

@@ -158,3 +157,2 @@ }

if (controls && !Array.isArray(controls)) {
// tslint:disable-next-line:no-parameter-reassignment
controls = [controls];

@@ -189,3 +187,2 @@ }

if (controls && !Array.isArray(controls)) {
// tslint:disable-next-line:no-parameter-reassignment
controls = [controls];

@@ -214,3 +211,2 @@ }

if (controls && !Array.isArray(controls)) {
// tslint:disable-next-line:no-parameter-reassignment
controls = [controls];

@@ -244,7 +240,5 @@ }

if (changes && !Array.isArray(changes)) {
// tslint:disable-next-line:no-parameter-reassignment
changes = [changes];
}
if (controls && !Array.isArray(controls)) {
// tslint:disable-next-line:no-parameter-reassignment
controls = [controls];

@@ -274,3 +268,2 @@ }

if (controls && !Array.isArray(controls)) {
// tslint:disable-next-line:no-parameter-reassignment
controls = [controls];

@@ -320,7 +313,5 @@ }

if (Array.isArray(controls)) {
// tslint:disable-next-line:no-parameter-reassignment
controls = controls.slice(0);
}
else {
// tslint:disable-next-line:no-parameter-reassignment
controls = [controls];

@@ -336,3 +327,2 @@ }

else {
// tslint:disable-next-line:no-parameter-reassignment
controls = [];

@@ -521,3 +511,3 @@ }

};
// tslint:disable-next-line:no-this-assignment
// eslint-disable-next-line @typescript-eslint/no-this-alias
const clientInstance = this;

@@ -565,4 +555,5 @@ function socketClose() {

socket.removeAllListeners('error');
// tslint:disable-next-line:no-empty
socket.on('error', () => { });
socket.on('error', () => {
// Ignore NOOP
});
socket.end();

@@ -572,5 +563,7 @@ }

* Sends request message to the ldap server over the connected socket.
* Each message request is given a unique id (messageId), used to identify the associated response when it is sent back over the socket.
Each message request is given a unique id (messageId), used to identify the associated response when it is sent back over the socket.
*
* @returns {Promise<Message>}
* @private
* @param {object} message
*/

@@ -581,6 +574,8 @@ _send(message) {

}
/* tslint:disable:no-empty */
let messageResolve = () => { };
let messageReject = () => { };
/* tslint:enable:no-empty */
let messageResolve = () => {
// Ignore this as a NOOP
};
let messageReject = () => {
// Ignore this as a NOOP
};
const sendPromise = new Promise((resolve, reject) => {

@@ -599,3 +594,3 @@ // @ts-ignore

this._endSocket(messageDetails.socket);
return messageReject(new Error(`${message.constructor.name}: Operation timed out`));
messageReject(new Error(`${message.constructor.name}: Operation timed out`));
}

@@ -614,3 +609,3 @@ }, this.clientOptions.timeout) : null,

else if (message instanceof messages_1.UnbindRequest) {
logDebug(`Unbind success. Ending socket`);
logDebug('Unbind success. Ending socket');
this._endSocket(this.socket);

@@ -617,0 +612,0 @@ }

@@ -8,2 +8,3 @@ "use strict";

const ServerSideSortingRequestControl_1 = require("./controls/ServerSideSortingRequestControl");
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
class ControlParser {

@@ -10,0 +11,0 @@ static parse(reader) {

@@ -17,7 +17,9 @@ "use strict";

}
// tslint:disable-next-line:no-empty
// eslint-disable-next-line @typescript-eslint/no-unused-vars
writeControl(_) {
// Do nothing as the default action
}
// tslint:disable-next-line:no-empty
// eslint-disable-next-line @typescript-eslint/no-unused-vars
parseControl(_) {
// Do nothing as the default action
}

@@ -24,0 +26,0 @@ }

@@ -20,6 +20,5 @@ import { RDN, RDNAttributes } from './RDN';

* Add an RDN component to the DN, consisting of key & value pair.
*
* @param key
* @param value
* @returns DN
* @param {string} key
* @param {string} value
* @returns {object} DN
*/

@@ -31,4 +30,4 @@ addPairRDN(key: string, value: string): this;

* Note, that this RDN can be compound (single RDN can have multiple key & value pairs).
* @param rdn
* @returns DN
* @param {object} rdn
* @returns {object} DN
*/

@@ -44,5 +43,4 @@ addRDN(rdn: RDN | RDNAttributes): this;

* - create RDNs from object map, where every key & value will create a new RDN
*
* @param rdns
* @returns DN
* @param {object|object[]} rdns
* @returns {object} DN
*/

@@ -56,4 +54,3 @@ addRDNs(rdns: RDN[] | RDNAttributes[] | RDNMap | DN): this;

* Checks, if this instance of DN is equal to the other DN.
*
* @param other
* @param {object} other
*/

@@ -60,0 +57,0 @@ equals(other: DN): boolean;

@@ -22,6 +22,5 @@ "use strict";

* Add an RDN component to the DN, consisting of key & value pair.
*
* @param key
* @param value
* @returns DN
* @param {string} key
* @param {string} value
* @returns {object} DN
*/

@@ -36,4 +35,4 @@ addPairRDN(key, value) {

* Note, that this RDN can be compound (single RDN can have multiple key & value pairs).
* @param rdn
* @returns DN
* @param {object} rdn
* @returns {object} DN
*/

@@ -57,23 +56,29 @@ addRDN(rdn) {

* - create RDNs from object map, where every key & value will create a new RDN
*
* @param rdns
* @returns DN
* @param {object|object[]} rdns
* @returns {object} DN
*/
addRDNs(rdns) {
if (rdns instanceof DN) {
this.rdns = [...this.rdns, ...rdns.rdns];
this.rdns.push(...rdns.rdns);
}
else if (Array.isArray(rdns)) {
rdns.forEach((rdn) => this.addRDN(rdn));
for (const rdn of rdns) {
this.addRDN(rdn);
}
}
else {
Object.keys(rdns).map((name) => {
const value = rdns[name];
for (const [name, value] of Object.entries(rdns)) {
if (Array.isArray(value)) {
value.forEach((v) => this.rdns.push(new RDN_1.RDN({ [name]: v })));
for (const rdnValue of value) {
this.rdns.push(new RDN_1.RDN({
[name]: rdnValue,
}));
}
}
else {
this.rdns.push(new RDN_1.RDN({ [name]: value }));
this.rdns.push(new RDN_1.RDN({
[name]: value,
}));
}
});
}
}

@@ -98,8 +103,7 @@ return this;

isEmpty() {
return this.rdns.length === 0;
return !this.rdns.length;
}
/**
* Checks, if this instance of DN is equal to the other DN.
*
* @param other
* @param {object} other
*/

@@ -106,0 +110,0 @@ equals(other) {

@@ -13,12 +13,11 @@ export interface RDNAttributes {

* Set an RDN pair.
*
* @param name
* @param value
* @param {string} name
* @param {string} value
* @returns {object} RDN class
*/
set(name: string, value: string): this;
set(name: string, value: string): RDN;
/**
* Get an RDN value at the specified name.
*
* @param name
* @returns value
* @param {string} name
* @returns {string} value
*/

@@ -28,4 +27,3 @@ get(name: string): string;

* Checks, if this instance of RDN is equal to the other RDN.
*
* @param other
* @param {object} other
*/

@@ -35,4 +33,3 @@ equals(other: RDN): boolean;

* Parse the RDN, escape values & return a string representation.
*
* @returns Escaped string representation of RDN.
* @returns {string} Escaped string representation of RDN.
*/

@@ -45,17 +42,17 @@ toString(): string;

*
* Comma ,
* Backslash character \
* Pound sign (hash sign) #
* Plus sign +
* Less than symbol <
* Greater than symbol >
* Semicolon ;
* Double quote (quotation mark) "
* Equal sign =
* Comma ,
* Backslash character \
* Pound sign (hash sign) #
* Plus sign +
* Less than symbol <
* Greater than symbol >
* Semicolon ;
* Double quote (quotation mark) "
* Equal sign =
* Leading or trailing spaces
*
* @param value RDN value to be escaped
* @returns Escaped string representation of RDN
* @param {string} value - RDN value to be escaped
* @returns {string} Escaped string representation of RDN
*/
private _escape;
}

@@ -16,5 +16,5 @@ "use strict";

* Set an RDN pair.
*
* @param name
* @param value
* @param {string} name
* @param {string} value
* @returns {object} RDN class
*/

@@ -27,5 +27,4 @@ set(name, value) {

* Get an RDN value at the specified name.
*
* @param name
* @returns value
* @param {string} name
* @returns {string} value
*/

@@ -37,4 +36,3 @@ get(name) {

* Checks, if this instance of RDN is equal to the other RDN.
*
* @param other
* @param {object} other
*/

@@ -61,4 +59,3 @@ equals(other) {

* Parse the RDN, escape values & return a string representation.
*
* @returns Escaped string representation of RDN.
* @returns {string} Escaped string representation of RDN.
*/

@@ -81,15 +78,15 @@ toString() {

*
* Comma ,
* Backslash character \
* Pound sign (hash sign) #
* Plus sign +
* Less than symbol <
* Greater than symbol >
* Semicolon ;
* Double quote (quotation mark) "
* Equal sign =
* Comma ,
* Backslash character \
* Pound sign (hash sign) #
* Plus sign +
* Less than symbol <
* Greater than symbol >
* Semicolon ;
* Double quote (quotation mark) "
* Equal sign =
* Leading or trailing spaces
*
* @param value RDN value to be escaped
* @returns Escaped string representation of RDN
* @param {string} value - RDN value to be escaped
* @returns {string} Escaped string representation of RDN
*/

@@ -101,7 +98,7 @@ _escape(value) {

const len = value.length;
const escaped = /[\\\"]/;
const escaped = /[\\"]/;
const special = /[,=+<>#;]/;
if (len > 0) {
// Wrap strings with trailing or leading spaces in quotes
quoted = value[0] === ' ' || value[len - 1] === ' ';
quoted = value.startsWith(' ') || value[len - 1] === ' ';
}

@@ -108,0 +105,0 @@ while (current < len) {

@@ -7,3 +7,8 @@ "use strict";

this.code = code;
this.message = `${message} Code: 0x${code.toString(16)}`;
if (typeof code === 'undefined' || code === null) {
this.message = message;
}
else {
this.message = `${message} Code: 0x${code.toString(16)}`;
}
}

@@ -10,0 +15,0 @@ }

@@ -5,2 +5,3 @@ "use strict";

const SearchFilter_1 = require("./SearchFilter");
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
class FilterParser {

@@ -12,4 +13,3 @@ static parseString(filterString) {

// Wrap input in parens if it wasn't already
if (filterString.charAt(0) !== '(') {
// tslint:disable-next-line:no-parameter-reassignment
if (!filterString.startsWith('(')) {
filterString = `(${filterString})`;

@@ -61,3 +61,3 @@ }

switch (type) {
case SearchFilter_1.SearchFilter.and:
case SearchFilter_1.SearchFilter.and: {
const andFilters = FilterParser._parseSet(reader);

@@ -68,2 +68,3 @@ filter = new filters_1.AndFilter({

break;
}
case SearchFilter_1.SearchFilter.approxMatch:

@@ -89,3 +90,3 @@ filter = new filters_1.ApproximateFilter();

break;
case SearchFilter_1.SearchFilter.not:
case SearchFilter_1.SearchFilter.not: {
const innerFilter = FilterParser.parse(reader);

@@ -96,3 +97,4 @@ filter = new filters_1.NotFilter({

break;
case SearchFilter_1.SearchFilter.or:
}
case SearchFilter_1.SearchFilter.or: {
const orFilters = FilterParser._parseSet(reader);

@@ -103,2 +105,3 @@ filter = new filters_1.OrFilter({

break;
}
case SearchFilter_1.SearchFilter.present:

@@ -119,3 +122,3 @@ filter = new filters_1.PresenceFilter();

let cursor = start;
const length = filterString.length;
const { length } = filterString;
let filter;

@@ -178,3 +181,3 @@ if (filterString[cursor] !== '(') {

let remainingExpression;
if (filterString[0] === ':') {
if (filterString.startsWith(':')) {
// An extensible filter can have no attribute name (Only valid when using dn and * matching-rule evaluation)

@@ -187,3 +190,3 @@ attribute = '';

if (matches && matches.length) {
attribute = matches[0];
[attribute] = matches;
remainingExpression = filterString.substr(attribute.length);

@@ -200,5 +203,5 @@ }

}
if (remainingExpression[0] === '=') {
if (remainingExpression.startsWith('=')) {
remainingExpression = remainingExpression.substr(1);
if (remainingExpression.indexOf('*') !== -1) {
if (remainingExpression.includes('*')) {
const escapedExpression = FilterParser._unescapeSubstring(remainingExpression);

@@ -217,3 +220,3 @@ return new filters_1.SubstringFilter({

}
if (remainingExpression[0] === '>' && remainingExpression[1] === '=') {
if (remainingExpression.startsWith('>') && remainingExpression[1] === '=') {
return new filters_1.GreaterThanEqualsFilter({

@@ -224,3 +227,3 @@ attribute,

}
if (remainingExpression[0] === '<' && remainingExpression[1] === '=') {
if (remainingExpression.startsWith('<') && remainingExpression[1] === '=') {
return new filters_1.LessThanEqualsFilter({

@@ -231,3 +234,3 @@ attribute,

}
if (remainingExpression[0] === '~' && remainingExpression[1] === '=') {
if (remainingExpression.startsWith('~') && remainingExpression[1] === '=') {
return new filters_1.ApproximateFilter({

@@ -238,3 +241,3 @@ attribute,

}
if (remainingExpression[0] === ':') {
if (remainingExpression.startsWith(':')) {
return FilterParser._parseExtensibleFilterFromString(attribute, remainingExpression);

@@ -257,6 +260,6 @@ }

}
if (fields.length && fields[0][0] !== '=') {
if (fields.length && !fields[0].startsWith('=')) {
rule = fields.shift();
}
if (fields.length && fields[0][0] !== '=') {
if (fields.length && !fields[0].startsWith('=')) {
throw new Error(`Missing := in extensible filter: ${filterString}`);

@@ -263,0 +266,0 @@ }

@@ -20,4 +20,5 @@ "use strict";

}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
matches(_ = {}, __) {
throw new Error(`Approximate match implementation unknown`);
throw new Error('Approximate match implementation unknown');
}

@@ -24,0 +25,0 @@ toString() {

@@ -53,4 +53,5 @@ "use strict";

}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
matches(_ = {}, __) {
throw new Error(`Approximate match implementation unknown`);
throw new Error('Approximate match implementation unknown');
}

@@ -57,0 +58,0 @@ toString() {

@@ -13,3 +13,2 @@ /// <reference types="node" />

* RFC 2254 Escaping of filter strings
*
* Raw Escaped

@@ -19,2 +18,4 @@ * (o=Parens (R Us)) (o=Parens \28R Us\29)

* (filename=C:\MyFile) (filename=C:\5cMyFile)
*
* @param {string|Buffer} input
*/

@@ -21,0 +22,0 @@ escape(input: string | Buffer): string;

@@ -12,2 +12,3 @@ "use strict";

}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
matches(_ = {}, __) {

@@ -18,3 +19,2 @@ return true;

* RFC 2254 Escaping of filter strings
*
* Raw Escaped

@@ -24,2 +24,4 @@ * (o=Parens (R Us)) (o=Parens \28R Us\29)

* (filename=C:\MyFile) (filename=C:\5cMyFile)
*
* @param {string|Buffer} input
*/

@@ -64,7 +66,9 @@ escape(input) {

}
// tslint:disable-next-line:no-empty
// eslint-disable-next-line @typescript-eslint/no-unused-vars
parseFilter(_) {
// Do nothing as the default action
}
// tslint:disable-next-line:no-empty
// eslint-disable-next-line @typescript-eslint/no-unused-vars
writeFilter(_) {
// Do nothing as the default action
}

@@ -71,0 +75,0 @@ getObjectValue(objectToCheck = {}, key, strictAttributeCase) {

@@ -16,4 +16,3 @@ "use strict";

writeFilter(writer) {
// tslint:disable-next-line:no-increment-decrement
for (let i = 0; i < this.attribute.length; i++) {
for (let i = 0; i < this.attribute.length; i += 1) {
writer.writeByte(this.attribute.charCodeAt(i));

@@ -20,0 +19,0 @@ }

@@ -15,3 +15,3 @@ "use strict";

static _escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
}

@@ -31,3 +31,3 @@ parseFilter(reader) {

break;
case 0x81:
case 0x81: {
let anyValue = reader.readString(tag);

@@ -39,2 +39,3 @@ if (this.attribute === 'objectclass') {

break;
}
case 0x82:

@@ -85,2 +86,3 @@ this.final = reader.readString(tag);

}
// eslint-disable-next-line security/detect-non-literal-regexp
const matcher = new RegExp(regexp, strictAttributeCase ? 'gmu' : 'igmu');

@@ -87,0 +89,0 @@ return matcher.test(objectToCheckValue);

@@ -126,3 +126,3 @@ "use strict";

break;
default:
default: {
const error = new errors_1.MessageParserError(`Protocol Operation not supported: 0x${protocolOperation.toString(16)}`);

@@ -134,2 +134,3 @@ error.messageDetails = {

throw error;
}
}

@@ -136,0 +137,0 @@ message.parse(reader);

@@ -10,5 +10,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const assert = __importStar(require("assert"));
const Message_1 = require("./Message");
const ProtocolOperation_1 = require("../ProtocolOperation");
const assert = __importStar(require("assert"));
class AbandonRequest extends Message_1.Message {

@@ -20,5 +20,5 @@ constructor(options) {

}
/* eslint-disable no-bitwise */
writeMessage(writer) {
// Encode abandon request using different ASN.1 integer logic
/* tslint:disable:no-bitwise no-increment-decrement */
let i = this.abandonId;

@@ -28,6 +28,7 @@ let intSize = 4;

while ((((i & mask) === 0) || ((i & mask) === mask)) && (intSize > 1)) {
intSize--;
intSize -= 1;
i <<= 8;
}
assert.ok(intSize <= 4);
// eslint-disable-next-line no-plusplus
while (intSize-- > 0) {

@@ -37,22 +38,25 @@ writer.writeByte((i & 0xff000000) >> 24);

}
/* tslint:enable:no-bitwise no-increment-decrement */
}
parseMessage(reader) {
const length = reader.length;
// Abandon request messages are encoded using different ASN.1 integer logic, forcing custom decoding logic
let offset = 0;
let value;
/* tslint:disable:no-bitwise no-increment-decrement */
const fb = reader.buffer[offset++];
value = fb & 0x7F;
for (let i = 1; i < length; i++) {
value <<= 8;
value |= (reader.buffer[offset++] & 0xff);
const { length } = reader;
if (length) {
// Abandon request messages are encoded using different ASN.1 integer logic, forcing custom decoding logic
let offset = 1;
let value;
const fb = reader.buffer[offset];
value = fb & 0x7F;
for (let i = 1; i < length; i += 1) {
value <<= 8;
offset += 1;
value |= (reader.buffer[offset] & 0xff);
}
if ((fb & 0x80) === 0x80) {
value = -value;
}
reader._offset += length;
this.abandonId = value;
}
if ((fb & 0x80) === 0x80) {
value = -value;
else {
this.abandonId = 0;
}
/* tslint:enable:no-bitwise no-increment-decrement */
reader._offset += length;
this.abandonId = value;
}

@@ -59,0 +63,0 @@ }

@@ -18,3 +18,3 @@ "use strict";

parseMessage(reader) {
const length = reader.length;
const { length } = reader;
this.dn = reader.buffer.slice(0, length).toString('utf8');

@@ -21,0 +21,0 @@ reader._offset += reader.length;

@@ -25,5 +25,2 @@ "use strict";

}
this.status = reader.readEnumeration();
this.matchedDN = reader.readString();
this.errorMessage = reader.readString();
}

@@ -30,0 +27,0 @@ }

@@ -50,7 +50,9 @@ "use strict";

}
// tslint:disable-next-line:no-empty
// eslint-disable-next-line @typescript-eslint/no-unused-vars
parseMessage(_) {
// Do nothing as the default action
}
// tslint:disable-next-line:no-empty
// eslint-disable-next-line @typescript-eslint/no-unused-vars
writeMessage(_) {
// Do nothing as the default action
}

@@ -57,0 +59,0 @@ }

@@ -30,2 +30,3 @@ "use strict";

if (attribute.values.length === 1) {
// eslint-disable-next-line prefer-destructuring
result[attribute.type] = attribute.values[0];

@@ -32,0 +33,0 @@ }

{
"name": "ldapts",
"version": "1.10.0",
"version": "2.0.0",
"description": "LDAP client",

@@ -10,9 +10,17 @@ "main": "index.js",

"test": "mocha -r ts-node/register tests/*.tests.ts tests/**/*.tests.ts",
"lint": "tslint --fix -p tsconfig.lint.json -c tslint.json -t stylish",
"lint": "eslint --fix --ext .ts src tests",
"dist": "if [ -d \"src\" ]; then rm -rf dist && npm run lint && npm run build && npm run test && cp package.json dist && cp *.md dist && cp .npmignore dist && cd dist && npm publish; fi",
"prepublishOnly": "if [ -d \"src\" ]; then echo \"Please use: npm run dist\" && exit 125; fi"
},
"lint-staged": {
"*.js": [
"eslint --fix"
],
"*.ts": [
"eslint --fix"
]
},
"husky": {
"hooks": {
"pre-commit": "npm run lint"
"pre-commit": "lint-staged"
}

@@ -25,3 +33,3 @@ },

"engines": {
"node": ">=8.11"
"node": ">=10"
},

@@ -41,3 +49,3 @@ "keywords": [

"@types/asn1": "~0.2.0",
"@types/node": "~8.10.54",
"@types/node": "~10.17.9",
"asn1": "~0.2.4",

@@ -48,16 +56,24 @@ "debug": "~4.1.1",

"devDependencies": {
"@types/chai": "~4.2.3",
"@types/chai": "~4.2.7",
"@types/chai-as-promised": "~7.1.2",
"@types/debug": "~4.1.5",
"@types/mocha": "~5.2.6",
"@typescript-eslint/eslint-plugin": "~2.12.0",
"@typescript-eslint/parser": "~2.12.0",
"chai": "~4.2.0",
"chai-as-promised": "~7.1.1",
"husky": "~3.0.5",
"mocha": "~6.2.0",
"eslint": "~6.7.1",
"eslint-config-airbnb-base": "~14.0.0",
"eslint-plugin-import": "~2.19.1",
"eslint-plugin-jsdoc": "~18.4.3",
"eslint-plugin-mocha": "~6.2.2",
"eslint-plugin-promise": "~4.2.1",
"eslint-plugin-security": "~1.4.0",
"husky": "~3.1.0",
"lint-staged": "9.5.0",
"mocha": "~6.2.2",
"ts-mockito": "~2.5.0",
"ts-node": "~8.4.1",
"tslint": "~5.20.0",
"tslint-config-airbnb": "~5.11.2",
"typescript": "~3.6.3"
"ts-node": "~8.5.4",
"typescript": "~3.7.3"
}
}

@@ -10,7 +10,321 @@ LDAPts

## Usage Examples
### Table of Contents
* [API Details](#api-details)
* [Create a client](#create-a-client)
* [bind](#bind)
* [add](#add)
* [compare](#compare)
* [del](#del)
* [exop](#exop)
* [modify](#modify)
* [Change](#change)
* [modifyDN](#modifydn)
* [search](#search)
* [Filter Strings](#filter-strings)
* [unbind](#unbind)
* [Usage Examples](#usage-examples)
* [Authenticate example](#authenticate-example)
* [Search example](#search-example)
* [Delete Active Directory entry example](#delete-active-directory-entry-example)
### Authenticate
# API details
## Create a client
The code to create a new client looks like:
```javascript
import { Client } from 'ldapts';
const client = new Client({
url: 'ldaps://ldap.jumpcloud.com',
timeout: 0,
connectTimeout: 0,
tlsOptions: {
minVersion: 'TLSv1.2',
},
strictDN: true,
});
```
You can use `ldap://` or `ldaps://`; the latter would connect over SSL (note
that this will not use the LDAP TLS extended operation, but literally an SSL
connection to port 636, as in LDAP v2). The full set of options to create a
client is:
|Attribute |Description |
|---------------|-----------------------------------------------------------|
|url |A valid LDAP URL (proto/host/port only) |
|timeout |Milliseconds client should let operations live for before timing out (Default: Infinity)|
|connectTimeout |Milliseconds client should wait before timing out on TCP connections (Default: OS default)|
|tlsOptions |TLS [connect() options](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback)|
|strictDN |Force strict DN parsing for client methods (Default is true)|
## bind
`bind(dn, password, [controls])`
Performs a bind operation against the LDAP server.
The bind API only allows LDAP 'simple' binds (equivalent to HTTP Basic
Authentication) for now. Note that all client APIs can optionally take a single `Control` object or array
of `Control` objects. You probably don't need them though...
Arguments:
`dn (string)`: The name (DN) of the directory object that the client wishes to bind as
`password (string)`: Password for the target bind DN
`[controls] (Control|Control[])`: Optional `Control` object or array of `Control` objects
Example:
await client.bind('cn=root', 'secret');
## add
`add(dn, entry, [controls])`
Performs an add operation against the LDAP server.
Allows you to add an entry (as a js object or array of Attributes), and as always,
controls are optional.
Arguments:
`dn (string)`: The DN of the entry to add
`entry (object|Attribute[])`: The set of attributes to include in that entry
`[controls] (Control|Control[])`: Optional `Control` object or array of `Control` objects
Example:
var entry = {
cn: 'foo',
sn: 'bar',
email: ['foo@bar.com', 'foo1@bar.com'],
objectclass: 'fooPerson'
};
await client.add('cn=foo, o=example', entry);
## compare
`compare(dn, attribute, value, [controls])`
Performs an LDAP compare operation with the given attribute and value against
the entry referenced by dn.
Arguments:
`dn (string)`: The DN of the entry in which the comparison is to be made
`attribute (string)`: The Name of the attribute in which the comparison is to be made
`value (string)`: The Attribute Value Assertion to try to find in the specified attribute
`[controls] (Control|Control[])`: Optional `Control` object or array of `Control` objects
Returns:
`(boolean)`: Returns `true` if the target entry exists and does contain the specified attribute value; otherwise `false`
Example:
const hasValue = await client.compare('cn=foo, o=example', 'sn', 'bar');
## del
`del(dn, [controls])`
Deletes an entry from the LDAP server.
Arguments:
`dn (string)`: The DN of the entry to delete
`[controls] (Control|Control[])`: Optional `Control` object or array of `Control` objects
Example:
await client.del('cn=foo, o=example');
## exop
`exop(oid, [value], [controls])`
Performs an LDAP extended operation against an LDAP server.
Arguments:
`oid (string)`: Object identifier representing the type of request
`[value] (string)`: Optional value - based on the type of operation
`[controls] (Control|Control[])`: Optional `Control` object or array of `Control` objects
Example (performs an LDAP 'whois' extended op):
const { value } = await client.exop('1.3.6.1.4.1.4203.1.11.3');
## modify
`modify(name, changes, [controls])`
Performs an LDAP modify operation against the LDAP server. This API requires
you to pass in a `Change` object, which is described below. Note that you can
pass in a single `Change` or an array of `Change` objects.
Arguments:
`dn (string)`: The DN of the entry to modify
`changes (Change|Change[])`: The set of changes to make to the entry
`[controls] (Control|Control[])`: Optional `Control` object or array of `Control` objects
Example (update multiple attributes):
import { Attribute, Change } from 'ldapts';
await client.modify('cn=foo, o=example', [
new Change({ operation: 'replace', modification: new Attribute({ type: 'title', values: ['web tester'] })),
new Change({ operation: 'replace', modification: new Attribute({ type: 'displayName', values: ['John W Doe'] })),
]);
Example (update binary attribute):
import { Attribute, Change } from 'ldapts';
const thumbnailPhotoBuffer = await fs.readFile(path.join(__dirname, './groot_100.jpg'));
var change = new Change({
operation: 'replace',
modification: new Attribute({
type: 'thumbnailPhoto;binary',
values: [thumbnailPhotoBuffer]
}),
});
await client.modify('cn=foo, o=example', change);
### Change
`Change({ operation, modification })`
A `Change` object maps to the LDAP protocol of a modify change, and requires you
to set the `operation` and `modification`. The `operation` is a string, and
must be one of:
||replace||Replaces the attribute referenced in `modification`. If the modification has no values, it is equivalent to a delete.||
||add||Adds the attribute value(s) referenced in `modification`. The attribute may or may not already exist.||
||delete||Deletes the attribute (and all values) referenced in `modification`.||
Arguments:
`operation (replace|add|delete)`:
| Value | Description
| --------- | ------------
| `replace` |Replaces the attribute referenced in `modification`. If the modification has no values, it is equivalent to a delete.|
| `add` |Adds the attribute value(s) referenced in `modification`. The attribute may or may not already exist.|
| `delete` |Deletes the attribute (and all values) referenced in `modification`.|
`modification (Attribute)`: Attribute details to add, remove, or update
## modifyDN
`modifyDN(dn, newDN, [controls])`
Performs an LDAP modifyDN (rename) operation against an entry in the LDAP
server. A couple points with this client API:
* There is no ability to set "keep old dn." It's always going to flag the old
dn to be purged.
* The client code will automatically figure out if the request is a "new
superior" request ("new superior" means move to a different part of the tree,
as opposed to just renaming the leaf).
Arguments:
`dn (string)`: The DN of the entry to rename
`newDN (string)`: The new RDN to use assign to the entry. It may be the same as the current RDN if you only intend to move the entry beneath a new parent. If the new RDN includes any attribute values that aren’t already in the entry, the entry will be updated to include them.
`[controls] (Control|Control[])`: Optional `Control` object or array of `Control` objects
Example:
await client.modifyDN('cn=foo, o=example', 'cn=bar');
## search
`search(baseDN, options, [controls])`
Performs a search operation against the LDAP server.
The search operation is more complex than the other operations, so this one
takes an `options` object for all the parameters.
Arguments:
`baseDN (string)`: The base of the subtree in which the search is to be constrained
`options (object)`:
|Attribute |Description
|-----------------------------------------------|---------------------------------------------------|
|[scope=sub] (string) |<ul><li>`base` - Indicates that only the entry specified as the search base should be considered. None of its subordinates will be considered.</li><li>`one` - Indicates that only the immediate children of the entry specified as the search base should be considered. The base entry itself should not be considered, nor any descendants of the immediate children of the base entry.</li><li>`sub` - Indicates that the entry specified as the search base, and all of its subordinates to any depth, should be considered.</li><li>`children` - Indicates that the entry specified by the search base should not be considered, but all of its subordinates to any depth should be considered.</li></ul>
|[filter=(objectclass=*)] (string&#124;Filter) |The filter of the search request. It must conform to the LDAP filter syntax specified in RFC4515
|[derefAliases=never] (string) |<ul><li>`never` - Never dereferences entries, returns alias objects instead. The alias contains the reference to the real entry.</li><li>`always` - Always returns the referenced entries, not the alias object.</li><li>`search` - While searching subordinates of the base object, dereferences any alias within the search scope. Dereferenced objects become the bases of further search scopes where the Search operation is also applied by the server. The server should eliminate duplicate entries that arise due to alias dereferencing while searching.</li><li>`find` - Dereferences aliases in locating the base object of the search, but not when searching subordinates of the base object.</li></ul>
|[returnAttributeValues=true] (boolean) |If true, attribute values should be included in the entries that are returned; otherwise entries that match the search criteria should be returned containing only the attribute descriptions for the attributes contained in that entry but should not include the values for those attributes.
|[sizeLimit=0] (number) |The maximum number of entries that should be returned from the search. A value of zero indicates no limit. Note that the server may also impose a size limit for the search operation, and in that case the smaller of the client-requested and server-imposed size limits will be enforced.
|[timeLimit=10] (number) |The maximum length of time, in seconds, that the server should spend processing the search. A value of zero indicates no limit. Note that the server may also impose a time limit for the search operation, and in that case the smaller of the client-requested and server-imposed time limits will be enforced.
|[paged=false] (boolean&#124;SearchPageOptions) |Used to allow paging and specify the page size
|[attributes=] (string[]) |A set of attributes to request for inclusion in entries that match the search criteria and are returned to the client. If a specific set of attribute descriptions are listed, then only those attributes should be included in matching entries. The special value “*” indicates that all user attributes should be included in matching entries. The special value “+” indicates that all operational attributes should be included in matching entries. The special value “1.1” indicates that no attributes should be included in matching entries. Some servers may also support the ability to use the “@” symbol followed by an object class name (e.g., “@inetOrgPerson”) to request all attributes associated with that object class. If the set of attributes to request is empty, then the server should behave as if the value “*” was specified to request that all user attributes be included in entries that are returned.
`[controls] (Control|Control[])`: Optional `Control` object or array of `Control` objects
Example:
const {
searchEntries,
searchReferences,
} = await client.search(searchDN, {
filter: '(mail=peter.parker@marvel.com)',
});
Please see [Client tests](https://github.com/ldapts/ldapts/blob/master/tests/Client.tests.ts) for more search examples
### Filter Strings
The easiest way to write search filters is to write them compliant with RFC2254,
which is "The string representation of LDAP search filters."
Assuming you don't really want to read the RFC, search filters in LDAP are
basically are a "tree" of attribute/value assertions, with the tree specified
in prefix notation. For example, let's start simple, and build up a complicated
filter. The most basic filter is equality, so let's assume you want to search
for an attribute `email` with a value of `foo@bar.com`. The syntax would be:
(email=foo@bar.com)
ldapts requires all filters to be surrounded by '()' blocks. Ok, that was easy.
Let's now assume that you want to find all records where the email is actually
just anything in the "@bar.com" domain and the location attribute is set to
Seattle:
(&(email=*@bar.com)(l=Seattle))
Now our filter is actually three LDAP filters. We have an `and` filter (single
amp `&`), an `equality` filter `(the l=Seattle)`, and a `substring` filter.
Substrings are wildcard filters. They use `*` as the wildcard. You can put more
than one wildcard for a given string. For example you could do `(email=*@*bar.com)`
to match any email of @bar.com or its subdomains like "example@foo.bar.com".
Now, let's say we also want to set our filter to include a
specification that either the employeeType *not* be a manager nor a secretary:
(&(email=*@bar.com)(l=Seattle)(!(|(employeeType=manager)(employeeType=secretary))))
The `not` character is represented as a `!`, the `or` as a single pipe `|`.
It gets a little bit complicated, but it's actually quite powerful, and lets you
find almost anything you're looking for.
## unbind
`unbind()`
Used to indicate that the client wants to close the connection to the directory server.
Example:
await client.unbind();
# Usage Examples
## Authenticate example
```javascript
const { Client } = require('ldapts');

@@ -38,3 +352,3 @@

### Search
## Search example

@@ -74,3 +388,3 @@ ```javascript

### Delete Active Directory entry
## Delete Active Directory entry example

@@ -77,0 +391,0 @@ ```javascript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const resultCodeErrors_1 = require("./errors/resultCodeErrors");
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
class StatusCodeParser {

@@ -5,0 +6,0 @@ static parse(code, message) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc