2019-08-27 21:11:49 +00:00
|
|
|
'use strict'
|
2014-01-22 18:21:57 +00:00
|
|
|
|
2021-05-20 14:40:37 +00:00
|
|
|
const net = require('net')
|
2019-08-27 21:11:49 +00:00
|
|
|
const tap = require('tap')
|
|
|
|
const vasync = require('vasync')
|
|
|
|
const { getSock } = require('./utils')
|
|
|
|
const ldap = require('../lib')
|
2014-01-22 18:21:57 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const SERVER_PORT = process.env.SERVER_PORT || 1389
|
|
|
|
const SUFFIX = 'dc=test'
|
2014-01-22 18:21:57 +00:00
|
|
|
|
2021-04-05 05:25:32 +00:00
|
|
|
tap.beforeEach(function (t) {
|
2019-08-27 13:08:00 +00:00
|
|
|
// We do not need a `.afterEach` to clean up the sock files because that
|
|
|
|
// is done when the server is destroyed.
|
|
|
|
t.context.sock = getSock()
|
|
|
|
})
|
|
|
|
|
|
|
|
tap.test('basic create', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const server = ldap.createServer()
|
|
|
|
t.ok(server)
|
|
|
|
t.end()
|
|
|
|
})
|
2014-01-22 18:21:57 +00:00
|
|
|
|
2020-02-15 16:22:00 +00:00
|
|
|
tap.test('connection count', function (t) {
|
|
|
|
const server = ldap.createServer()
|
|
|
|
t.ok(server)
|
|
|
|
server.listen(0, 'localhost', function () {
|
|
|
|
t.ok(true, 'server listening on ' + server.url)
|
|
|
|
|
|
|
|
server.getConnections(function (err, count) {
|
|
|
|
t.error(err)
|
|
|
|
t.equal(count, 0)
|
|
|
|
|
|
|
|
const client = ldap.createClient({ url: server.url })
|
|
|
|
client.on('connect', function () {
|
|
|
|
t.ok(true, 'client connected')
|
|
|
|
server.getConnections(function (err, count) {
|
|
|
|
t.error(err)
|
|
|
|
t.equal(count, 1)
|
|
|
|
client.unbind()
|
|
|
|
server.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
tap.test('properties', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const server = ldap.createServer()
|
|
|
|
t.equal(server.name, 'LDAPServer')
|
2015-10-31 13:34:51 +00:00
|
|
|
|
|
|
|
// TODO: better test
|
2019-08-27 21:11:49 +00:00
|
|
|
server.maxConnections = 10
|
|
|
|
t.equal(server.maxConnections, 10)
|
2015-10-31 13:34:51 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
t.equal(server.url, null, 'url empty before bind')
|
2015-10-31 13:34:51 +00:00
|
|
|
// listen on a random port so we have a url
|
|
|
|
server.listen(0, 'localhost', function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(server.url)
|
2015-10-31 13:34:51 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
server.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
2015-10-31 13:34:51 +00:00
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
tap.test('listen on unix/named socket', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const server = ldap.createServer()
|
2019-08-27 13:08:00 +00:00
|
|
|
server.listen(t.context.sock, function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(server.url)
|
|
|
|
t.equal(server.url.split(':')[0], 'ldapi')
|
|
|
|
server.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
2014-06-06 17:21:05 +00:00
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
tap.test('listen on static port', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const server = ldap.createServer()
|
2014-06-06 17:21:05 +00:00
|
|
|
server.listen(SERVER_PORT, '127.0.0.1', function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
const addr = server.address()
|
|
|
|
t.equal(addr.port, parseInt(SERVER_PORT, 10))
|
2021-04-05 05:34:59 +00:00
|
|
|
t.equal(server.url, `ldap://127.0.0.1:${SERVER_PORT}`)
|
2019-08-27 21:11:49 +00:00
|
|
|
server.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
2014-01-22 18:21:57 +00:00
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
tap.test('listen on ephemeral port', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const server = ldap.createServer()
|
2014-01-22 18:21:57 +00:00
|
|
|
server.listen(0, 'localhost', function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
const addr = server.address()
|
|
|
|
t.ok(addr.port > 0)
|
|
|
|
t.ok(addr.port < 65535)
|
|
|
|
server.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
2014-01-22 18:21:57 +00:00
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
tap.test('route order', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
function generateHandler (response) {
|
|
|
|
const func = function handler (req, res, next) {
|
2014-01-22 18:21:57 +00:00
|
|
|
res.send({
|
|
|
|
dn: response,
|
|
|
|
attributes: { }
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
res.end()
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
return func
|
2014-01-22 18:21:57 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const server = ldap.createServer()
|
|
|
|
const sock = t.context.sock
|
|
|
|
const dnShort = SUFFIX
|
2020-07-27 23:15:46 +00:00
|
|
|
const dnMed = 'dc=sub,' + SUFFIX
|
|
|
|
const dnLong = 'dc=long,dc=sub,' + SUFFIX
|
2014-01-22 18:21:57 +00:00
|
|
|
|
|
|
|
// Mount routes out of order
|
2019-08-27 21:11:49 +00:00
|
|
|
server.search(dnMed, generateHandler(dnMed))
|
|
|
|
server.search(dnShort, generateHandler(dnShort))
|
|
|
|
server.search(dnLong, generateHandler(dnLong))
|
2014-01-22 18:21:57 +00:00
|
|
|
server.listen(sock, function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(true, 'server listen')
|
|
|
|
const client = ldap.createClient({ socketPath: sock })
|
2019-08-27 18:17:33 +00:00
|
|
|
client.on('connect', () => {
|
|
|
|
vasync.forEachParallel({
|
2019-08-27 21:11:49 +00:00
|
|
|
func: runSearch,
|
|
|
|
inputs: [dnShort, dnMed, dnLong]
|
2020-12-07 01:26:27 +00:00
|
|
|
}, function (err) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.error(err)
|
|
|
|
client.unbind()
|
|
|
|
server.close(() => t.end())
|
|
|
|
})
|
2019-08-27 18:17:33 +00:00
|
|
|
})
|
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
function runSearch (value, cb) {
|
2014-01-22 18:21:57 +00:00
|
|
|
client.search(value, '(objectclass=*)', function (err, res) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.error(err)
|
|
|
|
t.ok(res)
|
2014-01-22 18:21:57 +00:00
|
|
|
res.on('searchEntry', function (entry) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.equal(entry.dn.toString(), value)
|
|
|
|
})
|
2014-01-22 18:21:57 +00:00
|
|
|
res.on('end', function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
cb()
|
|
|
|
})
|
|
|
|
})
|
2014-01-22 18:21:57 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
})
|
2014-01-22 18:21:57 +00:00
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
tap.test('route absent', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const server = ldap.createServer()
|
|
|
|
const DN_ROUTE = 'dc=base'
|
|
|
|
const DN_MISSING = 'dc=absent'
|
2014-01-22 18:21:57 +00:00
|
|
|
|
|
|
|
server.bind(DN_ROUTE, function (req, res, next) {
|
2019-08-27 21:11:49 +00:00
|
|
|
res.end()
|
|
|
|
return next()
|
|
|
|
})
|
2014-01-22 18:21:57 +00:00
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
server.listen(t.context.sock, function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(true, 'server startup')
|
2014-01-22 18:21:57 +00:00
|
|
|
vasync.parallel({
|
2019-08-27 18:17:33 +00:00
|
|
|
funcs: [
|
2019-08-27 21:11:49 +00:00
|
|
|
function presentBind (cb) {
|
|
|
|
const clt = ldap.createClient({ socketPath: t.context.sock })
|
2014-01-22 18:21:57 +00:00
|
|
|
clt.bind(DN_ROUTE, '', function (err) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.notOk(err)
|
|
|
|
clt.unbind()
|
|
|
|
cb()
|
|
|
|
})
|
2014-01-22 18:21:57 +00:00
|
|
|
},
|
2019-08-27 21:11:49 +00:00
|
|
|
function absentBind (cb) {
|
|
|
|
const clt = ldap.createClient({ socketPath: t.context.sock })
|
2014-01-22 18:21:57 +00:00
|
|
|
clt.bind(DN_MISSING, '', function (err) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(err)
|
|
|
|
t.equal(err.code, ldap.LDAP_NO_SUCH_OBJECT)
|
|
|
|
clt.unbind()
|
|
|
|
cb()
|
|
|
|
})
|
2014-01-22 18:21:57 +00:00
|
|
|
}
|
|
|
|
]
|
2020-12-07 01:26:27 +00:00
|
|
|
}, function (err) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.notOk(err)
|
|
|
|
server.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-06-06 19:05:08 +00:00
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
tap.test('route unbind', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const server = ldap.createServer()
|
2014-06-06 19:05:08 +00:00
|
|
|
|
|
|
|
server.unbind(function (req, res, next) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(true, 'server unbind successful')
|
|
|
|
res.end()
|
|
|
|
return next()
|
|
|
|
})
|
2014-06-06 19:05:08 +00:00
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
server.listen(t.context.sock, function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(true, 'server startup')
|
|
|
|
const client = ldap.createClient({ socketPath: t.context.sock })
|
2014-06-06 19:05:08 +00:00
|
|
|
client.bind('', '', function (err) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.error(err, 'client bind error')
|
2014-06-06 19:05:08 +00:00
|
|
|
client.unbind(function (err) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.error(err, 'client unbind error')
|
|
|
|
server.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-09-30 23:39:19 +00:00
|
|
|
|
2021-07-12 15:02:12 +00:00
|
|
|
tap.test('bind/unbind identity anonymous', function (t) {
|
|
|
|
const server = ldap.createServer({
|
|
|
|
connectionRouter: function (c) {
|
|
|
|
server.newConnection(c)
|
|
|
|
server.emit('testconnection', c)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
server.unbind(function (req, res, next) {
|
|
|
|
t.ok(true, 'server unbind successful')
|
|
|
|
res.end()
|
|
|
|
return next()
|
|
|
|
})
|
|
|
|
|
|
|
|
server.bind('', function (req, res, next) {
|
|
|
|
t.ok(true, 'server bind successful')
|
|
|
|
res.end()
|
|
|
|
return next()
|
|
|
|
})
|
|
|
|
|
|
|
|
const anonDN = ldap.dn.parse('cn=anonymous')
|
|
|
|
|
|
|
|
server.listen(t.context.sock, function () {
|
|
|
|
t.ok(true, 'server startup')
|
|
|
|
|
|
|
|
const client = ldap.createClient({ socketPath: t.context.sock })
|
|
|
|
server.once('testconnection', (c) => {
|
|
|
|
t.ok(anonDN.equals(c.ldap.bindDN), 'pre bind dn is correct')
|
|
|
|
client.bind('', '', function (err) {
|
|
|
|
t.error(err, 'client anon bind error')
|
|
|
|
t.ok(anonDN.equals(c.ldap.bindDN), 'anon bind dn is correct')
|
|
|
|
client.unbind(function (err) {
|
|
|
|
t.error(err, 'client anon unbind error')
|
|
|
|
t.ok(anonDN.equals(c.ldap.bindDN), 'anon unbind dn is correct')
|
|
|
|
server.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
tap.test('bind/unbind identity user', function (t) {
|
|
|
|
const server = ldap.createServer({
|
|
|
|
connectionRouter: function (c) {
|
|
|
|
server.newConnection(c)
|
|
|
|
server.emit('testconnection', c)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
server.unbind(function (req, res, next) {
|
|
|
|
t.ok(true, 'server unbind successful')
|
|
|
|
res.end()
|
|
|
|
return next()
|
|
|
|
})
|
|
|
|
|
|
|
|
server.bind('', function (req, res, next) {
|
|
|
|
t.ok(true, 'server bind successful')
|
|
|
|
res.end()
|
|
|
|
return next()
|
|
|
|
})
|
|
|
|
|
|
|
|
const anonDN = ldap.dn.parse('cn=anonymous')
|
|
|
|
const testDN = ldap.dn.parse('cn=anotheruser')
|
|
|
|
|
|
|
|
server.listen(t.context.sock, function () {
|
|
|
|
t.ok(true, 'server startup')
|
|
|
|
|
|
|
|
const client = ldap.createClient({ socketPath: t.context.sock })
|
|
|
|
server.once('testconnection', (c) => {
|
|
|
|
t.ok(anonDN.equals(c.ldap.bindDN), 'pre bind dn is correct')
|
|
|
|
client.bind(testDN.toString(), 'somesecret', function (err) {
|
|
|
|
t.error(err, 'user bind error')
|
2021-07-12 15:24:01 +00:00
|
|
|
t.ok(testDN.equals(c.ldap.bindDN), 'user bind dn is correct')
|
|
|
|
// check rebinds too
|
|
|
|
client.bind('', '', function (err) {
|
|
|
|
t.error(err, 'client anon bind error')
|
|
|
|
t.ok(anonDN.equals(c.ldap.bindDN), 'anon bind dn is correct')
|
|
|
|
// user rebind
|
|
|
|
client.bind(testDN.toString(), 'somesecret', function (err) {
|
|
|
|
t.error(err, 'user bind error')
|
|
|
|
t.ok(testDN.equals(c.ldap.bindDN), 'user rebind dn is correct')
|
|
|
|
client.unbind(function (err) {
|
|
|
|
t.error(err, 'user unbind error')
|
|
|
|
t.ok(anonDN.equals(c.ldap.bindDN), 'user unbind dn is correct')
|
|
|
|
server.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
2021-07-12 15:02:12 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
tap.test('strict routing', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const testDN = 'cn=valid'
|
|
|
|
let clt
|
|
|
|
let server
|
|
|
|
const sock = t.context.sock
|
2015-10-31 14:01:50 +00:00
|
|
|
vasync.pipeline({
|
|
|
|
funcs: [
|
2019-08-27 21:11:49 +00:00
|
|
|
function setup (_, cb) {
|
2015-10-31 14:01:50 +00:00
|
|
|
server = ldap.createServer({
|
|
|
|
// strictDN: true - on by default
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2015-10-31 14:01:50 +00:00
|
|
|
// invalid DNs would go to default handler
|
|
|
|
server.search('', function (req, res, next) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(req.dn)
|
|
|
|
t.equal(typeof (req.dn), 'object')
|
|
|
|
t.equal(req.dn.toString(), testDN)
|
|
|
|
res.end()
|
|
|
|
next()
|
|
|
|
})
|
2015-10-31 14:01:50 +00:00
|
|
|
server.listen(sock, function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(true, 'server startup')
|
2015-10-31 14:01:50 +00:00
|
|
|
clt = ldap.createClient({
|
|
|
|
socketPath: sock,
|
|
|
|
strictDN: false
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
cb()
|
|
|
|
})
|
2015-10-31 14:01:50 +00:00
|
|
|
},
|
2019-08-27 21:11:49 +00:00
|
|
|
function testBad (_, cb) {
|
|
|
|
clt.search('not a dn', { scope: 'base' }, function (err, res) {
|
|
|
|
t.error(err)
|
2015-10-31 14:01:50 +00:00
|
|
|
res.once('error', function (err2) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(err2)
|
|
|
|
t.equal(err2.code, ldap.LDAP_INVALID_DN_SYNTAX)
|
|
|
|
cb()
|
|
|
|
})
|
2015-10-31 14:01:50 +00:00
|
|
|
res.once('end', function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.fail('accepted invalid dn')
|
|
|
|
cb(Error('bogus'))
|
|
|
|
})
|
|
|
|
})
|
2015-10-31 14:01:50 +00:00
|
|
|
},
|
2019-08-27 21:11:49 +00:00
|
|
|
function testGood (_, cb) {
|
|
|
|
clt.search(testDN, { scope: 'base' }, function (err, res) {
|
|
|
|
t.error(err)
|
2015-10-31 14:01:50 +00:00
|
|
|
res.once('error', function (err2) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.error(err2)
|
|
|
|
cb(err2)
|
|
|
|
})
|
2015-10-31 14:01:50 +00:00
|
|
|
res.once('end', function (result) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(result, 'accepted invalid dn')
|
|
|
|
cb()
|
|
|
|
})
|
|
|
|
})
|
2015-10-31 14:01:50 +00:00
|
|
|
}
|
|
|
|
]
|
2019-08-27 21:11:49 +00:00
|
|
|
}, function (err) {
|
|
|
|
t.error(err)
|
2015-10-31 14:01:50 +00:00
|
|
|
if (clt) {
|
2019-08-27 21:11:49 +00:00
|
|
|
clt.destroy()
|
2015-10-31 14:01:50 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
server.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
2015-10-31 14:01:50 +00:00
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
tap.test('non-strict routing', function (t) {
|
|
|
|
const server = ldap.createServer({
|
2014-09-30 23:39:19 +00:00
|
|
|
strictDN: false
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
const testDN = 'this ain\'t a DN'
|
2014-09-30 23:39:19 +00:00
|
|
|
|
|
|
|
// invalid DNs go to default handler
|
|
|
|
server.search('', function (req, res, next) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(req.dn)
|
|
|
|
t.equal(typeof (req.dn), 'string')
|
|
|
|
t.equal(req.dn, testDN)
|
|
|
|
res.end()
|
|
|
|
next()
|
|
|
|
})
|
2014-09-30 23:39:19 +00:00
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
server.listen(t.context.sock, function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(true, 'server startup')
|
2019-08-27 18:17:33 +00:00
|
|
|
const clt = ldap.createClient({
|
2019-08-27 13:08:00 +00:00
|
|
|
socketPath: t.context.sock,
|
2014-09-30 23:39:19 +00:00
|
|
|
strictDN: false
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
clt.search(testDN, { scope: 'base' }, function (err, res) {
|
|
|
|
t.error(err)
|
2014-09-30 23:39:19 +00:00
|
|
|
res.on('end', function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
clt.destroy()
|
|
|
|
server.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-08-27 11:57:29 +00:00
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
tap.test('close accept a callback', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const server = ldap.createServer()
|
2019-08-27 13:08:00 +00:00
|
|
|
// callback is called when the server is closed
|
2019-08-27 21:11:49 +00:00
|
|
|
server.listen(0, function (err) {
|
|
|
|
t.error(err)
|
|
|
|
server.close(function (err) {
|
2019-08-27 18:17:33 +00:00
|
|
|
t.error(err)
|
2019-08-27 21:11:49 +00:00
|
|
|
t.end()
|
|
|
|
})
|
2019-08-27 18:17:33 +00:00
|
|
|
})
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2019-08-27 11:57:29 +00:00
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
tap.test('close without error calls callback', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const server = ldap.createServer()
|
2019-08-27 13:08:00 +00:00
|
|
|
// when the server is closed without error, the callback parameter is undefined
|
2019-08-27 21:11:49 +00:00
|
|
|
server.listen(1389, '127.0.0.1', function (err) {
|
|
|
|
t.error(err)
|
|
|
|
server.close(function (err) {
|
|
|
|
t.error(err)
|
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-08-27 13:08:00 +00:00
|
|
|
|
|
|
|
tap.test('close passes error to callback', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const server = ldap.createServer()
|
2019-08-27 13:08:00 +00:00
|
|
|
// when the server is closed with an error, the error is the first parameter of the callback
|
2019-08-27 21:11:49 +00:00
|
|
|
server.close(function (err) {
|
|
|
|
t.ok(err)
|
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
})
|
2021-05-20 14:33:46 +00:00
|
|
|
|
|
|
|
tap.test('multithreading support via external server', function (t) {
|
2021-05-20 16:27:10 +00:00
|
|
|
const serverOptions = { }
|
2021-05-20 14:33:46 +00:00
|
|
|
const server = ldap.createServer(serverOptions)
|
|
|
|
const fauxServer = net.createServer(serverOptions, (connection) => {
|
|
|
|
server.newConnection(connection)
|
|
|
|
})
|
|
|
|
fauxServer.log = serverOptions.log
|
|
|
|
fauxServer.ldap = {
|
|
|
|
config: serverOptions
|
|
|
|
}
|
|
|
|
t.ok(server)
|
|
|
|
fauxServer.listen(5555, 'localhost', function () {
|
|
|
|
t.ok(true, 'server listening on ' + server.url)
|
|
|
|
|
|
|
|
t.ok(fauxServer)
|
|
|
|
const client = ldap.createClient({ url: 'ldap://127.0.0.1:5555' })
|
|
|
|
client.on('connect', function () {
|
|
|
|
t.ok(client)
|
|
|
|
client.unbind()
|
|
|
|
fauxServer.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
tap.test('multithreading support via hook', function (t) {
|
2021-05-20 16:27:10 +00:00
|
|
|
const serverOptions = {
|
2021-05-20 14:33:46 +00:00
|
|
|
connectionRouter: (connection) => {
|
|
|
|
server.newConnection(connection)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const server = ldap.createServer(serverOptions)
|
|
|
|
const fauxServer = ldap.createServer(serverOptions)
|
|
|
|
t.ok(server)
|
|
|
|
fauxServer.listen(0, 'localhost', function () {
|
|
|
|
t.ok(true, 'server listening on ' + server.url)
|
|
|
|
|
|
|
|
t.ok(fauxServer)
|
|
|
|
const client = ldap.createClient({ url: fauxServer.url })
|
|
|
|
client.on('connect', function () {
|
|
|
|
t.ok(client)
|
|
|
|
client.unbind()
|
|
|
|
fauxServer.close(() => t.end())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|