Progress on supporting IPv6 (#805)

* Progress on supporting IPv6

* Apply suggestions from code review

Co-authored-by: James Sumners <james@sumners.email>

* tests: add IPv6 URL format test to server.test.js

Co-authored-by: James Sumners <james@sumners.email>
This commit is contained in:
Max Leiter 2022-06-07 17:59:33 -07:00 committed by GitHub
parent 9143456b4f
commit 188870d7b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View File

@ -508,7 +508,15 @@ Object.defineProperties(Server.prototype, {
} else {
str = 'ldap://'
}
str += this.host + ':' + this.port
let host = this.host
// Node 18 switched family from returning a string to returning a number
// https://nodejs.org/api/net.html#serveraddress
if (addr.family === 'IPv6' || addr.family === 6) {
host = '[' + this.host + ']'
}
str += host + ':' + this.port
return str
},
configurable: false

View File

@ -24,7 +24,7 @@ tap.test('basic create', function (t) {
tap.test('connection count', function (t) {
const server = ldap.createServer()
t.ok(server)
server.listen(0, 'localhost', function () {
server.listen(0, '127.0.0.1', function () {
t.ok(true, 'server listening on ' + server.url)
server.getConnections(function (err, count) {
@ -62,6 +62,17 @@ tap.test('properties', function (t) {
})
})
tap.test('IPv6 URL is formatted correctly', function (t) {
const server = ldap.createServer()
t.equal(server.url, null, 'url empty before bind')
server.listen(0, '::1', function () {
t.ok(server.url)
t.equal(server.url, 'ldap://[::1]:' + server.port)
server.close(() => t.end())
})
})
tap.test('listen on unix/named socket', function (t) {
const server = ldap.createServer()
server.listen(t.context.sock, function () {
@ -437,7 +448,7 @@ tap.test('multithreading support via external server', function (t) {
config: serverOptions
}
t.ok(server)
fauxServer.listen(5555, 'localhost', function () {
fauxServer.listen(5555, '127.0.0.1', function () {
t.ok(true, 'server listening on ' + server.url)
t.ok(fauxServer)
@ -459,7 +470,7 @@ tap.test('multithreading support via hook', function (t) {
const server = ldap.createServer(serverOptions)
const fauxServer = ldap.createServer(serverOptions)
t.ok(server)
fauxServer.listen(0, 'localhost', function () {
fauxServer.listen(0, '127.0.0.1', function () {
t.ok(true, 'server listening on ' + server.url)
t.ok(fauxServer)