@@ -1481,6 +1481,93 @@ it('supports pre-response CONNECT payload', (done) => {
1481
1481
} ) ;
1482
1482
} ) ;
1483
1483
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
+
1484
1571
// Run all combinations of test parameters
1485
1572
const useSslVariants = [
1486
1573
false ,
0 commit comments