Skip to content

Commit

Permalink
fixup! chore: add localhost lookup test
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Oct 25, 2024
1 parent c09f48e commit 6e839ab
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions test/cli/host-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,12 @@ function checkConnections (t, req, canConnect) {
}
}

test('localhost resolution', (t) => {
console.error('/etc/hosts\n' + fs.readFileSync('/etc/hosts', 'utf8'))
dns.lookup('localhost', (err, address, family) => {
t.error(err)
t.equal('127.0.0.1', address)
t.equal(4, family)
t.end()
})
})

testServer(
'Listening on all ports by default',
[], null,
['127.0.0.1', 'localhost', otherAddress], []
)

testServer(
'Restricted to localhost',
['--localhost'], 'localhost',
['127.0.0.1', 'localhost'], [otherAddress]
)

testServer(
'Restricted to non-local host',
['--host', otherAddress], otherAddress,
Expand All @@ -102,3 +86,14 @@ testServer(
['--host', '127.0.0.1'], '127.0.0.1',
['127.0.0.1'], ['::1']
)

dns.lookup('localhost', (err, address) => {
if (err) {
throw err
}
testServer(
'Restricted to localhost',
['--localhost'], 'localhost',
[address, 'localhost'], [otherAddress]
)
})

0 comments on commit 6e839ab

Please sign in to comment.