mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 17:03:34 +00:00

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>
20 lines
592 B
JavaScript
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)$/ }
|
|
);
|