Skip to content

Commit 67808e2

Browse files
committed
test: avoid socket remoteAddress in DNS regression
1 parent 306602e commit 67808e2

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

test/interceptors/dns.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ test('Should respect DNS origin hostname for SNI on TLS', async t => {
217217
})
218218

219219
test('#5573 - Should preserve DNS origin hostname on HTTP sockets', async context => {
220-
const t = tspl(context, { plan: 4 })
220+
const t = tspl(context, { plan: 5 })
221221

222222
const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {
223223
res.end('hello world!')
@@ -239,13 +239,11 @@ test('#5573 - Should preserve DNS origin hostname on HTTP sockets', async contex
239239
})
240240

241241
const originalConnect = net.connect
242-
let socket
243242
let connectOptions
244243

245244
net.connect = function (...args) {
246245
connectOptions = args[0]
247-
socket = originalConnect.apply(this, args)
248-
return socket
246+
return originalConnect.apply(this, args)
249247
}
250248
context.after(() => {
251249
net.connect = originalConnect
@@ -260,7 +258,19 @@ test('#5573 - Should preserve DNS origin hostname on HTTP sockets', async contex
260258
t.equal(response.statusCode, 200)
261259
t.equal(await response.body.text(), 'hello world!')
262260
t.equal(connectOptions.host, 'localhost')
263-
t.equal(socket.remoteAddress, '127.0.0.1')
261+
262+
await new Promise((resolve, reject) => {
263+
connectOptions.lookup(connectOptions.host, {}, (err, address, family) => {
264+
if (err) {
265+
reject(err)
266+
return
267+
}
268+
269+
t.equal(address, '127.0.0.1')
270+
t.equal(family, 4)
271+
resolve()
272+
})
273+
})
264274
})
265275

266276
test('Should recover on network errors (dual stack - 4)', async t => {

0 commit comments

Comments
 (0)