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

Commit bec2ff8

Browse files
committed
Add test for issue 940
1 parent 6a67636 commit bec2ff8

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
'use strict'
2+
3+
const tap = require('tap')
4+
const ldapjs = require('../../lib')
5+
const Change = require('@ldapjs/change')
6+
7+
const SCHEME = process.env.SCHEME || 'ldap'
8+
const HOST = process.env.HOST || '127.0.0.1'
9+
const PORT = process.env.PORT || 389
10+
const baseURL = `${SCHEME}://${HOST}:${PORT}`
11+
12+
const client = ldapjs.createClient({ url: baseURL })
13+
14+
tap.before(() => {
15+
return new Promise((resolve, reject) => {
16+
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', (err) => {
17+
if (err) {
18+
return reject(err)
19+
}
20+
resolve()
21+
})
22+
})
23+
})
24+
25+
tap.teardown(() => {
26+
client.unbind()
27+
})
28+
29+
tap.test('can modify entries with non-ascii chars in RDN', t => {
30+
t.plan(6)
31+
32+
const dn = 'cn=Mendonça,ou=people,dc=planetexpress,dc=com'
33+
const entry = {
34+
objectclass: 'person',
35+
sn: 'change me'
36+
}
37+
38+
client.add(dn, entry, error => {
39+
t.error(error, 'add should not error')
40+
doSearch('change me', doModify)
41+
})
42+
43+
function doModify () {
44+
const change = new Change({
45+
operation: 'replace',
46+
modification: {
47+
type: 'sn',
48+
values: ['changed']
49+
}
50+
})
51+
52+
client.modify(dn, change, (error) => {
53+
t.error(error, 'modify should not error')
54+
doSearch('changed', t.end.bind(t))
55+
})
56+
}
57+
58+
function doSearch (expected, callback) {
59+
const searchOpts = {
60+
filter: '(&(objectclass=person)(cn=Mendonça))',
61+
scope: 'subtree',
62+
attributes: ['sn']
63+
}
64+
client.search('ou=people,dc=planetexpress,dc=com', searchOpts, (error, res) => {
65+
t.error(error, 'search should not error')
66+
67+
res.on('searchEntry', entry => {
68+
const found = entry.attributes.filter(a => a.type === 'sn').pop().values.pop()
69+
t.equal(found, expected, `expected '${expected}' and got '${found}'`)
70+
})
71+
72+
res.on('error', error => {
73+
t.error(error, 'search result processing should not error')
74+
})
75+
76+
res.on('end', () => {
77+
callback()
78+
})
79+
})
80+
}
81+
})

0 commit comments

Comments
 (0)