From 0fcad2443d5b8302586738541c321c8ec40d1fc9 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Sat, 22 Jul 2023 21:42:51 +0200 Subject: [PATCH] Fix ensureDN (#918) --- lib/client/client.js | 2 +- test/client.test.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/client/client.js b/lib/client/client.js index d24f169..10959fc 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -80,7 +80,7 @@ function validateControls (controls) { function ensureDN (input) { if (DN.isDn(input)) { - return DN + return input } else if (typeof (input) === 'string') { return DN.fromString(input) } else { diff --git a/test/client.test.js b/test/client.test.js index 2ae4a22..7066398 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -10,6 +10,7 @@ const Attribute = require('@ldapjs/attribute') const Change = require('@ldapjs/change') const messages = require('@ldapjs/messages') const controls = require('@ldapjs/controls') +const dn = require('@ldapjs/dn') const ldap = require('../lib') 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) { t.context.client.search('cn=test, ' + SUFFIX, '(objectclass=*)', function (err, res) { t.error(err)