Skip to content

Commit 097248b

Browse files
committed
add ignoreUpstreamProxyCertificate tests
1 parent bad3172 commit 097248b

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

test/server.js

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

1484+
describe('supports ignoreProxyCertificate', () => {
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+
const response = await requestPromised({
1518+
proxy: 'http://localhost:6666',
1519+
url: 'http://httpbin.org/ip',
1520+
});
1521+
1522+
expect(proxyServerError).to.be.equal(false);
1523+
1524+
expect(response.statusCode).to.be.equal(599);
1525+
1526+
proxyServer.close();
1527+
target.close();
1528+
});
1529+
1530+
it('bypass upstream error', async () => {
1531+
const target = https.createServer(serverOptions, (_req, res) => {
1532+
res.write(responseMessage);
1533+
res.end();
1534+
});
1535+
1536+
await util.promisify(target.listen.bind(target))(0);
1537+
1538+
const proxyServer = new ProxyChain.Server({
1539+
port: 6666,
1540+
prepareRequestFunction: () => {
1541+
return {
1542+
ignoreUpstreamProxyCertificate: true,
1543+
upstreamProxyUrl: `https://localhost:${target.address().port}`,
1544+
};
1545+
},
1546+
});
1547+
1548+
let proxyServerError = false;
1549+
proxyServer.on('requestFailed', () => {
1550+
// requestFailed will be called if we pass an invalid proxy url
1551+
proxyServerError = true;
1552+
});
1553+
1554+
await proxyServer.listen();
1555+
1556+
const response = await requestPromised({
1557+
proxy: 'http://localhost:6666',
1558+
url: 'http://httpbin.org/ip',
1559+
});
1560+
1561+
expect(proxyServerError).to.be.equal(false);
1562+
1563+
expect(response.statusCode).to.be.equal(200);
1564+
expect(response.body).to.be.equal(responseMessage);
1565+
1566+
proxyServer.close();
1567+
target.close();
1568+
});
1569+
});
1570+
14841571
// Run all combinations of test parameters
14851572
const useSslVariants = [
14861573
false,

0 commit comments

Comments
 (0)