issue-940.test.js 1.9 KB

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