node/test/parallel/test-dns-lookupService-promises.js
Daeyeon Jeong db7fa9f4b7
test: allow numeric string for lookupService test
Fixes: https://github.com/nodejs/node/issues/42164

If the given port number isn't associated with any service name,
the `service` resolved from `dns.lookupService` can be a numeric
string representing the port number.

PR-URL: https://github.com/nodejs/node/pull/42596
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
2022-04-12 13:27:05 +01:00

20 lines
592 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const dnsPromises = require('dns').promises;
dnsPromises.lookupService('127.0.0.1', 22).then(common.mustCall((result) => {
assert(['ssh', '22'].includes(result.service));
assert.strictEqual(typeof result.hostname, 'string');
assert.notStrictEqual(result.hostname.length, 0);
}));
// Use an IP from the RFC 5737 test range to cause an error.
// Refs: https://tools.ietf.org/html/rfc5737
assert.rejects(
() => dnsPromises.lookupService('192.0.2.1', 22),
{ code: /^(?:ENOTFOUND|EAI_AGAIN)$/ }
);