Merge pull request #615 from rkaw92/612-tests-unused-tcp-port

This commit is contained in:
James Sumners 2020-05-21 08:05:42 -04:00 committed by GitHub
commit d8c428f1d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 27 deletions

View File

@ -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",

View File

@ -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,40 +1496,44 @@ tap.test('resultError handling', function (t) {
})
tap.test('connection refused', function (t) {
const client = ldap.createClient({
url: 'ldap://0.0.0.0'
})
getPort().then(function (unusedPortNumber) {
const client = ldap.createClient({
url: `ldap://0.0.0.0:${unusedPortNumber}`
})
client.bind('cn=root', 'secret', function (err, res) {
t.true(err)
t.type(err, Error)
t.equals(err.code, 'ECONNREFUSED')
t.false(res)
t.end()
client.bind('cn=root', 'secret', function (err, res) {
t.true(err)
t.type(err, Error)
t.equals(err.code, 'ECONNREFUSED')
t.false(res)
t.end()
})
})
})
tap.test('connection timeout', function (t) {
const client = ldap.createClient({
url: 'ldap://example.org',
connectTimeout: 1,
timeout: 1
})
getPort().then(function (unusedPortNumber) {
const client = ldap.createClient({
url: `ldap://example.org:${unusedPortNumber}`,
connectTimeout: 1,
timeout: 1
})
var done = false
var done = false
setTimeout(function () {
if (!done) {
throw new Error('LDAPJS waited for the server for too long')
}
}, 2000)
setTimeout(function () {
if (!done) {
throw new Error('LDAPJS waited for the server for too long')
}
}, 2000)
client.bind('cn=root', 'secret', function (err, res) {
t.true(err)
t.type(err, Error)
t.equals(err.message, 'connection timeout')
done = true
t.false(res)
t.end()
client.bind('cn=root', 'secret', function (err, res) {
t.true(err)
t.type(err, Error)
t.equals(err.message, 'connection timeout')
done = true
t.false(res)
t.end()
})
})
})