Skip to content

Commit a465f2b

Browse files
joyeecheungevanlucas
authored andcommitted
test: introduce test/common/internet.addresses
This commit introduces test/common/internet.address, which includes a set of addresses for doing internet tests. These addresses can be overriden using NODE_TEST_* environment variables. PR-URL: #16390 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 15dcb96 commit a465f2b

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

test/common/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This directory contains modules used to test the Node.js implementation.
1010
* [DNS module](#dns-module)
1111
* [Duplex pair helper](#duplex-pair-helper)
1212
* [Fixtures module](#fixtures-module)
13+
* [Internet module](#internet-module)
1314
* [WPT module](#wpt-module)
1415

1516
## Benchmark Module
@@ -498,6 +499,40 @@ Returns the result of
498499
Returns the result of
499500
`fs.readFileSync(path.join(fixtures.fixturesDir, 'keys', arg), 'enc')`.
500501

502+
## Internet Module
503+
504+
The `common/internet` module provides utilities for working with
505+
internet-related tests.
506+
507+
### internet.addresses
508+
509+
* [&lt;Object>]
510+
* `INET_HOST` [&lt;String>] A generic host that has registered common
511+
DNS records, supports both IPv4 and IPv6, and provides basic HTTP/HTTPS
512+
services
513+
* `INET4_HOST` [&lt;String>] A host that provides IPv4 services
514+
* `INET6_HOST` [&lt;String>] A host that provides IPv6 services
515+
* `INET4_IP` [&lt;String>] An accessible IPv4 IP, defaults to the
516+
Google Public DNS IPv4 address
517+
* `INET6_IP` [&lt;String>] An accessible IPv6 IP, defaults to the
518+
Google Public DNS IPv6 address
519+
* `INVALID_HOST` [&lt;String>] An invalid host that cannot be resolved
520+
* `MX_HOST` [&lt;String>] A host with MX records registered
521+
* `SRV_HOST` [&lt;String>] A host with SRV records registered
522+
* `PTR_HOST` [&lt;String>] A host with PTR records registered
523+
* `NAPTR_HOST` [&lt;String>] A host with NAPTR records registered
524+
* `SOA_HOST` [&lt;String>] A host with SOA records registered
525+
* `CNAME_HOST` [&lt;String>] A host with CNAME records registered
526+
* `NS_HOST` [&lt;String>] A host with NS records registered
527+
* `TXT_HOST` [&lt;String>] A host with TXT records registered
528+
* `DNS4_SERVER` [&lt;String>] An accessible IPv4 DNS server
529+
* `DNS6_SERVER` [&lt;String>] An accessible IPv6 DNS server
530+
531+
A set of addresses for internet-related tests. All properties are configurable
532+
via `NODE_TEST_*` environment variables. For example, to configure
533+
`internet.addresses.INET_HOST`, set the environment
534+
vairable `NODE_TEST_INET_HOST` to a specified host.
535+
501536
## WPT Module
502537

503538
The wpt.js module is a port of parts of

test/common/dns.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,6 @@ function writeDNSPacket(parsed) {
287287
}));
288288
}
289289

290-
module.exports = { types, classes, writeDNSPacket, parseDNSPacket };
290+
module.exports = {
291+
types, classes, writeDNSPacket, parseDNSPacket
292+
};

test/common/internet.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* eslint-disable required-modules */
2+
'use strict';
3+
4+
// Utilities for internet-related tests
5+
6+
const addresses = {
7+
// A generic host that has registered common DNS records,
8+
// supports both IPv4 and IPv6, and provides basic HTTP/HTTPS services
9+
INET_HOST: 'nodejs.org',
10+
// A host that provides IPv4 services
11+
INET4_HOST: 'nodejs.org',
12+
// A host that provides IPv6 services
13+
INET6_HOST: 'nodejs.org',
14+
// An accessible IPv4 IP,
15+
// defaults to the Google Public DNS IPv4 address
16+
INET4_IP: '8.8.8.8',
17+
// An accessible IPv6 IP,
18+
// defaults to the Google Public DNS IPv6 address
19+
INET6_IP: '2001:4860:4860::8888',
20+
// An invalid host that cannot be resolved
21+
// See https://tools.ietf.org/html/rfc2606#section-2
22+
INVALID_HOST: 'something.invalid',
23+
// A host with MX records registered
24+
MX_HOST: 'nodejs.org',
25+
// A host with SRV records registered
26+
SRV_HOST: '_jabber._tcp.google.com',
27+
// A host with PTR records registered
28+
PTR_HOST: '8.8.8.8.in-addr.arpa',
29+
// A host with NAPTR records registered
30+
NAPTR_HOST: 'sip2sip.info',
31+
// A host with SOA records registered
32+
SOA_HOST: 'nodejs.org',
33+
// A host with CNAME records registered
34+
CNAME_HOST: 'blog.nodejs.org',
35+
// A host with NS records registered
36+
NS_HOST: 'nodejs.org',
37+
// A host with TXT records registered
38+
TXT_HOST: 'nodejs.org',
39+
// An accessible IPv4 DNS server
40+
DNS4_SERVER: '8.8.8.8',
41+
// An accessible IPv4 DNS server
42+
DNS6_SERVER: '2001:4860:4860::8888'
43+
};
44+
45+
for (const key of Object.keys(addresses)) {
46+
const envName = `NODE_TEST_${key}`;
47+
if (process.env[envName]) {
48+
addresses[key] = process.env[envName];
49+
}
50+
}
51+
52+
module.exports = {
53+
addresses
54+
};

0 commit comments

Comments
 (0)