Use a random TCP port for testing timeouts/rejects
This fixes a test failure when the host has something listening on the LDAP TCP port. Previously, the test cases would assume that the port was free and they would not connect. For #612
This commit is contained in:
parent
e14cf696a0
commit
c9be815d4f
|
@ -27,6 +27,7 @@
|
|||
"verror": "^1.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"get-port": "^5.1.1",
|
||||
"husky": "^3.0.4",
|
||||
"snazzy": "^8.0.0",
|
||||
"standard": "^14.0.2",
|
||||
|
|
|
@ -5,6 +5,7 @@ const assert = require('assert')
|
|||
const tap = require('tap')
|
||||
const uuid = require('uuid')
|
||||
const vasync = require('vasync')
|
||||
const getPort = require('get-port')
|
||||
const { getSock } = require('./utils')
|
||||
const ldap = require('../lib')
|
||||
const { Attribute, Change } = ldap
|
||||
|
@ -1495,8 +1496,9 @@ tap.test('resultError handling', function (t) {
|
|||
})
|
||||
|
||||
tap.test('connection refused', function (t) {
|
||||
getPort().then(function (unusedPortNumber) {
|
||||
const client = ldap.createClient({
|
||||
url: 'ldap://0.0.0.0'
|
||||
url: `ldap://0.0.0.0:${unusedPortNumber}`
|
||||
})
|
||||
|
||||
client.bind('cn=root', 'secret', function (err, res) {
|
||||
|
@ -1507,10 +1509,12 @@ tap.test('connection refused', function (t) {
|
|||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
tap.test('connection timeout', function (t) {
|
||||
getPort().then(function (unusedPortNumber) {
|
||||
const client = ldap.createClient({
|
||||
url: 'ldap://example.org',
|
||||
url: `ldap://example.org:${unusedPortNumber}`,
|
||||
connectTimeout: 1,
|
||||
timeout: 1
|
||||
})
|
||||
|
@ -1532,3 +1536,4 @@ tap.test('connection timeout', function (t) {
|
|||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue