node/test/client-proxy/test-http-proxy-request-invalid-proxy.mjs
Joyee Cheung 81af7b93c5
http,https: handle IPv6 with proxies
This simplifies the proxy configuration handling code,
 adds tests to make sure the proxy support works with IPv6
and throws correct errors for invalid proxy IPs.
Drive-by: remove useless properties from ProxyConfig

PR-URL: https://github.com/nodejs/node/pull/59894
Refs: https://github.com/nodejs/node/issues/57872
Reviewed-By: Aditi Singh <aditisingh1400@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2025-09-22 23:19:26 +00:00

37 lines
794 B
JavaScript

// This tests that constructing agents with invalid proxy URLs throws ERR_PROXY_INVALID_CONFIG.
import '../common/index.mjs';
import assert from 'node:assert';
import http from 'node:http';
const testCases = [
{
name: 'invalid IPv4 address',
proxyUrl: 'http://256.256.256.256:8080',
},
{
name: 'invalid IPv6 address',
proxyUrl: 'http://::1:8080',
},
{
name: 'missing host',
proxyUrl: 'http://:8080',
},
{
name: 'non-numeric port',
proxyUrl: 'http://proxy.example.com:port',
},
];
for (const testCase of testCases) {
assert.throws(() => {
new http.Agent({
proxyEnv: {
HTTP_PROXY: testCase.proxyUrl,
},
});
}, {
code: 'ERR_PROXY_INVALID_CONFIG',
message: `Invalid proxy URL: ${testCase.proxyUrl}`,
});
}