Skip to content

Commit ec1ab92

Browse files
authored
test: add ignoreUpstreamProxyCertificate tests (#583)
* add ignoreUpstreamProxyCertificate tests * 2.5.9 * rename the test group to use whole correct option name * Add comments with explanations to the new tests
1 parent bad3172 commit ec1ab92

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "proxy-chain",
3-
"version": "2.5.8",
3+
"version": "2.5.9",
44
"description": "Node.js implementation of a proxy server (think Squid) with support for SSL, authentication, upstream proxy chaining, and protocol tunneling.",
55
"main": "dist/index.js",
66
"keywords": [

test/server.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,101 @@ it('supports pre-response CONNECT payload', (done) => {
14811481
});
14821482
});
14831483

1484+
describe('supports ignoreUpstreamProxyCertificate', () => {
1485+
const serverOptions = {
1486+
key: sslKey,
1487+
cert: sslCrt,
1488+
};
1489+
1490+
const responseMessage = 'Hello World!';
1491+
1492+
it('fails on upstream error', async () => {
1493+
const target = https.createServer(serverOptions, (_req, res) => {
1494+
res.write(responseMessage);
1495+
res.end();
1496+
});
1497+
1498+
await util.promisify(target.listen.bind(target))(0);
1499+
1500+
const proxyServer = new ProxyChain.Server({
1501+
port: 6666,
1502+
prepareRequestFunction: () => {
1503+
return {
1504+
upstreamProxyUrl: `https://localhost:${target.address().port}`,
1505+
};
1506+
},
1507+
});
1508+
1509+
let proxyServerError = false;
1510+
proxyServer.on('requestFailed', () => {
1511+
// requestFailed will be called if we pass an invalid proxy url
1512+
proxyServerError = true;
1513+
});
1514+
1515+
await proxyServer.listen();
1516+
1517+
/**
1518+
* request is sent with rejectUnauthorized: true
1519+
* so when the SSL certificate is not trusted (self-signed, expired, invalid), client will reject the connection
1520+
*/
1521+
const response = await requestPromised({
1522+
proxy: 'http://localhost:6666',
1523+
url: 'http://httpbin.org/ip',
1524+
});
1525+
1526+
expect(proxyServerError).to.be.equal(false);
1527+
1528+
expect(response.statusCode).to.be.equal(599);
1529+
1530+
proxyServer.close();
1531+
target.close();
1532+
});
1533+
1534+
it('bypass upstream error', async () => {
1535+
const target = https.createServer(serverOptions, (_req, res) => {
1536+
res.write(responseMessage);
1537+
res.end();
1538+
});
1539+
1540+
await util.promisify(target.listen.bind(target))(0);
1541+
1542+
const proxyServer = new ProxyChain.Server({
1543+
port: 6666,
1544+
prepareRequestFunction: () => {
1545+
return {
1546+
ignoreUpstreamProxyCertificate: true,
1547+
upstreamProxyUrl: `https://localhost:${target.address().port}`,
1548+
};
1549+
},
1550+
});
1551+
1552+
let proxyServerError = false;
1553+
proxyServer.on('requestFailed', () => {
1554+
// requestFailed will be called if we pass an invalid proxy url
1555+
proxyServerError = true;
1556+
});
1557+
1558+
await proxyServer.listen();
1559+
1560+
/**
1561+
* request is sent with rejectUnauthorized: false
1562+
* so when the SSL certificate is not trusted (self-signed, expired, invalid), client won't reject the connection
1563+
*/
1564+
const response = await requestPromised({
1565+
proxy: 'http://localhost:6666',
1566+
url: 'http://httpbin.org/ip',
1567+
});
1568+
1569+
expect(proxyServerError).to.be.equal(false);
1570+
1571+
expect(response.statusCode).to.be.equal(200);
1572+
expect(response.body).to.be.equal(responseMessage);
1573+
1574+
proxyServer.close();
1575+
target.close();
1576+
});
1577+
});
1578+
14841579
// Run all combinations of test parameters
14851580
const useSslVariants = [
14861581
false,

0 commit comments

Comments
 (0)