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

Commit 0fcad24

Browse files
authored
Fix ensureDN (#918)
1 parent 3c7b7cb commit 0fcad24

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/client/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function validateControls (controls) {
8080

8181
function ensureDN (input) {
8282
if (DN.isDn(input)) {
83-
return DN
83+
return input
8484
} else if (typeof (input) === 'string') {
8585
return DN.fromString(input)
8686
} else {

test/client.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const Attribute = require('@ldapjs/attribute')
1010
const Change = require('@ldapjs/change')
1111
const messages = require('@ldapjs/messages')
1212
const controls = require('@ldapjs/controls')
13+
const dn = require('@ldapjs/dn')
1314
const ldap = require('../lib')
1415

1516
const {
@@ -761,6 +762,36 @@ tap.test('search basic', function (t) {
761762
})
762763
})
763764

765+
tap.test('search basic with DN', function (t) {
766+
const { SearchResultEntry, SearchResultDone } = messages
767+
768+
t.context.client.search(dn.DN.fromString('cn=test, ' + SUFFIX, '(objectclass=*)'), function (err, res) {
769+
t.error(err)
770+
t.ok(res)
771+
let gotEntry = 0
772+
res.on('searchEntry', function (entry) {
773+
t.ok(entry)
774+
t.ok(entry instanceof SearchResultEntry)
775+
t.equal(entry.dn.toString(), 'cn=test,' + SUFFIX)
776+
t.ok(entry.attributes)
777+
t.ok(entry.attributes.length)
778+
t.equal(entry.attributes[0].type, 'cn')
779+
t.equal(entry.attributes[1].type, 'SN')
780+
gotEntry++
781+
})
782+
res.on('error', function (err) {
783+
t.fail(err)
784+
})
785+
res.on('end', function (res) {
786+
t.ok(res)
787+
t.ok(res instanceof SearchResultDone)
788+
t.equal(res.status, 0)
789+
t.equal(gotEntry, 2)
790+
t.end()
791+
})
792+
})
793+
})
794+
764795
tap.test('GH-602 search basic with delayed event listener binding', function (t) {
765796
t.context.client.search('cn=test, ' + SUFFIX, '(objectclass=*)', function (err, res) {
766797
t.error(err)

0 commit comments

Comments
 (0)