diff --git a/.github/workflows/test-internet.yml b/.github/workflows/test-internet.yml index 10b72c78ff5ed6..e899deb4d8d581 100644 --- a/.github/workflows/test-internet.yml +++ b/.github/workflows/test-internet.yml @@ -10,9 +10,13 @@ on: paths: - .github/workflows/test-internet.yml - test/internet/** + - test/common/internet.js - internal/dns/** - lib/dns.js + - lib/internal/dns/** - lib/net.js + - src/cares_wrap.cc + - src/cares_wrap.h push: branches: - main @@ -22,9 +26,13 @@ on: paths: - .github/workflows/test-internet.yml - test/internet/** + - test/common/internet.js - internal/dns/** - lib/dns.js + - lib/internal/dns/** - lib/net.js + - src/cares_wrap.cc + - src/cares_wrap.h concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} diff --git a/test/common/internet.js b/test/common/internet.js index 411917893d22b9..fd55ccd14cdde7 100644 --- a/test/common/internet.js +++ b/test/common/internet.js @@ -46,6 +46,10 @@ const addresses = { DNS4_SERVER: '8.8.8.8', // An accessible IPv4 DNS server DNS6_SERVER: '2001:4860:4860::8888', + // A valid host with no records (except SOA) + NO_RECORD_HOST: 'void.example.com', + // A valid host with no TXT records, and a CNAME to a host with no TXT records + CNAME_TO_NO_TXT_HOST: 'www.microsoft.com', }; for (const key of Object.keys(addresses)) { diff --git a/test/internet/test-dns-txt-sigsegv.js b/test/internet/test-dns-txt-sigsegv.js index 013394f2d9c2e8..e54db635380aff 100644 --- a/test/internet/test-dns-txt-sigsegv.js +++ b/test/internet/test-dns-txt-sigsegv.js @@ -1,15 +1,17 @@ 'use strict'; const common = require('../common'); +const { addresses } = require('../common/internet'); const assert = require('assert'); const dns = require('dns'); const dnsPromises = dns.promises; -(async function() { - const result = await dnsPromises.resolveTxt('www.microsoft.com'); - assert.strictEqual(result.length, 0); -})().then(common.mustCall()); +assert.rejects( + dnsPromises.resolveTxt(addresses.CNAME_TO_NO_TXT_HOST), + { code: 'ENODATA' }, +).then(common.mustCall()); -dns.resolveTxt('www.microsoft.com', common.mustCall((err, records) => { - assert.strictEqual(err, null); - assert.strictEqual(records.length, 0); +dns.resolveTxt(addresses.CNAME_TO_NO_TXT_HOST, common.mustCall((err, records) => { + assert.ok(err instanceof Error); + assert.strictEqual(err.code, 'ENODATA'); + assert.strictEqual(records, undefined); })); diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js index accc789f9e4d48..86fb99611f50b6 100644 --- a/test/internet/test-dns.js +++ b/test/internet/test-dns.js @@ -724,6 +724,67 @@ test(function test_resolve_failure(done) { }); +async function testEmptyRecords(method, done) { + await assert.rejects( + dnsPromises[method](addresses.NO_RECORD_HOST), + { code: 'ENODATA' }, + ); + + const req = dns[method](addresses.NO_RECORD_HOST, common.mustCall((err, result) => { + assert.ok(err instanceof Error); + assert.strictEqual(err.code, 'ENODATA'); + assert.strictEqual(result, undefined); + done(); + })); + + checkWrap(req); +} + +test(function test_empty_4_records(done) { + testEmptyRecords('resolve4', done); +}); + +test(function test_empty_6_records(done) { + testEmptyRecords('resolve6', done); +}); + +test(function test_empty_caa_records(done) { + testEmptyRecords('resolveCaa', done); +}); + +test(function test_empty_cname_records(done) { + testEmptyRecords('resolveCname', done); +}); + +test(function test_empty_mx_records(done) { + testEmptyRecords('resolveMx', done); +}); + +test(function test_empty_naptr_records(done) { + testEmptyRecords('resolveNaptr', done); +}); + +test(function test_empty_ns_records(done) { + testEmptyRecords('resolveNs', done); +}); + +test(function test_empty_ptr_records(done) { + testEmptyRecords('resolvePtr', done); +}); + +test(function test_empty_srv_records(done) { + testEmptyRecords('resolveSrv', done); +}); + +test(function test_empty_tlsa_records(done) { + testEmptyRecords('resolveTlsa', done); +}); + +test(function test_empty_txt_records(done) { + testEmptyRecords('resolveTxt', done); +}); + + let getaddrinfoCallbackCalled = false; console.log(`looking up ${addresses.INET4_HOST}..`);