@@ -10,7 +10,7 @@ const ProxyAgent = require('../lib/dispatcher/proxy-agent')
1010const Pool = require ( '../lib/dispatcher/pool' )
1111const { createServer } = require ( 'node:http' )
1212const https = require ( 'node:https' )
13- const proxy = require ( 'proxy' )
13+ const { createProxy } = require ( 'proxy' )
1414
1515test ( 'should throw error when no uri is provided' , ( t ) => {
1616 t = tspl ( t , { plan : 2 } )
@@ -81,16 +81,16 @@ test('use proxy agent to connect through proxy using Pool', async (t) => {
8181 let resolveFirstConnect
8282 let connectCount = 0
8383
84- proxy . authenticate = async function ( req , fn ) {
84+ proxy . authenticate = async function ( req ) {
8585 if ( ++ connectCount === 2 ) {
8686 t . ok ( true , 'second connect should arrive while first is still inflight' )
8787 resolveFirstConnect ( )
88- fn ( null , true )
88+ return true
8989 } else {
9090 await new Promise ( ( resolve ) => {
9191 resolveFirstConnect = resolve
9292 } )
93- fn ( null , true )
93+ return true
9494 }
9595 }
9696
@@ -161,7 +161,7 @@ test('use proxy-agent to connect through proxy with basic auth in URL', async (t
161161
162162 proxy . authenticate = function ( req , fn ) {
163163 t . ok ( true , 'authentication should be called' )
164- fn ( null , req . headers [ 'proxy-authorization' ] === `Basic ${ Buffer . from ( 'user:pass' ) . toString ( 'base64' ) } ` )
164+ return req . headers [ 'proxy-authorization' ] === `Basic ${ Buffer . from ( 'user:pass' ) . toString ( 'base64' ) } `
165165 }
166166 proxy . on ( 'connect' , ( ) => {
167167 t . ok ( true , 'proxy should be called' )
@@ -203,9 +203,9 @@ test('use proxy-agent with auth', async (t) => {
203203 } )
204204 const parsedOrigin = new URL ( serverUrl )
205205
206- proxy . authenticate = function ( req , fn ) {
206+ proxy . authenticate = function ( req ) {
207207 t . ok ( true , 'authentication should be called' )
208- fn ( null , req . headers [ 'proxy-authorization' ] === `Basic ${ Buffer . from ( 'user:pass' ) . toString ( 'base64' ) } ` )
208+ return req . headers [ 'proxy-authorization' ] === `Basic ${ Buffer . from ( 'user:pass' ) . toString ( 'base64' ) } `
209209 }
210210 proxy . on ( 'connect' , ( ) => {
211211 t . ok ( true , 'proxy should be called' )
@@ -247,9 +247,9 @@ test('use proxy-agent with token', async (t) => {
247247 } )
248248 const parsedOrigin = new URL ( serverUrl )
249249
250- proxy . authenticate = function ( req , fn ) {
250+ proxy . authenticate = function ( req ) {
251251 t . ok ( true , 'authentication should be called' )
252- fn ( null , req . headers [ 'proxy-authorization' ] === `Bearer ${ Buffer . from ( 'user:pass' ) . toString ( 'base64' ) } ` )
252+ return req . headers [ 'proxy-authorization' ] === `Bearer ${ Buffer . from ( 'user:pass' ) . toString ( 'base64' ) } `
253253 }
254254 proxy . on ( 'connect' , ( ) => {
255255 t . ok ( true , 'proxy should be called' )
@@ -460,16 +460,17 @@ test('ProxyAgent correctly sends headers when using fetch - #1355, #1623', async
460460} )
461461
462462test ( 'should throw when proxy does not return 200' , async ( t ) => {
463- t = tspl ( t , { plan : 2 } )
463+ t = tspl ( t , { plan : 3 } )
464464
465465 const server = await buildServer ( )
466466 const proxy = await buildProxy ( )
467467
468468 const serverUrl = `http://localhost:${ server . address ( ) . port } `
469469 const proxyUrl = `http://localhost:${ proxy . address ( ) . port } `
470470
471- proxy . authenticate = function ( req , fn ) {
472- fn ( null , false )
471+ proxy . authenticate = function ( _req ) {
472+ t . ok ( true , 'should call authenticate' )
473+ return false
473474 }
474475
475476 const proxyAgent = new ProxyAgent ( proxyUrl )
@@ -488,15 +489,16 @@ test('should throw when proxy does not return 200', async (t) => {
488489} )
489490
490491test ( 'pass ProxyAgent proxy status code error when using fetch - #2161' , async ( t ) => {
491- t = tspl ( t , { plan : 1 } )
492+ t = tspl ( t , { plan : 2 } )
492493 const server = await buildServer ( )
493494 const proxy = await buildProxy ( )
494495
495496 const serverUrl = `http://localhost:${ server . address ( ) . port } `
496497 const proxyUrl = `http://localhost:${ proxy . address ( ) . port } `
497498
498- proxy . authenticate = function ( req , fn ) {
499- fn ( null , false )
499+ proxy . authenticate = function ( _req ) {
500+ t . ok ( true , 'should call authenticate' )
501+ return false
500502 }
501503
502504 const proxyAgent = new ProxyAgent ( proxyUrl )
@@ -742,8 +744,8 @@ function buildSSLServer () {
742744function buildProxy ( listener ) {
743745 return new Promise ( ( resolve ) => {
744746 const server = listener
745- ? proxy ( createServer ( listener ) )
746- : proxy ( createServer ( ) )
747+ ? createProxy ( createServer ( listener ) )
748+ : createProxy ( createServer ( ) )
747749 server . listen ( 0 , ( ) => resolve ( server ) )
748750 } )
749751}
@@ -758,7 +760,7 @@ function buildSSLProxy () {
758760 }
759761
760762 return new Promise ( ( resolve ) => {
761- const server = proxy ( https . createServer ( serverOptions ) )
763+ const server = createProxy ( https . createServer ( serverOptions ) )
762764 server . listen ( 0 , ( ) => resolve ( server ) )
763765 } )
764766}
0 commit comments