mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
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>
37 lines
794 B
JavaScript
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}`,
|
|
});
|
|
}
|