• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// Verify that non-ASCII hostnames are handled correctly as IDNA 2008.
4//
5// * Tests will fail with NXDOMAIN when UTF-8 leaks through to a getaddrinfo()
6//   that doesn't support IDNA at all.
7//
8// * "straße.de" will resolve to the wrong address when the resolver supports
9//   only IDNA 2003 (e.g., glibc until 2.28) because it encodes it wrong.
10
11const { mustCall } = require('../common');
12const assert = require('assert');
13const dns = require('dns');
14const { addresses } = require('../common/internet');
15
16const fixture = {
17  hostname: 'straße.de',
18  expectedAddress: '81.169.145.78',
19  dnsServer: addresses.DNS4_SERVER,
20  family: 4,
21};
22
23// Explicitly use well-behaved DNS servers that are known to be able to resolve
24// the query (which is a.k.a xn--strae-oqa.de).
25dns.setServers([fixture.dnsServer]);
26
27dns.lookup(
28  fixture.hostname,
29  { family: fixture.family },
30  mustCall((err, address) => {
31    if (err && err.errno === 'ESERVFAIL') {
32      assert.ok(err.message.includes('queryA ESERVFAIL straße.de'));
33      return;
34    }
35    assert.ifError(err);
36    assert.strictEqual(address, fixture.expectedAddress);
37  }),
38);
39
40dns.promises.lookup(fixture.hostname, { family: fixture.family })
41  .then(({ address }) => {
42    assert.strictEqual(address, fixture.expectedAddress);
43  }, (err) => {
44    if (err && err.errno === 'ESERVFAIL') {
45      assert.ok(err.message.includes('queryA ESERVFAIL straße.de'));
46    } else {
47      throw err;
48    }
49  }).finally(mustCall());
50
51dns.resolve4(fixture.hostname, mustCall((err, addresses) => {
52  if (err && err.errno === 'ESERVFAIL') {
53    assert.ok(err.message.includes('queryA ESERVFAIL straße.de'));
54    return;
55  }
56  assert.ifError(err);
57  assert.deepStrictEqual(addresses, [fixture.expectedAddress]);
58}));
59
60const p = new dns.promises.Resolver().resolve4(fixture.hostname);
61p.then((addresses) => {
62  assert.deepStrictEqual(addresses, [fixture.expectedAddress]);
63}, (err) => {
64  if (err && err.errno === 'ESERVFAIL') {
65    assert.ok(err.message.includes('queryA ESERVFAIL straße.de'));
66  } else {
67    throw err;
68  }
69}).finally(mustCall());
70