diff options
Diffstat (limited to 'tests/node_compat/test/internet')
11 files changed, 1760 insertions, 0 deletions
diff --git a/tests/node_compat/test/internet/package.json b/tests/node_compat/test/internet/package.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/tests/node_compat/test/internet/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/node_compat/test/internet/test-dns-any.js b/tests/node_compat/test/internet/test-dns-any.js new file mode 100644 index 000000000..b8a70b8e2 --- /dev/null +++ b/tests/node_compat/test/internet/test-dns-any.js @@ -0,0 +1,194 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 16.13.0 +// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually + +// TODO(cmorten): enable remaining tests once functionality is implemented. + +'use strict'; + +const common = require('../common'); + +const assert = require('assert'); +const dns = require('dns'); +const net = require('net'); + +let running = false; +const queue = []; + +const dnsPromises = dns.promises; +const isIPv4 = net.isIPv4; +const isIPv6 = net.isIPv6; + +dns.setServers([ '8.8.8.8', '8.8.4.4' ]); + +function checkWrap(req) { + assert.ok(typeof req === 'object'); +} + +const checkers = { + checkA(r) { + assert.ok(isIPv4(r.address)); + // assert.strictEqual(typeof r.ttl, 'number'); + assert.strictEqual(r.type, 'A'); + }, + checkAAAA(r) { + assert.ok(isIPv6(r.address)); + // assert.strictEqual(typeof r.ttl, 'number'); + assert.strictEqual(r.type, 'AAAA'); + }, + checkCNAME(r) { + assert.ok(r.value); + assert.strictEqual(typeof r.value, 'string'); + assert.strictEqual(r.type, 'CNAME'); + }, + checkMX(r) { + assert.strictEqual(typeof r.exchange, 'string'); + assert.strictEqual(typeof r.priority, 'number'); + assert.strictEqual(r.type, 'MX'); + }, + checkNAPTR(r) { + assert.strictEqual(typeof r.flags, 'string'); + assert.strictEqual(typeof r.service, 'string'); + assert.strictEqual(typeof r.regexp, 'string'); + assert.strictEqual(typeof r.replacement, 'string'); + assert.strictEqual(typeof r.order, 'number'); + assert.strictEqual(typeof r.preference, 'number'); + assert.strictEqual(r.type, 'NAPTR'); + }, + checkNS(r) { + assert.strictEqual(typeof r.value, 'string'); + assert.strictEqual(r.type, 'NS'); + }, + checkPTR(r) { + assert.strictEqual(typeof r.value, 'string'); + assert.strictEqual(r.type, 'PTR'); + }, + checkTXT(r) { + assert.ok(Array.isArray(r.entries)); + assert.ok(r.entries.length > 0); + assert.strictEqual(r.type, 'TXT'); + }, + checkSOA(r) { + assert.strictEqual(typeof r.nsname, 'string'); + assert.strictEqual(typeof r.hostmaster, 'string'); + assert.strictEqual(typeof r.serial, 'number'); + assert.strictEqual(typeof r.refresh, 'number'); + assert.strictEqual(typeof r.retry, 'number'); + assert.strictEqual(typeof r.expire, 'number'); + assert.strictEqual(typeof r.minttl, 'number'); + assert.strictEqual(r.type, 'SOA'); + }, + checkSRV(r) { + assert.strictEqual(typeof r.name, 'string'); + assert.strictEqual(typeof r.port, 'number'); + assert.strictEqual(typeof r.priority, 'number'); + assert.strictEqual(typeof r.weight, 'number'); + assert.strictEqual(r.type, 'SRV'); + } +}; + +function TEST(f) { + function next() { + const f = queue.shift(); + if (f) { + running = true; + f(done); + } + } + + function done() { + running = false; + process.nextTick(next); + } + + queue.push(f); + + if (!running) { + next(); + } +} + +function processResult(res) { + assert.ok(Array.isArray(res)); + assert.ok(res.length > 0); + + const types = {}; + res.forEach((obj) => { + types[obj.type] = true; + checkers[`check${obj.type}`](obj); + }); + + return types; +} + +TEST(async function test_sip2sip_for_naptr(done) { + function validateResult(res) { + const types = processResult(res); + assert.ok( + types.A && types.NS && types.NAPTR && types.SOA, + `Missing record type, found ${Object.keys(types)}` + ); + } + + validateResult(await dnsPromises.resolve('sip2sip.info', 'ANY')); + + const req = dns.resolve( + 'sip2sip.info', + 'ANY', + common.mustSucceed((ret) => { + validateResult(ret); + done(); + })); + + checkWrap(req); +}); + +TEST(async function test_google_for_cname_and_srv(done) { + function validateResult(res) { + const types = processResult(res); + assert.ok(types.SRV); + } + + // TODO(kt3k): Temporarily use _caldav._tcp.google.com instead of + // _jabber._tcp.google.com, which currently doesn't respond + // validateResult(await dnsPromises.resolve('_jabber._tcp.google.com', 'ANY')); + validateResult(await dnsPromises.resolve('_caldav._tcp.google.com', 'ANY')); + + + // TODO(kt3k): Temporarily use _caldav._tcp.google.com instead of + // _jabber._tcp.google.com, which currently doesn't respond + const req = dns.resolve( + // '_jabber._tcp.google.com', + '_caldav._tcp.google.com', + 'ANY', + common.mustSucceed((ret) => { + validateResult(ret); + done(); + })); + + checkWrap(req); +}); + +// TODO(bartlomieju): this test started failing on CI on Dec 28th, 2023 returning +// ENOTFOUND. It's unclear what's going on, since `dig -x 8.8.8.8.in-addr.arpa` +// TEST(async function test_ptr(done) { +// function validateResult(res) { +// const types = processResult(res); +// assert.ok(types.PTR); +// } + +// validateResult(await dnsPromises.resolve('8.8.8.8.in-addr.arpa', 'ANY')); + +// const req = dns.resolve( +// '8.8.8.8.in-addr.arpa', +// 'ANY', +// common.mustSucceed((ret) => { +// validateResult(ret); +// done(); +// })); + +// checkWrap(req); +// }); diff --git a/tests/node_compat/test/internet/test-dns-idna2008.js b/tests/node_compat/test/internet/test-dns-idna2008.js new file mode 100644 index 000000000..7308f9deb --- /dev/null +++ b/tests/node_compat/test/internet/test-dns-idna2008.js @@ -0,0 +1,76 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by `tools/node_compat/setup.ts`. Do not modify this file manually. + +'use strict'; + +// Verify that non-ASCII hostnames are handled correctly as IDNA 2008. +// +// * Tests will fail with NXDOMAIN when UTF-8 leaks through to a getaddrinfo() +// that doesn't support IDNA at all. +// +// * "straße.de" will resolve to the wrong address when the resolver supports +// only IDNA 2003 (e.g., glibc until 2.28) because it encodes it wrong. + +const { mustCall } = require('../common'); +const assert = require('assert'); +const dns = require('dns'); +const { addresses } = require('../common/internet'); + +const fixture = { + hostname: 'straße.de', + expectedAddress: '81.169.145.78', + dnsServer: addresses.DNS4_SERVER, + family: 4, +}; + +// Explicitly use well-behaved DNS servers that are known to be able to resolve +// the query (which is a.k.a xn--strae-oqa.de). +dns.setServers([fixture.dnsServer]); + +dns.lookup( + fixture.hostname, + { family: fixture.family }, + mustCall((err, address) => { + if (err && err.errno === 'ESERVFAIL') { + assert.ok(err.message.includes('queryA ESERVFAIL straße.de')); + return; + } + assert.ifError(err); + assert.strictEqual(address, fixture.expectedAddress); + }), +); + +dns.promises.lookup(fixture.hostname, { family: fixture.family }) + .then(({ address }) => { + assert.strictEqual(address, fixture.expectedAddress); + }, (err) => { + if (err && err.errno === 'ESERVFAIL') { + assert.ok(err.message.includes('queryA ESERVFAIL straße.de')); + } else { + throw err; + } + }).finally(mustCall()); + +dns.resolve4(fixture.hostname, mustCall((err, addresses) => { + if (err && err.errno === 'ESERVFAIL') { + assert.ok(err.message.includes('queryA ESERVFAIL straße.de')); + return; + } + assert.ifError(err); + assert.deepStrictEqual(addresses, [fixture.expectedAddress]); +})); + +const p = new dns.promises.Resolver().resolve4(fixture.hostname); +p.then((addresses) => { + assert.deepStrictEqual(addresses, [fixture.expectedAddress]); +}, (err) => { + if (err && err.errno === 'ESERVFAIL') { + assert.ok(err.message.includes('queryA ESERVFAIL straße.de')); + } else { + throw err; + } +}).finally(mustCall()); diff --git a/tests/node_compat/test/internet/test-dns-ipv4.js b/tests/node_compat/test/internet/test-dns-ipv4.js new file mode 100644 index 000000000..43b60950a --- /dev/null +++ b/tests/node_compat/test/internet/test-dns-ipv4.js @@ -0,0 +1,257 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 16.13.0 +// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually + +'use strict'; + +// TODO: enable remaining tests once functionality is implemented. + +const common = require('../common'); +const { addresses } = require('../common/internet'); +const assert = require('assert'); +const dns = require('dns'); +const net = require('net'); +// const util = require('util'); +const isIPv4 = net.isIPv4; + +const dnsPromises = dns.promises; +let running = false; +const queue = []; + +function TEST(f) { + function next() { + const f = queue.shift(); + if (f) { + running = true; + console.log(f.name); + f(done); + } + } + + function done() { + running = false; + process.nextTick(next); + } + + queue.push(f); + + if (!running) { + next(); + } +} + +function checkWrap(req) { + assert.ok(typeof req === 'object'); +} + +TEST(async function test_resolve4(done) { + function validateResult(res) { + assert.ok(res.length > 0); + + for (let i = 0; i < res.length; i++) { + assert.ok(isIPv4(res[i])); + } + } + + validateResult(await dnsPromises.resolve4(addresses.INET4_HOST)); + + const req = dns.resolve4( + addresses.INET4_HOST, + common.mustSucceed((ips) => { + validateResult(ips); + done(); + })); + + checkWrap(req); +}); + +// TEST(async function test_reverse_ipv4(done) { +// function validateResult(res) { +// assert.ok(res.length > 0); + +// for (let i = 0; i < res.length; i++) { +// assert.ok(res[i]); +// assert.ok(typeof res[i] === 'string'); +// } +// } + +// validateResult(await dnsPromises.reverse(addresses.INET4_IP)); + +// const req = dns.reverse( +// addresses.INET4_IP, +// common.mustSucceed((domains) => { +// validateResult(domains); +// done(); +// })); + +// checkWrap(req); +// }); + +TEST(async function test_lookup_ipv4_explicit(done) { + function validateResult(res) { + assert.ok(net.isIPv4(res.address)); + assert.strictEqual(res.family, 4); + } + + validateResult(await dnsPromises.lookup(addresses.INET4_HOST, 4)); + + const req = dns.lookup( + addresses.INET4_HOST, 4, + common.mustSucceed((ip, family) => { + validateResult({ address: ip, family }); + done(); + })); + + checkWrap(req); +}); + +TEST(async function test_lookup_ipv4_implicit(done) { + function validateResult(res) { + assert.ok(net.isIPv4(res.address)); + assert.strictEqual(res.family, 4); + } + + validateResult(await dnsPromises.lookup(addresses.INET4_HOST)); + + const req = dns.lookup( + addresses.INET4_HOST, + common.mustSucceed((ip, family) => { + validateResult({ address: ip, family }); + done(); + })); + + checkWrap(req); +}); + +TEST(async function test_lookup_ipv4_explicit_object(done) { + function validateResult(res) { + assert.ok(net.isIPv4(res.address)); + assert.strictEqual(res.family, 4); + } + + validateResult(await dnsPromises.lookup(addresses.INET4_HOST, { family: 4 })); + + const req = dns.lookup(addresses.INET4_HOST, { + family: 4 + }, common.mustSucceed((ip, family) => { + validateResult({ address: ip, family }); + done(); + })); + + checkWrap(req); +}); + +TEST(async function test_lookup_ipv4_hint_addrconfig(done) { + function validateResult(res) { + assert.ok(net.isIPv4(res.address)); + assert.strictEqual(res.family, 4); + } + + validateResult(await dnsPromises.lookup(addresses.INET4_HOST, { + hints: dns.ADDRCONFIG + })); + + const req = dns.lookup(addresses.INET4_HOST, { + hints: dns.ADDRCONFIG + }, common.mustSucceed((ip, family) => { + validateResult({ address: ip, family }); + done(); + })); + + checkWrap(req); +}); + +TEST(async function test_lookup_ip_ipv4(done) { + function validateResult(res) { + assert.strictEqual(res.address, '127.0.0.1'); + assert.strictEqual(res.family, 4); + } + + validateResult(await dnsPromises.lookup('127.0.0.1')); + + const req = dns.lookup('127.0.0.1', + common.mustSucceed((ip, family) => { + validateResult({ address: ip, family }); + done(); + })); + + checkWrap(req); +}); + +TEST(async function test_lookup_localhost_ipv4(done) { + function validateResult(res) { + assert.strictEqual(res.address, '127.0.0.1'); + assert.strictEqual(res.family, 4); + } + + validateResult(await dnsPromises.lookup('localhost', 4)); + + const req = dns.lookup('localhost', 4, + common.mustSucceed((ip, family) => { + validateResult({ address: ip, family }); + done(); + })); + + checkWrap(req); +}); + +TEST(async function test_lookup_all_ipv4(done) { + function validateResult(res) { + assert.ok(Array.isArray(res)); + assert.ok(res.length > 0); + + res.forEach((ip) => { + assert.ok(isIPv4(ip.address)); + assert.strictEqual(ip.family, 4); + }); + } + + validateResult(await dnsPromises.lookup(addresses.INET4_HOST, { + all: true, + family: 4 + })); + + const req = dns.lookup( + addresses.INET4_HOST, + { all: true, family: 4 }, + common.mustSucceed((ips) => { + validateResult(ips); + done(); + }) + ); + + checkWrap(req); +}); + +// TEST(async function test_lookupservice_ip_ipv4(done) { +// function validateResult(res) { +// assert.strictEqual(typeof res.hostname, 'string'); +// assert(res.hostname); +// assert(['http', 'www', '80'].includes(res.service)); +// } + +// validateResult(await dnsPromises.lookupService('127.0.0.1', 80)); + +// const req = dns.lookupService( +// '127.0.0.1', 80, +// common.mustSucceed((hostname, service) => { +// validateResult({ hostname, service }); +// done(); +// }) +// ); + +// checkWrap(req); +// }); + +// TEST(function test_lookupservice_ip_ipv4_promise(done) { +// util.promisify(dns.lookupService)('127.0.0.1', 80) +// .then(common.mustCall(({ hostname, service }) => { +// assert.strictEqual(typeof hostname, 'string'); +// assert(hostname.length > 0); +// assert(['http', 'www', '80'].includes(service)); +// done(); +// })); +// }); diff --git a/tests/node_compat/test/internet/test-dns-ipv6.js b/tests/node_compat/test/internet/test-dns-ipv6.js new file mode 100644 index 000000000..4b94d6041 --- /dev/null +++ b/tests/node_compat/test/internet/test-dns-ipv6.js @@ -0,0 +1,250 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 16.13.0 +// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually + +'use strict'; + +// TODO: enable remaining tests once functionality is implemented. + +const common = require('../common'); +const { addresses } = require('../common/internet'); +if (!common.hasIPv6) + common.skip('this test, no IPv6 support'); + +const assert = require('assert'); +const dns = require('dns'); +const net = require('net'); +const dnsPromises = dns.promises; +const isIPv6 = net.isIPv6; + +let running = false; +const queue = []; + +function TEST(f) { + function next() { + const f = queue.shift(); + if (f) { + running = true; + console.log(f.name); + f(done); + } + } + + function done() { + running = false; + process.nextTick(next); + } + + queue.push(f); + + if (!running) { + next(); + } +} + +function checkWrap(req) { + assert.ok(typeof req === 'object'); +} + +TEST(async function test_resolve6(done) { + function validateResult(res) { + assert.ok(res.length > 0); + + for (let i = 0; i < res.length; i++) { + assert.ok(isIPv6(res[i])); + } + } + + validateResult(await dnsPromises.resolve6(addresses.INET6_HOST)); + + const req = dns.resolve6( + addresses.INET6_HOST, + common.mustSucceed((ips) => { + validateResult(ips); + done(); + })); + + checkWrap(req); +}); + +// TEST(async function test_reverse_ipv6(done) { +// function validateResult(res) { +// assert.ok(res.length > 0); + +// for (let i = 0; i < res.length; i++) { +// assert.ok(typeof res[i] === 'string'); +// } +// } + +// validateResult(await dnsPromises.reverse(addresses.INET6_IP)); + +// const req = dns.reverse( +// addresses.INET6_IP, +// common.mustSucceed((domains) => { +// validateResult(domains); +// done(); +// })); + +// checkWrap(req); +// }); + +TEST(async function test_lookup_ipv6_explicit(done) { + function validateResult(res) { + assert.ok(isIPv6(res.address)); + assert.strictEqual(res.family, 6); + } + + validateResult(await dnsPromises.lookup(addresses.INET6_HOST, 6)); + + const req = dns.lookup( + addresses.INET6_HOST, + 6, + common.mustSucceed((ip, family) => { + validateResult({ address: ip, family }); + done(); + })); + + checkWrap(req); +}); + +// This ends up just being too problematic to test +// TEST(function test_lookup_ipv6_implicit(done) { +// var req = dns.lookup(addresses.INET6_HOST, function(err, ip, family) { +// assert.ifError(err); +// assert.ok(net.isIPv6(ip)); +// assert.strictEqual(family, 6); + +// done(); +// }); + +// checkWrap(req); +// }); + +TEST(async function test_lookup_ipv6_explicit_object(done) { + function validateResult(res) { + assert.ok(isIPv6(res.address)); + assert.strictEqual(res.family, 6); + } + + validateResult(await dnsPromises.lookup(addresses.INET6_HOST, { family: 6 })); + + const req = dns.lookup(addresses.INET6_HOST, { + family: 6 + }, common.mustSucceed((ip, family) => { + validateResult({ address: ip, family }); + done(); + })); + + checkWrap(req); +}); + +TEST(function test_lookup_ipv6_hint(done) { + const req = dns.lookup(addresses.INET6_HOST, { + family: 6, + hints: dns.V4MAPPED + }, common.mustCall((err, ip, family) => { + if (err) { + // FreeBSD does not support V4MAPPED + if (common.isFreeBSD) { + assert(err instanceof Error); + assert.strictEqual(err.code, 'EAI_BADFLAGS'); + assert.strictEqual(err.hostname, addresses.INET_HOST); + assert.match(err.message, /getaddrinfo EAI_BADFLAGS/); + done(); + return; + } + + assert.ifError(err); + } + + assert.ok(isIPv6(ip)); + assert.strictEqual(family, 6); + + done(); + })); + + checkWrap(req); +}); + +TEST(async function test_lookup_ip_ipv6(done) { + function validateResult(res) { + assert.ok(isIPv6(res.address)); + assert.strictEqual(res.family, 6); + } + + validateResult(await dnsPromises.lookup('::1')); + + const req = dns.lookup( + '::1', + common.mustSucceed((ip, family) => { + validateResult({ address: ip, family }); + done(); + })); + + checkWrap(req); +}); + +TEST(async function test_lookup_all_ipv6(done) { + function validateResult(res) { + assert.ok(Array.isArray(res)); + assert.ok(res.length > 0); + + res.forEach((ip) => { + assert.ok(isIPv6(ip.address), + `Invalid IPv6: ${ip.address.toString()}`); + assert.strictEqual(ip.family, 6); + }); + } + + validateResult(await dnsPromises.lookup(addresses.INET6_HOST, { + all: true, + family: 6 + })); + + const req = dns.lookup( + addresses.INET6_HOST, + { all: true, family: 6 }, + common.mustSucceed((ips) => { + validateResult(ips); + done(); + }) + ); + + checkWrap(req); +}); + +// TEST(function test_lookupservice_ip_ipv6(done) { +// const req = dns.lookupService( +// '::1', 80, +// common.mustCall((err, host, service) => { +// if (err) { +// // Not skipping the test, rather checking an alternative result, +// // i.e. that ::1 may not be configured (e.g. in /etc/hosts) +// assert.strictEqual(err.code, 'ENOTFOUND'); +// return done(); +// } +// assert.strictEqual(typeof host, 'string'); +// assert(host); +// assert(['http', 'www', '80'].includes(service)); +// done(); +// }) +// ); + +// checkWrap(req); +// }); + +// Disabled because it appears to be not working on Linux. +// TEST(function test_lookup_localhost_ipv6(done) { +// var req = dns.lookup('localhost', 6, function(err, ip, family) { +// assert.ifError(err); +// assert.ok(net.isIPv6(ip)); +// assert.strictEqual(family, 6); +// +// done(); +// }); +// +// checkWrap(req); +// }); diff --git a/tests/node_compat/test/internet/test-dns-lookup.js b/tests/node_compat/test/internet/test-dns-lookup.js new file mode 100644 index 000000000..cfd3e758c --- /dev/null +++ b/tests/node_compat/test/internet/test-dns-lookup.js @@ -0,0 +1,61 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by `tools/node_compat/setup.ts`. Do not modify this file manually. + +'use strict'; + +require('../common'); +const common = require('../common'); +const dns = require('dns'); +const dnsPromises = dns.promises; +const { addresses } = require('../common/internet'); +const assert = require('assert'); + +assert.rejects( + dnsPromises.lookup(addresses.NOT_FOUND, { + hints: 0, + family: 0, + all: false, + }), + { + code: 'ENOTFOUND', + message: `getaddrinfo ENOTFOUND ${addresses.NOT_FOUND}`, + }, +); + +assert.rejects( + dnsPromises.lookup(addresses.NOT_FOUND, { + hints: 0, + family: 0, + all: true, + }), + { + code: 'ENOTFOUND', + message: `getaddrinfo ENOTFOUND ${addresses.NOT_FOUND}`, + }, +); + +dns.lookup(addresses.NOT_FOUND, { + hints: 0, + family: 0, + all: true, +}, common.mustCall((error) => { + assert.strictEqual(error.code, 'ENOTFOUND'); + assert.strictEqual( + error.message, + `getaddrinfo ENOTFOUND ${addresses.NOT_FOUND}`, + ); + assert.strictEqual(error.syscall, 'getaddrinfo'); + assert.strictEqual(error.hostname, addresses.NOT_FOUND); +})); + +assert.throws( + () => dnsPromises.lookup(addresses.NOT_FOUND, { + family: 'ipv4', + all: 'all', + }), + { code: 'ERR_INVALID_ARG_VALUE' }, +); diff --git a/tests/node_compat/test/internet/test-dns-promises-resolve.js b/tests/node_compat/test/internet/test-dns-promises-resolve.js new file mode 100644 index 000000000..e4ee5f782 --- /dev/null +++ b/tests/node_compat/test/internet/test-dns-promises-resolve.js @@ -0,0 +1,49 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by `tools/node_compat/setup.ts`. Do not modify this file manually. + +'use strict'; +const common = require('../common'); +const assert = require('assert'); + +const dnsPromises = require('dns').promises; + +// Error when rrtype is invalid. +{ + const rrtype = 'DUMMY'; + assert.throws( + () => dnsPromises.resolve('example.org', rrtype), + { + code: 'ERR_INVALID_ARG_VALUE', + name: 'TypeError', + message: `The argument 'rrtype' is invalid. Received '${rrtype}'`, + }, + ); +} + +// Error when rrtype is a number. +{ + const rrtype = 0; + assert.throws( + () => dnsPromises.resolve('example.org', rrtype), + { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + message: 'The "rrtype" argument must be of type string. ' + + `Received type ${typeof rrtype} (${rrtype})`, + }, + ); +} + +// Setting rrtype to undefined should work like resolve4. +{ + (async function() { + const rrtype = undefined; + const result = await dnsPromises.resolve('example.org', rrtype); + assert.ok(result !== undefined); + assert.ok(result.length > 0); + })().then(common.mustCall()); +} diff --git a/tests/node_compat/test/internet/test-dns-regress-6244.js b/tests/node_compat/test/internet/test-dns-regress-6244.js new file mode 100644 index 000000000..988cf21ee --- /dev/null +++ b/tests/node_compat/test/internet/test-dns-regress-6244.js @@ -0,0 +1,35 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by `tools/node_compat/setup.ts`. Do not modify this file manually. + +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; +const common = require('../common'); +const dns = require('dns'); + +// Should not segfault. +// Ref: https://github.com/nodejs/node-v0.x-archive/issues/6244 +dns.resolve4('127.0.0.1', common.mustCall()); diff --git a/tests/node_compat/test/internet/test-dns-setserver-in-callback-of-resolve4.js b/tests/node_compat/test/internet/test-dns-setserver-in-callback-of-resolve4.js new file mode 100644 index 000000000..b4360c205 --- /dev/null +++ b/tests/node_compat/test/internet/test-dns-setserver-in-callback-of-resolve4.js @@ -0,0 +1,25 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by `tools/node_compat/setup.ts`. Do not modify this file manually. + +'use strict'; + +// We don't care about `err` in the callback function of `dns.resolve4`. We just +// want to test whether `dns.setServers` that is run after `resolve4` will cause +// a crash or not. If it doesn't crash, the test succeeded. + +const common = require('../common'); +const { addresses } = require('../common/internet'); +const dns = require('dns'); + +dns.resolve4( + addresses.INET4_HOST, + common.mustCall(function(/* err, nameServers */) { + dns.setServers([ addresses.DNS4_SERVER ]); + })); + +// Test https://github.com/nodejs/node/issues/14734 +dns.resolve4(addresses.INET4_HOST, common.mustCall()); diff --git a/tests/node_compat/test/internet/test-dns.js b/tests/node_compat/test/internet/test-dns.js new file mode 100644 index 000000000..8aaeb728d --- /dev/null +++ b/tests/node_compat/test/internet/test-dns.js @@ -0,0 +1,766 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 16.13.0 +// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually + +// Flags: --expose-internals +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; + +// TODO(cmorten): enable remaining tests once functionality is implemented. + +const common = require('../common'); +const { addresses } = require('../common/internet'); +const { internalBinding } = require('internal/test/binding'); +// const { getSystemErrorName } = require('util'); +const assert = require('assert'); +const dns = require('dns'); +const net = require('net'); +const isIPv4 = net.isIPv4; +const isIPv6 = net.isIPv6; +const util = require('util'); +const dnsPromises = dns.promises; + +let expected = 0; +let completed = 0; +let running = false; +const queue = []; + + +function TEST(f) { + function next() { + const f = queue.shift(); + if (f) { + running = true; + console.log(f.name); + f(done); + } + } + + function done() { + running = false; + completed++; + process.nextTick(next); + } + + expected++; + queue.push(f); + + if (!running) { + next(); + } +} + + +function checkWrap(req) { + assert.strictEqual(typeof req, 'object'); +} + + +// TEST(function test_reverse_bogus(done) { +// dnsPromises.reverse('bogus ip') +// .then(common.mustNotCall()) +// .catch(common.mustCall((err) => { +// assert.strictEqual(err.code, 'EINVAL'); +// assert.strictEqual(getSystemErrorName(err.errno), 'EINVAL'); +// })); + +// assert.throws(() => { +// dns.reverse('bogus ip', common.mustNotCall()); +// }, /^Error: getHostByAddr EINVAL bogus ip$/); +// done(); +// }); + +// TEST(async function test_resolve4_ttl(done) { +// function validateResult(result) { +// assert.ok(result.length > 0); + +// for (const item of result) { +// assert.strictEqual(typeof item, 'object'); +// assert.strictEqual(typeof item.ttl, 'number'); +// assert.strictEqual(typeof item.address, 'string'); +// assert.ok(item.ttl >= 0); +// assert.ok(isIPv4(item.address)); +// } +// } + +// validateResult(await dnsPromises.resolve4(addresses.INET4_HOST, { +// ttl: true +// })); + +// const req = dns.resolve4(addresses.INET4_HOST, { +// ttl: true +// }, function(err, result) { +// assert.ifError(err); +// validateResult(result); +// done(); +// }); + +// checkWrap(req); +// }); + +// TEST(async function test_resolve6_ttl(done) { +// function validateResult(result) { +// assert.ok(result.length > 0); + +// for (const item of result) { +// assert.strictEqual(typeof item, 'object'); +// assert.strictEqual(typeof item.ttl, 'number'); +// assert.strictEqual(typeof item.address, 'string'); +// assert.ok(item.ttl >= 0); +// assert.ok(isIPv6(item.address)); +// } +// } + +// validateResult(await dnsPromises.resolve6(addresses.INET6_HOST, { +// ttl: true +// })); + +// const req = dns.resolve6(addresses.INET6_HOST, { +// ttl: true +// }, function(err, result) { +// assert.ifError(err); +// validateResult(result); +// done(); +// }); + +// checkWrap(req); +// }); + +TEST(async function test_resolveMx(done) { + function validateResult(result) { + assert.ok(result.length > 0); + + for (const item of result) { + assert.strictEqual(typeof item, 'object'); + assert.ok(item.exchange); + assert.strictEqual(typeof item.exchange, 'string'); + assert.strictEqual(typeof item.priority, 'number'); + } + } + + validateResult(await dnsPromises.resolveMx(addresses.MX_HOST)); + + const req = dns.resolveMx(addresses.MX_HOST, function(err, result) { + assert.ifError(err); + validateResult(result); + done(); + }); + + checkWrap(req); +}); + +// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN` +// instead of `ENOTFOUND`. +// TEST(function test_resolveMx_failure(done) { +// dnsPromises.resolveMx(addresses.NOT_FOUND) +// .then(common.mustNotCall()) +// .catch(common.mustCall((err) => { +// assert.strictEqual(err.code, 'ENOTFOUND'); +// })); + +// const req = dns.resolveMx(addresses.NOT_FOUND, function(err, result) { +// assert.ok(err instanceof Error); +// assert.strictEqual(err.code, 'ENOTFOUND'); + +// assert.strictEqual(result, undefined); + +// done(); +// }); + +// checkWrap(req); +// }); + +TEST(async function test_resolveNs(done) { + function validateResult(result) { + assert.ok(result.length > 0); + + for (const item of result) { + assert.ok(item); + assert.strictEqual(typeof item, 'string'); + } + } + + validateResult(await dnsPromises.resolveNs(addresses.NS_HOST)); + + const req = dns.resolveNs(addresses.NS_HOST, function(err, names) { + assert.ifError(err); + validateResult(names); + done(); + }); + + checkWrap(req); +}); + +// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN` +// instead of `ENOTFOUND`. +// TEST(function test_resolveNs_failure(done) { +// dnsPromises.resolveNs(addresses.NOT_FOUND) +// .then(common.mustNotCall()) +// .catch(common.mustCall((err) => { +// assert.strictEqual(err.code, 'ENOTFOUND'); +// })); + +// const req = dns.resolveNs(addresses.NOT_FOUND, function(err, result) { +// assert.ok(err instanceof Error); +// assert.strictEqual(err.code, 'ENOTFOUND'); + +// assert.strictEqual(result, undefined); + +// done(); +// }); + +// checkWrap(req); +// }); + +TEST(async function test_resolveSrv(done) { + function validateResult(result) { + assert.ok(result.length > 0); + + for (const item of result) { + assert.strictEqual(typeof item, 'object'); + assert.ok(item.name); + assert.strictEqual(typeof item.name, 'string'); + assert.strictEqual(typeof item.port, 'number'); + assert.strictEqual(typeof item.priority, 'number'); + assert.strictEqual(typeof item.weight, 'number'); + } + } + + validateResult(await dnsPromises.resolveSrv(addresses.SRV_HOST)); + + const req = dns.resolveSrv(addresses.SRV_HOST, function(err, result) { + assert.ifError(err); + validateResult(result); + done(); + }); + + checkWrap(req); +}); + +// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN` +// instead of `ENOTFOUND`. +// TEST(function test_resolveSrv_failure(done) { +// dnsPromises.resolveSrv(addresses.NOT_FOUND) +// .then(common.mustNotCall()) +// .catch(common.mustCall((err) => { +// assert.strictEqual(err.code, 'ENOTFOUND'); +// })); + +// const req = dns.resolveSrv(addresses.NOT_FOUND, function(err, result) { +// assert.ok(err instanceof Error); +// assert.strictEqual(err.code, 'ENOTFOUND'); + +// assert.strictEqual(result, undefined); + +// done(); +// }); + +// checkWrap(req); +// }); + +// TODO(bartlomieju): this test started failing on CI on Dec 28th, 2023 returning +// ENOTFOUND. It's unclear what's going on, since `dig -x 8.8.8.8.in-addr.arpa` +// returns correct PTR record. +// TEST(async function test_resolvePtr(done) { +// function validateResult(result) { +// assert.ok(result.length > 0); + +// for (const item of result) { +// assert.ok(item); +// assert.strictEqual(typeof item, 'string'); +// } +// } + +// validateResult(await dnsPromises.resolvePtr(addresses.PTR_HOST)); + +// const req = dns.resolvePtr(addresses.PTR_HOST, function(err, result) { +// assert.ifError(err); +// validateResult(result); +// done(); +// }); + +// checkWrap(req); +// }); + +// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN` +// instead of `ENOTFOUND`. +// TEST(function test_resolvePtr_failure(done) { +// dnsPromises.resolvePtr(addresses.NOT_FOUND) +// .then(common.mustNotCall()) +// .catch(common.mustCall((err) => { +// assert.strictEqual(err.code, 'ENOTFOUND'); +// })); + +// const req = dns.resolvePtr(addresses.NOT_FOUND, function(err, result) { +// assert.ok(err instanceof Error); +// assert.strictEqual(err.code, 'ENOTFOUND'); + +// assert.strictEqual(result, undefined); + +// done(); +// }); + +// checkWrap(req); +// }); + +TEST(async function test_resolveNaptr(done) { + function validateResult(result) { + assert.ok(result.length > 0); + + for (const item of result) { + assert.strictEqual(typeof item, 'object'); + assert.strictEqual(typeof item.flags, 'string'); + assert.strictEqual(typeof item.service, 'string'); + assert.strictEqual(typeof item.regexp, 'string'); + assert.strictEqual(typeof item.replacement, 'string'); + assert.strictEqual(typeof item.order, 'number'); + assert.strictEqual(typeof item.preference, 'number'); + } + } + + validateResult(await dnsPromises.resolveNaptr(addresses.NAPTR_HOST)); + + const req = dns.resolveNaptr(addresses.NAPTR_HOST, function(err, result) { + assert.ifError(err); + validateResult(result); + done(); + }); + + checkWrap(req); +}); + +// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN` +// instead of `ENOTFOUND`. +// TEST(function test_resolveNaptr_failure(done) { +// dnsPromises.resolveNaptr(addresses.NOT_FOUND) +// .then(common.mustNotCall()) +// .catch(common.mustCall((err) => { +// assert.strictEqual(err.code, 'ENOTFOUND'); +// })); + +// const req = dns.resolveNaptr(addresses.NOT_FOUND, function(err, result) { +// assert.ok(err instanceof Error); +// assert.strictEqual(err.code, 'ENOTFOUND'); + +// assert.strictEqual(result, undefined); + +// done(); +// }); + +// checkWrap(req); +// }); + +TEST(async function test_resolveSoa(done) { + function validateResult(result) { + assert.strictEqual(typeof result, 'object'); + assert.strictEqual(typeof result.nsname, 'string'); + assert.ok(result.nsname.length > 0); + assert.strictEqual(typeof result.hostmaster, 'string'); + assert.ok(result.hostmaster.length > 0); + assert.strictEqual(typeof result.serial, 'number'); + assert.ok((result.serial > 0) && (result.serial < 4294967295)); + assert.strictEqual(typeof result.refresh, 'number'); + assert.ok((result.refresh > 0) && (result.refresh < 2147483647)); + assert.strictEqual(typeof result.retry, 'number'); + assert.ok((result.retry > 0) && (result.retry < 2147483647)); + assert.strictEqual(typeof result.expire, 'number'); + assert.ok((result.expire > 0) && (result.expire < 2147483647)); + assert.strictEqual(typeof result.minttl, 'number'); + assert.ok((result.minttl >= 0) && (result.minttl < 2147483647)); + } + + validateResult(await dnsPromises.resolveSoa(addresses.SOA_HOST)); + + const req = dns.resolveSoa(addresses.SOA_HOST, function(err, result) { + assert.ifError(err); + validateResult(result); + done(); + }); + + checkWrap(req); +}); + +// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN` +// instead of `ENOTFOUND`. +// TEST(function test_resolveSoa_failure(done) { +// dnsPromises.resolveSoa(addresses.NOT_FOUND) +// .then(common.mustNotCall()) +// .catch(common.mustCall((err) => { +// assert.strictEqual(err.code, 'ENOTFOUND'); +// })); + +// const req = dns.resolveSoa(addresses.NOT_FOUND, function(err, result) { +// assert.ok(err instanceof Error); +// assert.strictEqual(err.code, 'ENOTFOUND'); + +// assert.strictEqual(result, undefined); + +// done(); +// }); + +// checkWrap(req); +// }); + +TEST(async function test_resolveCaa(done) { + function validateResult(result) { + assert.ok(Array.isArray(result), + `expected array, got ${util.inspect(result)}`); + assert.strictEqual(result.length, 1); + assert.strictEqual(typeof result[0].critical, 'number'); + assert.strictEqual(result[0].critical, 0); + assert.strictEqual(result[0].issue, 'pki.goog'); + } + + validateResult(await dnsPromises.resolveCaa(addresses.CAA_HOST)); + + const req = dns.resolveCaa(addresses.CAA_HOST, function(err, records) { + assert.ifError(err); + validateResult(records); + done(); + }); + + checkWrap(req); +}); + +// NOTE(bartlomieju): this test started failing around July 11th, 2023. +// TEST(async function test_resolveCname(done) { +// function validateResult(result) { +// assert.ok(result.length > 0); +// +// for (const item of result) { +// assert.ok(item); +// assert.strictEqual(typeof item, 'string'); +// } +// } +// +// validateResult(await dnsPromises.resolveCname(addresses.CNAME_HOST)); +// +// const req = dns.resolveCname(addresses.CNAME_HOST, function(err, names) { +// assert.ifError(err); +// validateResult(names); +// done(); +// }); +// +// checkWrap(req); +// }); + +// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN` +// instead of `ENOTFOUND`. +// TEST(function test_resolveCname_failure(done) { +// dnsPromises.resolveCname(addresses.NOT_FOUND) +// .then(common.mustNotCall()) +// .catch(common.mustCall((err) => { +// assert.strictEqual(err.code, 'ENOTFOUND'); +// })); + +// const req = dns.resolveCname(addresses.NOT_FOUND, function(err, result) { +// assert.ok(err instanceof Error); +// assert.strictEqual(err.code, 'ENOTFOUND'); + +// assert.strictEqual(result, undefined); + +// done(); +// }); + +// checkWrap(req); +// }); + + +TEST(async function test_resolveTxt(done) { + function validateResult(result) { + assert.ok(Array.isArray(result[0])); + assert.strictEqual(result.length, 1); + assert(result[0][0].startsWith('v=spf1')); + } + + validateResult(await dnsPromises.resolveTxt(addresses.TXT_HOST)); + + const req = dns.resolveTxt(addresses.TXT_HOST, function(err, records) { + assert.ifError(err); + validateResult(records); + done(); + }); + + checkWrap(req); +}); + +// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN` +// instead of `ENOTFOUND`. +// TEST(function test_resolveTxt_failure(done) { +// dnsPromises.resolveTxt(addresses.NOT_FOUND) +// .then(common.mustNotCall()) +// .catch(common.mustCall((err) => { +// assert.strictEqual(err.code, 'ENOTFOUND'); +// })); + +// const req = dns.resolveTxt(addresses.NOT_FOUND, function(err, result) { +// assert.ok(err instanceof Error); +// assert.strictEqual(err.code, 'ENOTFOUND'); + +// assert.strictEqual(result, undefined); + +// done(); +// }); + +// checkWrap(req); +// }); + + +TEST(function test_lookup_failure(done) { + dnsPromises.lookup(addresses.NOT_FOUND, 4) + .then(common.mustNotCall()) + .catch(common.expectsError({ code: dns.NOTFOUND })); + + const req = dns.lookup(addresses.NOT_FOUND, 4, (err) => { + assert.ok(err instanceof Error); + assert.strictEqual(err.code, dns.NOTFOUND); + assert.strictEqual(err.code, 'ENOTFOUND'); + assert.doesNotMatch(err.message, /ENOENT/); + assert.ok(err.message.includes(addresses.NOT_FOUND)); + + done(); + }); + + checkWrap(req); +}); + + +TEST(async function test_lookup_ip_all(done) { + function validateResult(result) { + assert.ok(Array.isArray(result)); + assert.ok(result.length > 0); + assert.strictEqual(result[0].address, '127.0.0.1'); + assert.strictEqual(result[0].family, 4); + } + + validateResult(await dnsPromises.lookup('127.0.0.1', { all: true })); + + const req = dns.lookup( + '127.0.0.1', + { all: true }, + function(err, ips, family) { + assert.ifError(err); + assert.strictEqual(family, undefined); + validateResult(ips); + done(); + } + ); + + checkWrap(req); +}); + + +TEST(function test_lookup_ip_all_promise(done) { + const req = util.promisify(dns.lookup)('127.0.0.1', { all: true }) + .then(function(ips) { + assert.ok(Array.isArray(ips)); + assert.ok(ips.length > 0); + assert.strictEqual(ips[0].address, '127.0.0.1'); + assert.strictEqual(ips[0].family, 4); + + done(); + }); + + checkWrap(req); +}); + + +TEST(function test_lookup_ip_promise(done) { + util.promisify(dns.lookup)('127.0.0.1') + .then(function({ address, family }) { + assert.strictEqual(address, '127.0.0.1'); + assert.strictEqual(family, 4); + + done(); + }); +}); + + +TEST(async function test_lookup_null_all(done) { + assert.deepStrictEqual(await dnsPromises.lookup(null, { all: true }), []); + + const req = dns.lookup(null, { all: true }, (err, ips) => { + assert.ifError(err); + assert.ok(Array.isArray(ips)); + assert.strictEqual(ips.length, 0); + + done(); + }); + + checkWrap(req); +}); + + +TEST(async function test_lookup_all_mixed(done) { + function validateResult(result) { + assert.ok(Array.isArray(result)); + assert.ok(result.length > 0); + + result.forEach(function(ip) { + if (isIPv4(ip.address)) + assert.strictEqual(ip.family, 4); + else if (isIPv6(ip.address)) + assert.strictEqual(ip.family, 6); + else + assert.fail('unexpected IP address'); + }); + } + + validateResult(await dnsPromises.lookup(addresses.INET_HOST, { all: true })); + + const req = dns.lookup(addresses.INET_HOST, { + all: true + }, function(err, ips) { + assert.ifError(err); + validateResult(ips); + done(); + }); + + checkWrap(req); +}); + + +// TEST(function test_lookupservice_invalid(done) { +// dnsPromises.lookupService('1.2.3.4', 80) +// .then(common.mustNotCall()) +// .catch(common.expectsError({ code: 'ENOTFOUND' })); + +// const req = dns.lookupService('1.2.3.4', 80, (err) => { +// assert(err instanceof Error); +// assert.strictEqual(err.code, 'ENOTFOUND'); +// assert.match(err.message, /1\.2\.3\.4/); + +// done(); +// }); + +// checkWrap(req); +// }); + + +// TEST(function test_reverse_failure(done) { +// dnsPromises.reverse('203.0.113.0') +// .then(common.mustNotCall()) +// .catch(common.expectsError({ +// code: 'ENOTFOUND', +// hostname: '203.0.113.0' +// })); + +// // 203.0.113.0/24 are addresses reserved for (RFC) documentation use only +// const req = dns.reverse('203.0.113.0', function(err) { +// assert(err instanceof Error); +// assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code... +// assert.strictEqual(err.hostname, '203.0.113.0'); +// assert.match(err.message, /203\.0\.113\.0/); + +// done(); +// }); + +// checkWrap(req); +// }); + + +// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN` +// instead of `ENOTFOUND`. +// TEST(function test_lookup_failure(done) { +// dnsPromises.lookup(addresses.NOT_FOUND) +// .then(common.mustNotCall()) +// .catch(common.expectsError({ +// code: 'ENOTFOUND', +// hostname: addresses.NOT_FOUND +// })); + +// const req = dns.lookup(addresses.NOT_FOUND, (err) => { +// assert(err instanceof Error); +// assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code... +// assert.strictEqual(err.hostname, addresses.NOT_FOUND); +// assert.ok(err.message.includes(addresses.NOT_FOUND)); + +// done(); +// }); + +// checkWrap(req); +// }); + + +// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN` +// instead of `ENOTFOUND`. +// TEST(function test_resolve_failure(done) { +// const req = dns.resolve4(addresses.NOT_FOUND, (err) => { +// assert(err instanceof Error); + +// switch (err.code) { +// case 'ENOTFOUND': +// case 'ESERVFAIL': +// break; +// default: +// assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code... +// break; +// } + +// assert.strictEqual(err.hostname, addresses.NOT_FOUND); +// assert.ok(err.message.includes(addresses.NOT_FOUND)); + +// done(); +// }); + +// checkWrap(req); +// }); + + +let getaddrinfoCallbackCalled = false; + +console.log(`looking up ${addresses.INET4_HOST}..`); + +const cares = internalBinding('cares_wrap'); +const req = new cares.GetAddrInfoReqWrap(); +cares.getaddrinfo(req, addresses.INET4_HOST, 4, + /* hints */ 0, /* verbatim */ true); + +req.oncomplete = function(err, domains) { + assert.strictEqual(err, 0); + console.log(`${addresses.INET4_HOST} = ${domains}`); + assert.ok(Array.isArray(domains)); + assert.ok(domains.length >= 1); + assert.strictEqual(typeof domains[0], 'string'); + getaddrinfoCallbackCalled = true; +}; + +process.on('exit', function() { + console.log(`${completed} tests completed`); + assert.strictEqual(running, false); + assert.strictEqual(completed, expected); + assert.ok(getaddrinfoCallbackCalled); +}); + +// Should not throw. +dns.lookup(addresses.INET6_HOST, 6, common.mustCall()); +dns.lookup(addresses.INET_HOST, {}, common.mustCall()); +// dns.lookupService('0.0.0.0', '0', common.mustCall()); +// dns.lookupService('0.0.0.0', 0, common.mustCall()); +(async function() { + await dnsPromises.lookup(addresses.INET6_HOST, 6); + await dnsPromises.lookup(addresses.INET_HOST, {}); +})().then(common.mustCall()); diff --git a/tests/node_compat/test/internet/test-http-https-default-ports.js b/tests/node_compat/test/internet/test-http-https-default-ports.js new file mode 100644 index 000000000..ef3edd2fc --- /dev/null +++ b/tests/node_compat/test/internet/test-http-https-default-ports.js @@ -0,0 +1,46 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by `tools/node_compat/setup.ts`. Do not modify this file manually. + +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; +const common = require('../common'); +const { addresses } = require('../common/internet'); + +if (!common.hasCrypto) + common.skip('missing crypto'); + +const https = require('https'); + +const http = require('http'); + +https.get(`https://${addresses.INET_HOST}/`, common.mustCall((res) => { + res.resume(); +})); + +http.get(`http://${addresses.INET_HOST}/`, common.mustCall((res) => { + res.resume(); +})); |