mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 13:40:37 +00:00

PR-URL: https://github.com/nodejs/node/pull/57192 Fixes: https://github.com/nodejs/node/issues/57112 Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
import * as common from '../common/index.mjs';
|
|
import net from 'node:net';
|
|
import { describe, it } from 'node:test';
|
|
|
|
const brokenCustomLookup = (_hostname, options, callback) => {
|
|
// Incorrectly return an array of IPs instead of a string.
|
|
callback(null, ['127.0.0.1'], options.family);
|
|
};
|
|
|
|
describe('when family is ipv4', () => {
|
|
it('socket emits an error when lookup does not return a string', (t, done) => {
|
|
const options = {
|
|
host: 'example.com',
|
|
port: 80,
|
|
lookup: brokenCustomLookup,
|
|
family: 4
|
|
};
|
|
|
|
const socket = net.connect(options, common.mustNotCall());
|
|
socket.on('error', (err) => {
|
|
t.assert.strictEqual(err.code, 'ERR_INVALID_IP_ADDRESS');
|
|
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when family is ipv6', () => {
|
|
it('socket emits an error when lookup does not return a string', (t, done) => {
|
|
const options = {
|
|
host: 'example.com',
|
|
port: 80,
|
|
lookup: brokenCustomLookup,
|
|
family: 6
|
|
};
|
|
|
|
const socket = net.connect(options, common.mustNotCall());
|
|
socket.on('error', (err) => {
|
|
t.assert.strictEqual(err.code, 'ERR_INVALID_IP_ADDRESS');
|
|
|
|
done();
|
|
});
|
|
});
|
|
});
|