Compare commits

..

39 Commits

Author SHA1 Message Date
James Sumners 8ffd0bc9c1
Add decommission note 2024-05-14 18:10:45 -04:00
James Sumners b86c493e7b
v3.0.7 2023-12-01 09:20:59 -05:00
Varun Patil 9c6142dbbf server: prevent crash on blank DN bind 2023-12-01 09:20:32 -05:00
James Sumners 6ceef13014
v3.0.6 2023-11-10 07:13:39 -05:00
its-sami a433489e98
Add integration test for PasswordPolicyControl (#949) 2023-11-10 07:12:57 -05:00
James Sumners bec2ff8e73 Add test for issue 940 2023-08-30 10:08:26 -04:00
James Sumners 6a676364ed
v3.0.5 2023-08-16 12:46:31 -04:00
James Sumners 971f1bbc3b Resolve issue #860 2023-08-16 12:45:52 -04:00
James Sumners 7b869f4a9d Resolve issue #924 2023-08-15 09:04:46 -04:00
James Sumners ac588a0fad Add integration test for issue #923 2023-08-04 12:36:59 -04:00
James Sumners 1cc6a733ba
v3.0.4 2023-07-22 15:43:21 -04:00
Niklas Mischkulnig 0fcad2443d
Fix ensureDN (#918) 2023-07-22 15:42:51 -04:00
James Sumners 3c7b7cbedf
v3.0.3 2023-07-04 08:57:20 -04:00
James Sumners 1fe60e48c3 Update minimum dependencies 2023-07-04 08:55:39 -04:00
James Sumners e2d516f6bb Address crash for unmatched server responses 2023-07-04 07:31:17 -04:00
Mihir Bhansali 70ce9c3643
update modification object in ldap.change (#910)
* updated the modification object in ldap.change

* Adding Change Interface

* Modification reference table
2023-06-28 07:30:30 -04:00
dependabot[bot] f2890088e4 build(deps-dev): bump eslint from 8.41.0 to 8.42.0
Bumps [eslint](https://github.com/eslint/eslint) from 8.41.0 to 8.42.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.41.0...v8.42.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-03 07:23:07 -04:00
dependabot[bot] 6bd92a74ec build(deps-dev): bump eslint from 8.40.0 to 8.41.0
Bumps [eslint](https://github.com/eslint/eslint) from 8.40.0 to 8.41.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.40.0...v8.41.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-20 08:22:07 -04:00
dependabot[bot] 830659ff93 build(deps-dev): bump eslint-plugin-n from 15.7.0 to 16.0.0
Bumps [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) from 15.7.0 to 16.0.0.
- [Release notes](https://github.com/eslint-community/eslint-plugin-n/releases)
- [Commits](https://github.com/eslint-community/eslint-plugin-n/compare/15.7.0...16.0.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-n
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-20 08:18:26 -04:00
James Sumners 0558c1a6cb Add test for issue #883 2023-05-18 08:32:23 -04:00
James Sumners bdaaf29d5a Add test for issue #885 2023-05-16 14:01:46 -04:00
dependabot[bot] a37daf168a build(deps-dev): bump eslint from 8.39.0 to 8.40.0
Bumps [eslint](https://github.com/eslint/eslint) from 8.39.0 to 8.40.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.39.0...v8.40.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-06 15:29:16 -04:00
dependabot[bot] 29ddc4db06 build(deps): bump @ldapjs/dn from 1.0.0 to 1.1.0
Bumps [@ldapjs/dn](https://github.com/ldapjs/dn) from 1.0.0 to 1.1.0.
- [Release notes](https://github.com/ldapjs/dn/releases)
- [Commits](https://github.com/ldapjs/dn/compare/v1.0.0...v1.1.0)

---
updated-dependencies:
- dependency-name: "@ldapjs/dn"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-29 07:49:26 -04:00
dependabot[bot] 7fc99fd721 build(deps): bump @ldapjs/messages from 1.0.2 to 1.1.0
Bumps [@ldapjs/messages](https://github.com/ldapjs/messages) from 1.0.2 to 1.1.0.
- [Release notes](https://github.com/ldapjs/messages/releases)
- [Commits](https://github.com/ldapjs/messages/compare/v1.0.2...v1.1.0)

---
updated-dependencies:
- dependency-name: "@ldapjs/messages"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-22 07:37:29 -04:00
dependabot[bot] 2363ec77c0 build(deps-dev): bump eslint from 8.38.0 to 8.39.0
Bumps [eslint](https://github.com/eslint/eslint) from 8.38.0 to 8.39.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.38.0...v8.39.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-22 07:29:45 -04:00
dependabot[bot] 2bb8985ada build(deps-dev): bump eslint from 8.37.0 to 8.38.0
Bumps [eslint](https://github.com/eslint/eslint) from 8.37.0 to 8.38.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.37.0...v8.38.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-08 08:28:18 -04:00
dependabot[bot] 65a519e203 build(deps-dev): bump eslint from 8.36.0 to 8.37.0
Bumps [eslint](https://github.com/eslint/eslint) from 8.36.0 to 8.37.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.36.0...v8.37.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-01 08:10:31 -04:00
James Sumners 49add89fa0
v3.0.2 2023-03-28 10:34:30 -04:00
Axel Kittenberger cfba105ecd cross-realm type checks in search 2023-03-28 10:34:04 -04:00
Axel Kittenberger 78014a2ea3 transcontextual safe type checks 2023-03-28 10:34:04 -04:00
Axel Kittenberger e2c0949dd5 transcontextual safe type checks 2023-03-28 10:34:04 -04:00
James Sumners 8c58f462fc Add test for issue 860
This PR adds a new integration test for issue #860.
2023-03-27 09:57:55 -04:00
dependabot[bot] 9613308c33 build(deps): bump @ldapjs/messages from 1.0.1 to 1.0.2
Bumps [@ldapjs/messages](https://github.com/ldapjs/messages) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/ldapjs/messages/releases)
- [Commits](https://github.com/ldapjs/messages/compare/v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: "@ldapjs/messages"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-11 08:55:04 -05:00
dependabot[bot] 7991a37c2c build(deps-dev): bump eslint from 8.35.0 to 8.36.0
Bumps [eslint](https://github.com/eslint/eslint) from 8.35.0 to 8.36.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.35.0...v8.36.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-11 08:27:46 -05:00
James Sumners 5c6c5dce78
v3.0.1 2023-03-08 17:27:13 -05:00
James Sumners 98b91de01a Add Node.js version support to readme 2023-03-08 17:25:16 -05:00
James Sumners 824dd2cb57 Resolve issue #845
This issue resolves issue #845 by updating `@ldapjs/messages` to the
latest version and adding a test that shows how the module should be
used to evaluate search request scopes.
2023-03-08 17:11:44 -05:00
Joakim Uddholm 0dfe40e209 Quick fix for outdated client doc
Still referring to result.object, instead of result.pojo.
2023-03-07 16:09:06 -05:00
dependabot[bot] 6ba15ed672 build(deps-dev): bump eslint from 8.34.0 to 8.35.0
Bumps [eslint](https://github.com/eslint/eslint) from 8.34.0 to 8.35.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.34.0...v8.35.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-04 08:14:42 -05:00
20 changed files with 831 additions and 75 deletions

View File

@ -20,10 +20,12 @@ jobs:
services: services:
openldap: openldap:
image: ghcr.io/ldapjs/docker-test-openldap/openldap:latest image: ghcr.io/ldapjs/docker-test-openldap/openldap:2023-10-30
ports: ports:
- 389:389 - 389:389
- 636:636 - 636:636
options: >
--health-cmd "ldapsearch -Y EXTERNAL -Q -H ldapi:// -b ou=people,dc=planetexpress,dc=com -LLL '(cn=Turanga Leela)' cn"
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

View File

@ -34,7 +34,7 @@ jobs:
node: node:
- 16 - 16
- 18 - 18
- 19 - 20
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

View File

@ -1,52 +1,34 @@
# LDAPjs # Project Decomissioned
[![Build Status](https://github.com/ldapjs/node-ldapjs/workflows/Lint%20And%20Test/badge.svg)](https://github.com/ldapjs/node-ldapjs/actions) This project has been decomissioned. I, James Sumners, took it on when it was
[![Coverage Status](https://coveralls.io/repos/github/ldapjs/node-ldapjs/badge.svg)](https://coveralls.io/github/ldapjs/node-ldapjs/) languishing without any maintenance as it filled a need in the ecosystem and
I had built things at a prior organization that depended upon this project.
I spent a lot of time triaging issues and reworking things toward a path
that could be more easily maintained by a community of volunteers. But I have
not had the time to dedicate to this project in quite a while. There are
outstanding issues that would take me at least a week of dedicated development
time to solve, and I cannot afford to take time off of work to do that.
Particularly considering that the aforementioned organization was two
jobs ago, and it is extremely unlikely that I will transition to a role again
that will need this project.
LDAPjs makes the LDAP protocol a first class citizen in Node.js. So, why am I just now deciding to decomission this project? Because today,
2024-05-14, I received the following email:
## Usage ![Abusive email](dt.png)
For full docs, head on over to <http://ldapjs.org>. I will not tolerate abuse, and I especially will not tolerate tacit death
threats, over a hobby. You can thank the author of that email for the
decomissioning on this project.
```javascript My recommendation to you in regard to LDAP operations: write a gateway in a
var ldap = require('ldapjs'); language that is more suited to these types of operations. I'd suggest
[Go](https://go.dev).
var server = ldap.createServer(); 👋
server.search('dc=example', function(req, res, next) { P.S.: if I ever do need this project again, I might revive it. But I'd fight
var obj = { hard for my suggestion above. Also, I will consider turning it over to an
dn: req.dn.toString(), interested party, but I will require at least one recommendation from a
attributes: { Node.js core contributor that I can vet with the people that I know on that
objectclass: ['organization', 'top'], team.
o: 'example'
}
};
if (req.filter.matches(obj.attributes))
res.send(obj);
res.end();
});
server.listen(1389, function() {
console.log('ldapjs listening at ' + server.url);
});
```
To run that, assuming you've got the [OpenLDAP](http://www.openldap.org/)
client on your system:
ldapsearch -H ldap://localhost:1389 -x -b dc=example objectclass=*
## Installation
npm install ldapjs
## License
MIT.
## Bugs
See <https://github.com/ldapjs/node-ldapjs/issues>.

View File

@ -1,8 +1,10 @@
version: '3'
services: services:
openldap: openldap:
image: ghcr.io/ldapjs/docker-test-openldap/openldap:latest image: ghcr.io/ldapjs/docker-test-openldap/openldap:2023-10-30
ports: ports:
- 389:389 - 389:389
- 636:636 - 636:636
healthcheck:
start_period: 3s
test: >
/usr/bin/ldapsearch -Y EXTERNAL -Q -H ldapi:// -b ou=people,dc=planetexpress,dc=com -LLL '(cn=Turanga Leela)' cn 1>/dev/null

View File

@ -213,7 +213,8 @@ Example:
const change = new ldap.Change({ const change = new ldap.Change({
operation: 'add', operation: 'add',
modification: { modification: {
pets: ['cat', 'dog'] type: 'pets',
values: ['cat', 'dog']
} }
}); });
@ -234,7 +235,13 @@ must be one of:
| add | Adds the attribute value(s) referenced in `modification`. The attribute may or may not already exist. | | 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`. | | delete | Deletes the attribute (and all values) referenced in `modification`. |
`modification` is just a plain old JS object with the values you want. `modification` is just a plain old JS object with the required type and values you want.
| Operation | Description |
|-----------|-------------|
| type | String that defines the attribute type for the modification. |
| values | Defines the values for modification. |
# modifyDN # modifyDN
`modifyDN(dn, newDN, controls, callback)` `modifyDN(dn, newDN, controls, callback)`
@ -308,7 +315,7 @@ client.search('o=example', opts, (err, res) => {
console.log('searchRequest: ', searchRequest.messageId); console.log('searchRequest: ', searchRequest.messageId);
}); });
res.on('searchEntry', (entry) => { res.on('searchEntry', (entry) => {
console.log('entry: ' + JSON.stringify(entry.object)); console.log('entry: ' + JSON.stringify(entry.pojo));
}); });
res.on('searchReference', (referral) => { res.on('searchReference', (referral) => {
console.log('referral: ' + referral.uris.join()); console.log('referral: ' + referral.uris.join());

BIN
dt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

View File

@ -80,7 +80,7 @@ function validateControls (controls) {
function ensureDN (input) { function ensureDN (input) {
if (DN.isDn(input)) { if (DN.isDn(input)) {
return DN return input
} else if (typeof (input) === 'string') { } else if (typeof (input) === 'string') {
return DN.fromString(input) return DN.fromString(input)
} else { } else {
@ -881,7 +881,13 @@ Client.prototype.connect = function connect () {
// object. // object.
tracker.parser.on('message', function onMessage (message) { tracker.parser.on('message', function onMessage (message) {
message.connection = self._socket message.connection = self._socket
const { message: trackedMessage, callback } = tracker.fetch(message.messageId) const trackedObject = tracker.fetch(message.messageId)
if (!trackedObject) {
log.error({ message: message.pojo }, 'unmatched server message received')
return false
}
const { message: trackedMessage, callback } = trackedObject
if (!callback) { if (!callback) {
log.error({ message: message.pojo }, 'unsolicited message') log.error({ message: message.pojo }, 'unsolicited message')

View File

@ -47,15 +47,15 @@ function mergeFunctionArgs (argv, start, end) {
const handlers = [] const handlers = []
for (let i = start; i < end; i++) { for (let i = start; i < end; i++) {
if (argv[i] instanceof Array) { if (Array.isArray(argv[i])) {
const arr = argv[i] const arr = argv[i]
for (let j = 0; j < arr.length; j++) { for (let j = 0; j < arr.length; j++) {
if (!(arr[j] instanceof Function)) { if (typeof arr[j] !== 'function') {
throw new TypeError('Invalid argument type: ' + typeof (arr[j])) throw new TypeError('Invalid argument type: ' + typeof (arr[j]))
} }
handlers.push(arr[j]) handlers.push(arr[j])
} }
} else if (argv[i] instanceof Function) { } else if (typeof argv[i] === 'function') {
handlers.push(argv[i]) handlers.push(argv[i])
} else { } else {
throw new TypeError('Invalid argument type: ' + typeof (argv[i])) throw new TypeError('Invalid argument type: ' + typeof (argv[i]))
@ -854,11 +854,11 @@ Server.prototype._getHandlerChain = function _getHandlerChain (req) {
} }
// Otherwise, match via DN rules // Otherwise, match via DN rules
assert.ok(req.dn)
const keys = this._sortedRouteKeys() const keys = this._sortedRouteKeys()
let fallbackHandler = [noSuffixHandler] let fallbackHandler = [noSuffixHandler]
// invalid DNs in non-strict mode are routed to the default handler // invalid DNs in non-strict mode are routed to the default handler
const testDN = (typeof (req.dn) === 'string') ? DN.fromString(req.dn) : req.dn const testDN = (typeof (req.dn) === 'string') ? DN.fromString(req.dn) : req.dn
assert.ok(testDN)
for (let i = 0; i < keys.length; i++) { for (let i = 0; i < keys.length; i++) {
const suffix = keys[i] const suffix = keys[i]

View File

@ -3,7 +3,7 @@
"name": "ldapjs", "name": "ldapjs",
"homepage": "http://ldapjs.org", "homepage": "http://ldapjs.org",
"description": "LDAP client and server APIs", "description": "LDAP client and server APIs",
"version": "3.0.0", "version": "3.0.7",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",
@ -11,13 +11,13 @@
}, },
"main": "lib/index.js", "main": "lib/index.js",
"dependencies": { "dependencies": {
"@ldapjs/asn1": "2.0.0", "@ldapjs/asn1": "^2.0.0",
"@ldapjs/attribute": "1.0.0", "@ldapjs/attribute": "^1.0.0",
"@ldapjs/change": "1.0.0", "@ldapjs/change": "^1.0.0",
"@ldapjs/controls": "2.0.0", "@ldapjs/controls": "^2.1.0",
"@ldapjs/dn": "1.0.0", "@ldapjs/dn": "^1.1.0",
"@ldapjs/filter": "2.0.0", "@ldapjs/filter": "^2.1.1",
"@ldapjs/messages": "1.0.0", "@ldapjs/messages": "^1.3.0",
"@ldapjs/protocol": "^1.2.1", "@ldapjs/protocol": "^1.2.1",
"abstract-logging": "^2.0.1", "abstract-logging": "^2.0.1",
"assert-plus": "^1.0.0", "assert-plus": "^1.0.0",
@ -28,17 +28,17 @@
}, },
"devDependencies": { "devDependencies": {
"@fastify/pre-commit": "^2.0.2", "@fastify/pre-commit": "^2.0.2",
"eslint": "8.34.0", "eslint": "^8.44.0",
"eslint-config-standard": "^17.0.0", "eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.27.5", "eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1", "eslint-plugin-n": "^16.0.0",
"eslint-plugin-node": "^11.1.0", "eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "6.1.1", "eslint-plugin-promise": "6.1.1",
"front-matter": "^4.0.2", "front-matter": "^4.0.2",
"get-port": "^5.1.1", "get-port": "^5.1.1",
"highlight.js": "^11.7.0", "highlight.js": "^11.7.0",
"marked": "^4.2.12", "marked": "^4.2.12",
"tap": "16.3.4" "tap": "^16.3.7"
}, },
"scripts": { "scripts": {
"test": "tap --no-cov -R terse", "test": "tap --no-cov -R terse",
@ -47,7 +47,7 @@
"test:cov:html": "tap --coverage-report=html -R terse", "test:cov:html": "tap --coverage-report=html -R terse",
"test:watch": "tap -n -w --no-coverage-report -R terse", "test:watch": "tap -n -w --no-coverage-report -R terse",
"test:integration": "tap --no-cov -R terse 'test-integration/**/*.test.js'", "test:integration": "tap --no-cov -R terse 'test-integration/**/*.test.js'",
"test:integration:local": "docker-compose up -d && npm run test:integration && docker-compose down", "test:integration:local": "docker-compose up -d --wait && npm run test:integration ; docker-compose down",
"lint": "eslint . --fix", "lint": "eslint . --fix",
"lint:ci": "eslint .", "lint:ci": "eslint .",
"docs": "node scripts/build-docs.js" "docs": "node scripts/build-docs.js"

View File

@ -0,0 +1,95 @@
'use strict'
const tap = require('tap')
const ldapjs = require('../../lib')
const parseDN = ldapjs.parseDN
const SCHEME = process.env.SCHEME || 'ldap'
const HOST = process.env.HOST || '127.0.0.1'
const PORT = process.env.PORT || 389
const baseURL = `${SCHEME}://${HOST}:${PORT}`
const client = ldapjs.createClient({ url: baseURL })
tap.before(() => {
return new Promise((resolve, reject) => {
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', (err) => {
if (err) {
return reject(err)
}
resolve()
})
})
})
tap.teardown(() => {
client.unbind()
})
tap.test('can search OUs with Japanese characters', t => {
t.plan(2)
const opts = {
filter: '(&(objectClass=person))',
scope: 'sub',
paged: true,
sizeLimit: 100,
attributes: ['cn', 'employeeID']
}
const baseDN = parseDN('ou=テスト,dc=planetexpress,dc=com')
client.search(baseDN.toString(), opts, (err, res) => {
t.error(err, 'search error')
res.on('searchEntry', (entry) => {
t.match(entry.pojo, {
type: 'SearchResultEntry',
objectName: 'cn=jdoe,ou=\\e3\\83\\86\\e3\\82\\b9\\e3\\83\\88,dc=planetexpress,dc=com',
attributes: [{
type: 'cn',
values: ['John', 'jdoe']
}]
})
})
res.on('error', (err) => {
t.error(err, 'search entry error')
})
res.on('end', () => {
t.end()
})
})
})
tap.test('can search with non-ascii chars in filter', t => {
t.plan(3)
const opts = {
filter: '(&(sn=Rodríguez))',
scope: 'sub',
attributes: ['dn', 'sn', 'cn'],
type: 'user'
}
let searchEntryCount = 0
client.search('dc=planetexpress,dc=com', opts, (err, res) => {
t.error(err, 'search error')
res.on('searchEntry', (entry) => {
searchEntryCount += 1
t.match(entry.pojo, {
type: 'SearchResultEntry',
objectName: 'cn=Bender Bending Rodr\\c3\\adguez,ou=people,dc=planetexpress,dc=com',
attributes: [{
type: 'cn',
values: ['Bender Bending Rodríguez']
}]
})
})
res.on('error', (err) => {
t.error(err, 'search entry error')
})
res.on('end', () => {
t.equal(searchEntryCount, 1, 'should have found 1 entry')
t.end()
})
})
})

View File

@ -0,0 +1,56 @@
'use strict'
const tap = require('tap')
const ldapjs = require('../../lib')
const SCHEME = process.env.SCHEME || 'ldap'
const HOST = process.env.HOST || '127.0.0.1'
const PORT = process.env.PORT || 389
const baseURL = `${SCHEME}://${HOST}:${PORT}`
const client = ldapjs.createClient({ url: baseURL })
tap.test('adds entries with Korean characters', t => {
t.plan(4)
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', (err) => {
t.error(err, 'bind error')
})
const nm = '홍길동'
const dn = `cn=${nm},ou=people,dc=planetexpress,dc=com`
const entry = {
objectclass: 'person',
sn: 'korean test'
}
client.add(dn, entry, err => {
t.error(err, 'add entry error')
const searchOpts = {
filter: '(sn=korean test)',
scope: 'subtree',
attributes: ['cn', 'sn'],
sizeLimit: 10,
timeLimit: 0
}
client.search('ou=people,dc=planetexpress,dc=com', searchOpts, (err, res) => {
t.error(err, 'search error')
res.on('searchEntry', (entry) => {
t.equal(
entry.attributes.filter(a => a.type === 'cn').pop().values.pop(),
nm
)
})
res.on('error', (err) => {
t.error(err, 'search entry error')
})
res.on('end', () => {
client.unbind(t.end)
})
})
})
})

View File

@ -0,0 +1,55 @@
'use strict'
const tap = require('tap')
const ldapjs = require('../../lib')
const parseDN = ldapjs.parseDN
const SCHEME = process.env.SCHEME || 'ldap'
const HOST = process.env.HOST || '127.0.0.1'
const PORT = process.env.PORT || 389
const baseURL = `${SCHEME}://${HOST}:${PORT}`
const client = ldapjs.createClient({ url: baseURL })
const searchOpts = {
filter: '(&(objectClass=person))',
scope: 'sub',
paged: true,
sizeLimit: 0,
attributes: ['cn', 'employeeID']
}
const baseDN = parseDN('ou=large_ou,dc=planetexpress,dc=com')
tap.test('paged search option returns pages', t => {
t.plan(4)
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', (err) => {
t.error(err, 'bind error')
})
client.search(baseDN.toString(), searchOpts, (err, res) => {
t.error(err, 'search error')
let pages = 0
const results = []
res.on('searchEntry', (entry) => {
results.push(entry)
})
res.on('page', () => {
pages += 1
})
res.on('error', (err) => {
t.error(err, 'search entry error')
})
res.on('end', () => {
t.equal(results.length, 2000)
t.equal(pages, 20)
client.unbind(t.end)
})
})
})

View File

@ -0,0 +1,91 @@
'use strict'
const tap = require('tap')
const ldapjs = require('../../lib')
const { DN } = require('@ldapjs/dn')
const Change = require('@ldapjs/change')
const SCHEME = process.env.SCHEME || 'ldap'
const HOST = process.env.HOST || '127.0.0.1'
const PORT = process.env.PORT || 389
const baseURL = `${SCHEME}://${HOST}:${PORT}`
const client = ldapjs.createClient({ url: baseURL })
tap.teardown(() => {
client.unbind()
})
tap.test('modifies entry specified by dn string', t => {
t.plan(4)
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', (err) => {
t.error(err, 'bind error')
})
const dn = 'cn=large10,ou=large_ou,dc=planetexpress,dc=com'
const change = new Change({
operation: 'replace',
modification: {
type: 'givenName',
values: ['test']
}
})
client.modify(dn, change, (err) => {
t.error(err, 'modify error')
validateChange({ t, expected: 'test', client })
})
})
tap.test('modifies entry specified by dn object', t => {
t.plan(4)
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', (err) => {
t.error(err, 'bind error')
})
const dn = DN.fromString('cn=large10,ou=large_ou,dc=planetexpress,dc=com')
const change = new Change({
operation: 'replace',
modification: {
type: 'givenName',
values: ['test2']
}
})
client.modify(dn, change, (err) => {
t.error(err, 'modify error')
validateChange({ t, expected: 'test2', client })
})
})
function validateChange ({ t, expected, client }) {
const searchBase = 'ou=large_ou,dc=planetexpress,dc=com'
const searchOpts = {
filter: '(cn=large10)',
scope: 'subtree',
attributes: ['givenName'],
sizeLimit: 10,
timeLimit: 0
}
client.search(searchBase, searchOpts, (err, res) => {
t.error(err, 'search error')
res.on('searchEntry', entry => {
t.equal(
entry.attributes.filter(a => a.type === 'givenName').pop().values.pop(),
expected
)
})
res.on('error', err => {
t.error(err, 'search entry error')
})
res.on('end', () => {
t.end()
})
})
}

View File

@ -0,0 +1,81 @@
'use strict'
const tap = require('tap')
const ldapjs = require('../../lib')
const Change = require('@ldapjs/change')
const SCHEME = process.env.SCHEME || 'ldap'
const HOST = process.env.HOST || '127.0.0.1'
const PORT = process.env.PORT || 389
const baseURL = `${SCHEME}://${HOST}:${PORT}`
const client = ldapjs.createClient({ url: baseURL })
tap.before(() => {
return new Promise((resolve, reject) => {
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', (err) => {
if (err) {
return reject(err)
}
resolve()
})
})
})
tap.teardown(() => {
client.unbind()
})
tap.test('can modify entries with non-ascii chars in RDN', t => {
t.plan(6)
const dn = 'cn=Mendonça,ou=people,dc=planetexpress,dc=com'
const entry = {
objectclass: 'person',
sn: 'change me'
}
client.add(dn, entry, error => {
t.error(error, 'add should not error')
doSearch('change me', doModify)
})
function doModify () {
const change = new Change({
operation: 'replace',
modification: {
type: 'sn',
values: ['changed']
}
})
client.modify(dn, change, (error) => {
t.error(error, 'modify should not error')
doSearch('changed', t.end.bind(t))
})
}
function doSearch (expected, callback) {
const searchOpts = {
filter: '(&(objectclass=person)(cn=Mendonça))',
scope: 'subtree',
attributes: ['sn']
}
client.search('ou=people,dc=planetexpress,dc=com', searchOpts, (error, res) => {
t.error(error, 'search should not error')
res.on('searchEntry', entry => {
const found = entry.attributes.filter(a => a.type === 'sn').pop().values.pop()
t.equal(found, expected, `expected '${expected}' and got '${found}'`)
})
res.on('error', error => {
t.error(error, 'search result processing should not error')
})
res.on('end', () => {
callback()
})
})
}
})

View File

@ -0,0 +1,87 @@
'use strict'
const tap = require('tap')
const ldapjs = require('../../lib')
const SCHEME = process.env.SCHEME || 'ldap'
const HOST = process.env.HOST || '127.0.0.1'
const PORT = process.env.PORT || 389
const baseURL = `${SCHEME}://${HOST}:${PORT}`
tap.test('can use password policy response', t => {
const client = ldapjs.createClient({ url: baseURL })
const targetDN = 'cn=Bender Bending Rodríguez,ou=people,dc=planetexpress,dc=com'
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', (err, res) => {
t.error(err)
t.ok(res)
t.equal(res.status, 0)
const newPassword = 'bender2'
changePassword(client, newPassword, () => {
client.unbind()
bindNewClient(newPassword, { error: 2 }, (client) => {
const newPassword = 'bender'
changePassword(client, newPassword, () => {
client.unbind()
bindNewClient(newPassword, { timeBeforeExpiration: 1000 }, (client) => {
client.unbind(t.end)
})
})
})
})
})
function bindNewClient (pwd, expected, callback) {
const client = ldapjs.createClient({ url: baseURL })
const control = new ldapjs.PasswordPolicyControl()
client.bind(targetDN, pwd, control, (err, res) => {
t.error(err)
t.ok(res)
t.equal(res.status, 0)
let error = null
let timeBeforeExpiration = null
let graceAuthNsRemaining = null
res.controls.forEach(control => {
if (control.type === ldapjs.PasswordPolicyControl.OID) {
error = control.value.error ?? error
timeBeforeExpiration = control.value.timeBeforeExpiration ?? timeBeforeExpiration
graceAuthNsRemaining = control.value.graceAuthNsRemaining ?? graceAuthNsRemaining
}
})
if (expected.error !== undefined) {
t.equal(error, expected.error)
}
if (expected.timeBeforeExpiration !== undefined) {
t.equal(timeBeforeExpiration, expected.timeBeforeExpiration)
}
if (expected.graceAuthNsRemaining !== undefined) {
t.equal(graceAuthNsRemaining, expected.graceAuthNsRemaining)
}
callback(client)
})
}
function changePassword (client, newPwd, callback) {
const change = new ldapjs.Change({
operation: 'replace',
modification: new ldapjs.Attribute({
type: 'userPassword',
values: newPwd
})
})
client.modify(targetDN, change, (err, res) => {
t.error(err)
t.ok(res)
t.equal(res.status, 0)
callback()
})
}
})

View File

@ -10,7 +10,14 @@ const PORT = process.env.PORT || 389
const baseURL = `${SCHEME}://${HOST}:${PORT}` const baseURL = `${SCHEME}://${HOST}:${PORT}`
tap.test('modifyDN with long name (issue #480)', t => { tap.test('modifyDN with long name (issue #480)', t => {
const longStr = 'a292979f2c86d513d48bbb9786b564b3c5228146e5ba46f404724e322544a7304a2b1049168803a5485e2d57a544c6a0d860af91330acb77e5907a9e601ad1227e80e0dc50abe963b47a004f2c90f570450d0e920d15436fdc771e3bdac0487a9735473ed3a79361d1778d7e53a7fb0e5f01f97a75ef05837d1d5496fc86968ff47fcb64' // 2023-08-15: disabling this 265 character string until a bug can be
// fixed in OpenLDAP. See https://github.com/ldapjs/docker-test-openldap/blob/d48bc2fb001b4ed9a152715ced4a2cb120439ec4/bootstrap/slapd-init.sh#L19-L31.
// const longStr = 'a292979f2c86d513d48bbb9786b564b3c5228146e5ba46f404724e322544a7304a2b1049168803a5485e2d57a544c6a0d860af91330acb77e5907a9e601ad1227e80e0dc50abe963b47a004f2c90f570450d0e920d15436fdc771e3bdac0487a9735473ed3a79361d1778d7e53a7fb0e5f01f97a75ef05837d1d5496fc86968ff47fcb64'
// 2023-08-15: this 140 character string satisfies the original issue
// (https://github.com/ldapjs/node-ldapjs/issues/480) and avoids a bug
// in OpenLDAP 2.5.
const longStr = '292979f2c86d513d48bbb9786b564b3c5228146e5ba46f404724e322544a7304a2b1049168803a5485e2d57a544c6a0d860af91330acb77e5907a9e601ad1227e80e0dc50ab'
const targetDN = 'cn=Turanga Leela,ou=people,dc=planetexpress,dc=com' const targetDN = 'cn=Turanga Leela,ou=people,dc=planetexpress,dc=com'
const client = ldapjs.createClient({ url: baseURL }) const client = ldapjs.createClient({ url: baseURL })
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', bindHandler) client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', bindHandler)
@ -80,9 +87,9 @@ tap.test('can access large groups (issue #582)', t => {
const memberAttr = results[0].attributes.find(a => a.type === 'member') const memberAttr = results[0].attributes.find(a => a.type === 'member')
t.ok(memberAttr) t.ok(memberAttr)
t.ok(memberAttr.vals) t.ok(memberAttr.values)
t.type(memberAttr.vals, Array) t.type(memberAttr.values, Array)
t.equal(memberAttr.vals.length, 2000) t.equal(memberAttr.values.length, 2000)
client.unbind(t.end) client.unbind(t.end)
}) })

View File

@ -10,6 +10,7 @@ const Attribute = require('@ldapjs/attribute')
const Change = require('@ldapjs/change') const Change = require('@ldapjs/change')
const messages = require('@ldapjs/messages') const messages = require('@ldapjs/messages')
const controls = require('@ldapjs/controls') const controls = require('@ldapjs/controls')
const dn = require('@ldapjs/dn')
const ldap = require('../lib') const ldap = require('../lib')
const { const {
@ -761,6 +762,36 @@ tap.test('search basic', function (t) {
}) })
}) })
tap.test('search basic with DN', function (t) {
const { SearchResultEntry, SearchResultDone } = messages
t.context.client.search(dn.DN.fromString('cn=test, ' + SUFFIX, '(objectclass=*)'), function (err, res) {
t.error(err)
t.ok(res)
let gotEntry = 0
res.on('searchEntry', function (entry) {
t.ok(entry)
t.ok(entry instanceof SearchResultEntry)
t.equal(entry.dn.toString(), 'cn=test,' + SUFFIX)
t.ok(entry.attributes)
t.ok(entry.attributes.length)
t.equal(entry.attributes[0].type, 'cn')
t.equal(entry.attributes[1].type, 'SN')
gotEntry++
})
res.on('error', function (err) {
t.fail(err)
})
res.on('end', function (res) {
t.ok(res)
t.ok(res instanceof SearchResultDone)
t.equal(res.status, 0)
t.equal(gotEntry, 2)
t.end()
})
})
})
tap.test('GH-602 search basic with delayed event listener binding', function (t) { tap.test('GH-602 search basic with delayed event listener binding', function (t) {
t.context.client.search('cn=test, ' + SUFFIX, '(objectclass=*)', function (err, res) { t.context.client.search('cn=test, ' + SUFFIX, '(objectclass=*)', function (err, res) {
t.error(err) t.error(err)

116
test/issue-845.test.js Normal file
View File

@ -0,0 +1,116 @@
'use strict'
const tap = require('tap')
const { SearchResultEntry, SearchRequest } = require('@ldapjs/messages')
const ldapjs = require('../')
const server = ldapjs.createServer()
const SUFFIX = ''
const directory = {
'dc=example,dc=com': {
objectclass: 'example',
dc: 'example',
cn: 'example'
}
}
server.bind(SUFFIX, (req, res, done) => {
res.end()
return done()
})
server.search(SUFFIX, (req, res, done) => {
const dn = req.dn.toString().toLowerCase()
if (Object.hasOwn(directory, dn) === false) {
return done(Error('not in directory'))
}
switch (req.scope) {
case SearchRequest.SCOPE_BASE:
case SearchRequest.SCOPE_SUBTREE: {
res.send(new SearchResultEntry({ objectName: `dc=${req.scopeName}` }))
break
}
}
res.end()
done()
})
tap.beforeEach(t => {
return new Promise((resolve, reject) => {
server.listen(0, '127.0.0.1', (err) => {
if (err) return reject(err)
t.context.url = server.url
t.context.client = ldapjs.createClient({ url: [server.url] })
t.context.searchOpts = {
filter: '(&(objectClass=*))',
scope: 'sub',
attributes: ['dn', 'cn']
}
resolve()
})
})
})
tap.afterEach(t => {
return new Promise((resolve, reject) => {
t.context.client.destroy()
server.close((err) => {
if (err) return reject(err)
resolve()
})
})
})
tap.test('rejects if search not in directory', t => {
const { client, searchOpts } = t.context
client.search('dc=nope', searchOpts, (err, res) => {
t.error(err)
res.on('error', err => {
// TODO: plain error messages should not be lost
// This should be fixed in a revamp of the server code.
// ~ jsumners 2023-03-08
t.equal(err.lde_message, 'Operations Error')
t.end()
})
})
})
tap.test('base scope matches', t => {
const { client, searchOpts } = t.context
searchOpts.scope = 'base'
client.search('dc=example,dc=com', searchOpts, (err, res) => {
t.error(err)
res.on('error', (err) => {
t.error(err)
t.end()
})
res.on('searchEntry', entry => {
t.equal(entry.objectName.toString(), 'dc=base')
t.end()
})
})
})
tap.test('sub scope matches', t => {
const { client, searchOpts } = t.context
client.search('dc=example,dc=com', searchOpts, (err, res) => {
t.error(err)
res.on('error', (err) => {
t.error(err)
t.end()
})
res.on('searchEntry', entry => {
t.equal(entry.objectName.toString(), 'dc=subtree')
t.end()
})
})
})

103
test/issue-890.test.js Normal file
View File

@ -0,0 +1,103 @@
'use strict'
// This test is complicated. It must simulate a server sending an unsolicited,
// or a mismatched, message in order to force the client's internal message
// tracker to try and find a corresponding sent message that does not exist.
// In order to do that, we need to set a high test timeout and wait for the
// error message to be logged.
const tap = require('tap')
const ldapjs = require('../')
const { SearchResultEntry } = require('@ldapjs/messages')
const server = ldapjs.createServer()
const SUFFIX = ''
tap.timeout = 10000
server.bind(SUFFIX, (res, done) => {
res.end()
return done()
})
server.search(SUFFIX, (req, res, done) => {
const result = new SearchResultEntry({
objectName: `dc=${req.scopeName}`
})
// Respond to the search request with a matched response.
res.send(result)
res.end()
// After a short delay, send ANOTHER response to the client that will not
// be matched by the client's internal tracker.
setTimeout(
() => {
res.send(result)
res.end()
done()
},
100
)
})
tap.beforeEach(t => {
return new Promise((resolve, reject) => {
server.listen(0, '127.0.0.1', (err) => {
if (err) return reject(err)
t.context.logMessages = []
t.context.logger = {
child () { return this },
debug () {},
error (...args) {
t.context.logMessages.push(args)
},
trace () {}
}
t.context.url = server.url
t.context.client = ldapjs.createClient({
url: [server.url],
timeout: 5,
log: t.context.logger
})
resolve()
})
})
})
tap.afterEach(t => {
return new Promise((resolve, reject) => {
t.context.client.destroy()
server.close((err) => {
if (err) return reject(err)
resolve()
})
})
})
tap.test('handle null messages', t => {
const { client, logMessages } = t.context
// There's no way to get an error from the client when it has received an
// unmatched response from the server. So we need to poll our logger instance
// and detect when the corresponding error message has been logged.
const timer = setInterval(
() => {
if (logMessages.length > 0) {
t.equal(
logMessages.some(msg => msg[1] === 'unmatched server message received'),
true
)
clearInterval(timer)
t.end()
}
},
100
)
client.search('dc=test', (error) => {
t.error(error)
})
})

View File

@ -3,6 +3,7 @@
const net = require('net') const net = require('net')
const tap = require('tap') const tap = require('tap')
const vasync = require('vasync') const vasync = require('vasync')
const vm = require('node:vm')
const { getSock } = require('./utils') const { getSock } = require('./utils')
const ldap = require('../lib') const ldap = require('../lib')
@ -256,6 +257,27 @@ tap.test('bind/unbind identity anonymous', function (t) {
}) })
}) })
tap.test('does not crash on empty DN values', function (t) {
const server = ldap.createServer({
connectionRouter: function (c) {
server.newConnection(c)
server.emit('testconnection', c)
}
})
server.listen(t.context.sock, function () {
const client = ldap.createClient({ socketPath: t.context.sock })
server.once('testconnection', () => {
client.bind('', 'pw', function (err) {
t.ok(err, 'blank bind dn throws error')
client.unbind(function () {
server.close(() => t.end())
})
})
})
})
})
tap.test('bind/unbind identity user', function (t) { tap.test('bind/unbind identity user', function (t) {
const server = ldap.createServer({ const server = ldap.createServer({
connectionRouter: function (c) { connectionRouter: function (c) {
@ -434,3 +456,16 @@ tap.test('multithreading support via hook', function (t) {
}) })
}) })
}) })
tap.test('cross-realm type checks', function (t) {
const server = ldap.createServer()
const ctx = vm.createContext({})
vm.runInContext(
'globalThis.search=function(){};\n' +
'globalThis.searches=[function(){}];'
, ctx)
server.search('', ctx.search)
server.search('', ctx.searches)
t.ok(server)
t.end()
})