node/test/parallel/test-net-connect-custom-lookup-non-string-address.mjs
Edy Silva 71196c431f
net: emit an error when custom lookup resolves to a non-string address
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>
2025-03-01 20:43:41 +00:00

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();
});
});
});