@@ -10,7 +10,7 @@ const ProxyAgent = require('../lib/dispatcher/proxy-agent')
10
10
const Pool = require ( '../lib/dispatcher/pool' )
11
11
const { createServer } = require ( 'node:http' )
12
12
const https = require ( 'node:https' )
13
- const proxy = require ( 'proxy' )
13
+ const { createProxy } = require ( 'proxy' )
14
14
15
15
test ( 'should throw error when no uri is provided' , ( t ) => {
16
16
t = tspl ( t , { plan : 2 } )
@@ -81,16 +81,16 @@ test('use proxy agent to connect through proxy using Pool', async (t) => {
81
81
let resolveFirstConnect
82
82
let connectCount = 0
83
83
84
- proxy . authenticate = async function ( req , fn ) {
84
+ proxy . authenticate = async function ( req ) {
85
85
if ( ++ connectCount === 2 ) {
86
86
t . ok ( true , 'second connect should arrive while first is still inflight' )
87
87
resolveFirstConnect ( )
88
- fn ( null , true )
88
+ return true
89
89
} else {
90
90
await new Promise ( ( resolve ) => {
91
91
resolveFirstConnect = resolve
92
92
} )
93
- fn ( null , true )
93
+ return true
94
94
}
95
95
}
96
96
@@ -161,7 +161,7 @@ test('use proxy-agent to connect through proxy with basic auth in URL', async (t
161
161
162
162
proxy . authenticate = function ( req , fn ) {
163
163
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' ) } `
165
165
}
166
166
proxy . on ( 'connect' , ( ) => {
167
167
t . ok ( true , 'proxy should be called' )
@@ -203,9 +203,9 @@ test('use proxy-agent with auth', async (t) => {
203
203
} )
204
204
const parsedOrigin = new URL ( serverUrl )
205
205
206
- proxy . authenticate = function ( req , fn ) {
206
+ proxy . authenticate = function ( req ) {
207
207
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' ) } `
209
209
}
210
210
proxy . on ( 'connect' , ( ) => {
211
211
t . ok ( true , 'proxy should be called' )
@@ -247,9 +247,9 @@ test('use proxy-agent with token', async (t) => {
247
247
} )
248
248
const parsedOrigin = new URL ( serverUrl )
249
249
250
- proxy . authenticate = function ( req , fn ) {
250
+ proxy . authenticate = function ( req ) {
251
251
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' ) } `
253
253
}
254
254
proxy . on ( 'connect' , ( ) => {
255
255
t . ok ( true , 'proxy should be called' )
@@ -460,16 +460,17 @@ test('ProxyAgent correctly sends headers when using fetch - #1355, #1623', async
460
460
} )
461
461
462
462
test ( 'should throw when proxy does not return 200' , async ( t ) => {
463
- t = tspl ( t , { plan : 2 } )
463
+ t = tspl ( t , { plan : 3 } )
464
464
465
465
const server = await buildServer ( )
466
466
const proxy = await buildProxy ( )
467
467
468
468
const serverUrl = `http://localhost:${ server . address ( ) . port } `
469
469
const proxyUrl = `http://localhost:${ proxy . address ( ) . port } `
470
470
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
473
474
}
474
475
475
476
const proxyAgent = new ProxyAgent ( proxyUrl )
@@ -488,15 +489,16 @@ test('should throw when proxy does not return 200', async (t) => {
488
489
} )
489
490
490
491
test ( 'pass ProxyAgent proxy status code error when using fetch - #2161' , async ( t ) => {
491
- t = tspl ( t , { plan : 1 } )
492
+ t = tspl ( t , { plan : 2 } )
492
493
const server = await buildServer ( )
493
494
const proxy = await buildProxy ( )
494
495
495
496
const serverUrl = `http://localhost:${ server . address ( ) . port } `
496
497
const proxyUrl = `http://localhost:${ proxy . address ( ) . port } `
497
498
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
500
502
}
501
503
502
504
const proxyAgent = new ProxyAgent ( proxyUrl )
@@ -742,8 +744,8 @@ function buildSSLServer () {
742
744
function buildProxy ( listener ) {
743
745
return new Promise ( ( resolve ) => {
744
746
const server = listener
745
- ? proxy ( createServer ( listener ) )
746
- : proxy ( createServer ( ) )
747
+ ? createProxy ( createServer ( listener ) )
748
+ : createProxy ( createServer ( ) )
747
749
server . listen ( 0 , ( ) => resolve ( server ) )
748
750
} )
749
751
}
@@ -758,7 +760,7 @@ function buildSSLProxy () {
758
760
}
759
761
760
762
return new Promise ( ( resolve ) => {
761
- const server = proxy ( https . createServer ( serverOptions ) )
763
+ const server = createProxy ( https . createServer ( serverOptions ) )
762
764
server . listen ( 0 , ( ) => resolve ( server ) )
763
765
} )
764
766
}
0 commit comments