-
-
Notifications
You must be signed in to change notification settings - Fork 32k
net: exclude ipv6 loopback addresses from server.listen #54264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nodejs-github-bot
merged 10 commits into
nodejs:main
from
puskin:net-exclude-ipv6-loopback-addresses-from-server.listen
Aug 23, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9e65b33
net: exclude ipv6 loopback addresses from server.listen
804842d
net: changed the replacing of the dns module with a proper mock
5dec579
dns: removed copyright from new test and fixed broken one
bbf4e0b
dns: added automated test to check the error emission in lookupAndListen
6a5f988
dns: fixed the broken test. On mac it is failing with a different code
1896a8e
net: checking the whole range of ipv6 link-back addresses
97d8fc3
net: bridging native uv_inet_pton to js to parse ip to binary buffer
puskin 195b631
test: update case of comment in a test
0f8eb48
test: updated the message when ipv6 is not enabled for link-local test
f04cc46
net: formatted cares_wrap.cc to fix linting issue
puskin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
test/sequential/test-net-server-listen-ipv6-link-local.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
const dns = require('dns'); | ||
const { mock } = require('node:test'); | ||
|
||
if (!common.hasIPv6) { | ||
common.printSkipMessage('IPv6 support is required for this test'); | ||
return; | ||
} | ||
|
||
// Test on IPv6 Server, dns.lookup throws an error | ||
{ | ||
mock.method(dns, 'lookup', (hostname, options, callback) => { | ||
callback(new Error('Mocked error')); | ||
}); | ||
const host = 'ipv6_link_local'; | ||
|
||
const server = net.createServer(); | ||
|
||
server.on('error', common.mustCall((e) => { | ||
assert.strictEqual(e.message, 'Mocked error'); | ||
})); | ||
|
||
server.listen(common.PORT + 2, host); | ||
} | ||
|
||
|
||
// Test on IPv6 Server, server.listen throws an error | ||
{ | ||
mock.method(dns, 'lookup', (hostname, options, callback) => { | ||
if (hostname === 'ipv6_link_local') { | ||
callback(null, [{ address: 'fe80::1', family: 6 }]); | ||
} else { | ||
dns.lookup.wrappedMethod(hostname, options, callback); | ||
} | ||
}); | ||
const host = 'ipv6_link_local'; | ||
|
||
const server = net.createServer(); | ||
|
||
server.on('error', common.mustCall((e) => { | ||
assert.strictEqual(e.address, 'fe80::1'); | ||
assert.strictEqual(e.syscall, 'listen'); | ||
})); | ||
|
||
server.listen(common.PORT + 2, host); | ||
} | ||
|
||
// Test on IPv6 Server, picks 127.0.0.1 between that and a bunch of link-local addresses | ||
{ | ||
|
||
mock.method(dns, 'lookup', (hostname, options, callback) => { | ||
if (hostname === 'ipv6_link_local_with_many_entries') { | ||
callback(null, [ | ||
{ address: 'fe80::1', family: 6 }, | ||
{ address: 'fe80::abcd:1234', family: 6 }, | ||
{ address: 'fe80::1ff:fe23:4567:890a', family: 6 }, | ||
{ address: 'fe80::200:5aee:feaa:20a2', family: 6 }, | ||
{ address: 'fe80::f2de:f1ff:fe2b:3c4b', family: 6 }, | ||
{ address: 'fe81::1', family: 6 }, | ||
{ address: 'fe82::abcd:1234', family: 6 }, | ||
{ address: 'fe83::1ff:fe23:4567:890a', family: 6 }, | ||
{ address: 'fe84::200:5aee:feaa:20a2', family: 6 }, | ||
{ address: 'fe85::f2de:f1ff:fe2b:3c4b', family: 6 }, | ||
{ address: 'fe86::1', family: 6 }, | ||
{ address: 'fe87::abcd:1234', family: 6 }, | ||
{ address: 'fe88::1ff:fe23:4567:890a', family: 6 }, | ||
{ address: 'fe89::200:5aee:feaa:20a2', family: 6 }, | ||
{ address: 'fe8a::f2de:f1ff:fe2b:3c4b', family: 6 }, | ||
{ address: 'fe8b::1', family: 6 }, | ||
{ address: 'fe8c::abcd:1234', family: 6 }, | ||
{ address: 'fe8d::1ff:fe23:4567:890a', family: 6 }, | ||
{ address: 'fe8e::200:5aee:feaa:20a2', family: 6 }, | ||
{ address: 'fe8f::f2de:f1ff:fe2b:3c4b', family: 6 }, | ||
{ address: 'fea0::1', family: 6 }, | ||
{ address: 'febf::abcd:1234', family: 6 }, | ||
{ address: 'febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff', family: 6 }, | ||
{ address: '127.0.0.1', family: 4 }, | ||
]); | ||
} else { | ||
dns.lookup.wrappedMethod(hostname, options, callback); | ||
} | ||
}); | ||
|
||
const host = 'ipv6_link_local_with_many_entries'; | ||
|
||
const server = net.createServer(); | ||
|
||
server.on('error', common.mustNotCall()); | ||
|
||
server.listen(common.PORT + 3, host, common.mustCall(() => { | ||
const address = server.address(); | ||
assert.strictEqual(address.address, '127.0.0.1'); | ||
assert.strictEqual(address.port, common.PORT + 3); | ||
assert.strictEqual(address.family, 'IPv4'); | ||
server.close(); | ||
})); | ||
} | ||
|
||
|
||
// Test on IPv6 Server, picks ::1 because the other address is a link-local address | ||
{ | ||
|
||
const host = 'ipv6_link_local_with_double_entry'; | ||
const validIpv6Address = '::1'; | ||
|
||
mock.method(dns, 'lookup', (hostname, options, callback) => { | ||
if (hostname === 'ipv6_link_local_with_double_entry') { | ||
callback(null, [ | ||
{ address: 'fe80::1', family: 6 }, | ||
{ address: validIpv6Address, family: 6 }, | ||
]); | ||
} else { | ||
dns.lookup.wrappedMethod(hostname, options, callback); | ||
} | ||
}); | ||
|
||
const server = net.createServer(); | ||
|
||
server.on('error', common.mustNotCall()); | ||
|
||
server.listen(common.PORT + 4, host, common.mustCall(() => { | ||
const address = server.address(); | ||
assert.strictEqual(address.address, validIpv6Address); | ||
assert.strictEqual(address.port, common.PORT + 4); | ||
assert.strictEqual(address.family, 'IPv6'); | ||
server.close(); | ||
})); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.