wangzhibo
2026-05-09 53418655c061ac26f66058253f39200aced1ab1d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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)
      })
    })
  })
})