issues.test.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. 'use strict'
  2. const tap = require('tap')
  3. const ldapjs = require('../../lib')
  4. const SCHEME = process.env.SCHEME || 'ldap'
  5. const HOST = process.env.HOST || '127.0.0.1'
  6. const PORT = process.env.PORT || 389
  7. const baseURL = `${SCHEME}://${HOST}:${PORT}`
  8. tap.test('modifyDN with long name (issue #480)', t => {
  9. // 2023-08-15: disabling this 265 character string until a bug can be
  10. // fixed in OpenLDAP. See https://github.com/ldapjs/docker-test-openldap/blob/d48bc2fb001b4ed9a152715ced4a2cb120439ec4/bootstrap/slapd-init.sh#L19-L31.
  11. // const longStr = 'a292979f2c86d513d48bbb9786b564b3c5228146e5ba46f404724e322544a7304a2b1049168803a5485e2d57a544c6a0d860af91330acb77e5907a9e601ad1227e80e0dc50abe963b47a004f2c90f570450d0e920d15436fdc771e3bdac0487a9735473ed3a79361d1778d7e53a7fb0e5f01f97a75ef05837d1d5496fc86968ff47fcb64'
  12. // 2023-08-15: this 140 character string satisfies the original issue
  13. // (https://github.com/ldapjs/node-ldapjs/issues/480) and avoids a bug
  14. // in OpenLDAP 2.5.
  15. const longStr = '292979f2c86d513d48bbb9786b564b3c5228146e5ba46f404724e322544a7304a2b1049168803a5485e2d57a544c6a0d860af91330acb77e5907a9e601ad1227e80e0dc50ab'
  16. const targetDN = 'cn=Turanga Leela,ou=people,dc=planetexpress,dc=com'
  17. const client = ldapjs.createClient({ url: baseURL })
  18. client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', bindHandler)
  19. function bindHandler (err) {
  20. t.error(err)
  21. client.modifyDN(
  22. targetDN,
  23. `cn=${longStr},ou=people,dc=planetexpress,dc=com`,
  24. modifyHandler
  25. )
  26. }
  27. function modifyHandler (err, res) {
  28. t.error(err)
  29. t.ok(res)
  30. t.equal(res.status, 0)
  31. client.modifyDN(
  32. `cn=${longStr},ou=people,dc=planetexpress,dc=com`,
  33. targetDN,
  34. (err) => {
  35. t.error(err)
  36. client.unbind(t.end)
  37. }
  38. )
  39. }
  40. })
  41. tap.test('whois works correctly (issue #370)', t => {
  42. const client = ldapjs.createClient({ url: baseURL })
  43. client.bind('cn=Philip J. Fry,ou=people,dc=planetexpress,dc=com', 'fry', (err) => {
  44. t.error(err)
  45. client.exop('1.3.6.1.4.1.4203.1.11.3', (err, value, res) => {
  46. t.error(err)
  47. t.ok(value)
  48. t.equal(value, 'dn:cn=Philip J. Fry,ou=people,dc=planetexpress,dc=com')
  49. t.ok(res)
  50. t.equal(res.status, 0)
  51. client.unbind(t.end)
  52. })
  53. })
  54. })
  55. tap.test('can access large groups (issue #582)', t => {
  56. const client = ldapjs.createClient({ url: baseURL })
  57. client.bind('cn=admin,dc=planetexpress,dc=com ', 'GoodNewsEveryone', (err) => {
  58. t.error(err)
  59. const searchOpts = {
  60. scope: 'sub',
  61. filter: '(&(objectClass=group)(cn=large_group))'
  62. }
  63. client.search('ou=large_ou,dc=planetexpress,dc=com', searchOpts, (err, response) => {
  64. t.error(err)
  65. const results = []
  66. response.on('searchEntry', (entry) => {
  67. results.push(entry)
  68. })
  69. response.on('error', t.error)
  70. response.on('end', (result) => {
  71. t.equal(result.status, 0)
  72. t.equal(results.length === 1, true)
  73. t.ok(results[0].attributes)
  74. const memberAttr = results[0].attributes.find(a => a.type === 'member')
  75. t.ok(memberAttr)
  76. t.ok(memberAttr.values)
  77. t.type(memberAttr.values, Array)
  78. t.equal(memberAttr.values.length, 2000)
  79. client.unbind(t.end)
  80. })
  81. })
  82. })
  83. })