Skip to content

Commit

Permalink
Progress on supporting IPv6 (#805)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Max Leiter and jsumners committed Jun 8, 2022
1 parent 9143456 commit 188870d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
10 changes: 9 additions & 1 deletion lib/server.js
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions test/server.test.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 188870d

Please sign in to comment.