From 3ba464dbc40dd2d6bd3f7a1912aa8f0fad95058f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 18 Nov 2024 19:27:44 +0000 Subject: [PATCH] chore: temporarily disable dns tests for Node compat (#26915) These tests are hitting a remote server which sometimes starts failing randomly on CI. They need to be rewritten to use a local server and have `/etc/hosts` setup that remaps relevants URLs. --- tests/node_compat/config.jsonc | 18 +- tests/node_compat/runner/TODO.md | 4 + .../node_compat/test/internet/test-dns-any.js | 194 ----- .../test/internet/test-dns-ipv4.js | 257 ------ .../test/internet/test-dns-ipv6.js | 250 ------ tests/node_compat/test/internet/test-dns.js | 766 ------------------ 6 files changed, 14 insertions(+), 1475 deletions(-) delete mode 100644 tests/node_compat/test/internet/test-dns-any.js delete mode 100644 tests/node_compat/test/internet/test-dns-ipv4.js delete mode 100644 tests/node_compat/test/internet/test-dns-ipv6.js delete mode 100644 tests/node_compat/test/internet/test-dns.js diff --git a/tests/node_compat/config.jsonc b/tests/node_compat/config.jsonc index 664adaedfa0c49..31b184505054b1 100644 --- a/tests/node_compat/config.jsonc +++ b/tests/node_compat/config.jsonc @@ -13,10 +13,12 @@ "x.txt" ], "internet": [ - "test-dns-any.js", - "test-dns-ipv4.js", - "test-dns-ipv6.js", - "test-dns.js" + // TODO(bartlomieju): temporarily disabled as these tests were hitting nodejs.org + // server. We should have a setup that hits a local server instead. + // "test-dns-any.js", + // "test-dns-ipv4.js", + // "test-dns-ipv6.js", + // "test-dns.js" ], "parallel": [ "test-assert.js", @@ -149,15 +151,15 @@ ], "fixtures/keys": ["agent1-cert.pem", "agent1-key.pem", "ca1-cert.pem"], "internet": [ - "test-dns-any.js", + // "test-dns-any.js", "test-dns-idna2008.js", - "test-dns-ipv4.js", - "test-dns-ipv6.js", + // "test-dns-ipv4.js", + // "test-dns-ipv6.js", "test-dns-lookup.js", "test-dns-promises-resolve.js", "test-dns-regress-6244.js", "test-dns-setserver-in-callback-of-resolve4.js", - "test-dns.js", + // "test-dns.js", "test-http-https-default-ports.js" ], "parallel": [ diff --git a/tests/node_compat/runner/TODO.md b/tests/node_compat/runner/TODO.md index 27c2ef3e789059..cb7e6034b96b54 100644 --- a/tests/node_compat/runner/TODO.md +++ b/tests/node_compat/runner/TODO.md @@ -105,9 +105,13 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co - [internet/test-dgram-multicast-set-interface-lo.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dgram-multicast-set-interface-lo.js) - [internet/test-dgram-multicast-ssm-multi-process.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dgram-multicast-ssm-multi-process.js) - [internet/test-dgram-multicast-ssmv6-multi-process.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dgram-multicast-ssmv6-multi-process.js) +- [internet/test-dns-any.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-any.js) - [internet/test-dns-cares-domains.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-cares-domains.js) - [internet/test-dns-getDefaultResultOrder.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-getDefaultResultOrder.js) +- [internet/test-dns-ipv4.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-ipv4.js) +- [internet/test-dns-ipv6.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-ipv6.js) - [internet/test-dns-txt-sigsegv.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-txt-sigsegv.js) +- [internet/test-dns.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns.js) - [internet/test-http-dns-fail.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-http-dns-fail.js) - [internet/test-http2-issue-32922.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-http2-issue-32922.js) - [internet/test-https-autoselectfamily-slow-timeout.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-https-autoselectfamily-slow-timeout.js) diff --git a/tests/node_compat/test/internet/test-dns-any.js b/tests/node_compat/test/internet/test-dns-any.js deleted file mode 100644 index b8a70b8e2e7136..00000000000000 --- a/tests/node_compat/test/internet/test-dns-any.js +++ /dev/null @@ -1,194 +0,0 @@ -// 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-ipv4.js b/tests/node_compat/test/internet/test-dns-ipv4.js deleted file mode 100644 index 43b60950a0b04d..00000000000000 --- a/tests/node_compat/test/internet/test-dns-ipv4.js +++ /dev/null @@ -1,257 +0,0 @@ -// 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 deleted file mode 100644 index 4b94d60414ecca..00000000000000 --- a/tests/node_compat/test/internet/test-dns-ipv6.js +++ /dev/null @@ -1,250 +0,0 @@ -// 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.js b/tests/node_compat/test/internet/test-dns.js deleted file mode 100644 index 8aaeb728d59bd6..00000000000000 --- a/tests/node_compat/test/internet/test-dns.js +++ /dev/null @@ -1,766 +0,0 @@ -// 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());