@@ -1545,7 +1545,7 @@ nodeOnly(() => {
15451545 describe ( "when configured to transform requests automatically" , ( ) => {
15461546
15471547 beforeEach ( async ( ) => {
1548- server = getLocal ( { debug : true } ) ;
1548+ server = getLocal ( ) ;
15491549 await server . start ( ) ;
15501550 process . env = _ . merge ( { } , process . env , server . proxyEnv ) ;
15511551
@@ -1868,7 +1868,7 @@ nodeOnly(() => {
18681868 describe ( "when configured to transform responses automatically" , ( ) => {
18691869
18701870 beforeEach ( async ( ) => {
1871- server = getLocal ( { debug : true } ) ;
1871+ server = getLocal ( ) ;
18721872 await server . start ( ) ;
18731873 process . env = _ . merge ( { } , process . env , server . proxyEnv ) ;
18741874
@@ -2166,11 +2166,11 @@ nodeOnly(() => {
21662166
21672167 describe ( "when configured to use an upstream proxy" , ( ) => {
21682168
2169- const intermediateProxy = getLocal ( { debug : true } ) ;
2169+ const intermediateProxy = getLocal ( ) ;
21702170 let proxyEndpoint : MockedEndpoint ;
21712171
21722172 beforeEach ( async ( ) => {
2173- server = getLocal ( { debug : true } ) ;
2173+ server = getLocal ( ) ;
21742174 await server . start ( ) ;
21752175
21762176 await intermediateProxy . start ( ) ;
@@ -2200,6 +2200,143 @@ nodeOnly(() => {
22002200 // And it went via the intermediate proxy
22012201 expect ( ( await proxyEndpoint . getSeenRequests ( ) ) . length ) . to . equal ( 1 ) ;
22022202 } ) ;
2203+
2204+ it ( "should skip the proxy if the target is in the no-proxy list" , async ( ) => {
2205+ // Remote server sends fixed response on this one URL:
2206+ await remoteServer . get ( '/test-url' ) . thenReply ( 200 , "Remote server says hi!" ) ;
2207+
2208+ // Mockttp forwards requests via our intermediate proxy
2209+ await server . anyRequest ( ) . thenPassThrough ( {
2210+ proxyConfig : {
2211+ proxyUrl : intermediateProxy . url ,
2212+ noProxy : [ 'localhost' ]
2213+ }
2214+ } ) ;
2215+
2216+ const response = await request . get ( remoteServer . urlFor ( "/test-url" ) ) ;
2217+
2218+ // We get a successful response
2219+ expect ( response ) . to . equal ( "Remote server says hi!" ) ;
2220+
2221+ // And it didn't use the proxy
2222+ expect ( ( await proxyEndpoint . getSeenRequests ( ) ) . length ) . to . equal ( 0 ) ;
2223+ } ) ;
2224+
2225+ it ( "should skip the proxy if the target is in the no-proxy list with a matching port" , async ( ) => {
2226+ // Remote server sends fixed response on this one URL:
2227+ await remoteServer . get ( '/test-url' ) . thenReply ( 200 , "Remote server says hi!" ) ;
2228+
2229+ // Mockttp forwards requests via our intermediate proxy
2230+ await server . anyRequest ( ) . thenPassThrough ( {
2231+ proxyConfig : {
2232+ proxyUrl : intermediateProxy . url ,
2233+ noProxy : [ `localhost:${ remoteServer . port } ` ]
2234+ }
2235+ } ) ;
2236+
2237+ const response = await request . get ( remoteServer . urlFor ( "/test-url" ) ) ;
2238+
2239+ // We get a successful response
2240+ expect ( response ) . to . equal ( "Remote server says hi!" ) ;
2241+
2242+ // And it didn't use the proxy
2243+ expect ( ( await proxyEndpoint . getSeenRequests ( ) ) . length ) . to . equal ( 0 ) ;
2244+ } ) ;
2245+
2246+ it ( "should skip the proxy if the target's implicit port is in the no-proxy list" , async ( ) => {
2247+ // Mockttp forwards requests via our intermediate proxy
2248+ await server . anyRequest ( ) . thenPassThrough ( {
2249+ proxyConfig : {
2250+ proxyUrl : intermediateProxy . url ,
2251+ noProxy : [ 'example.com:80' ]
2252+ }
2253+ } ) ;
2254+
2255+ await request . get ( 'http://example.com/' ) . catch ( ( ) => { } ) ;
2256+
2257+ // And it didn't use the proxy
2258+ expect ( ( await proxyEndpoint . getSeenRequests ( ) ) . length ) . to . equal ( 0 ) ;
2259+ } ) ;
2260+
2261+ it ( "should skip the proxy if a suffix of the target is in the no-proxy list" , async ( ) => {
2262+ // Remote server sends fixed response on this one URL:
2263+ await remoteServer . get ( '/test-url' ) . thenReply ( 200 , "Remote server says hi!" ) ;
2264+
2265+ // Mockttp forwards requests via our intermediate proxy
2266+ await server . anyRequest ( ) . thenPassThrough ( {
2267+ proxyConfig : {
2268+ proxyUrl : intermediateProxy . url ,
2269+ noProxy : [ 'localhost' ]
2270+ }
2271+ } ) ;
2272+
2273+ const response = await request . get (
2274+ `http://test-subdomain.localhost:${ remoteServer . port } /test-url`
2275+ ) ;
2276+
2277+ // We get a successful response
2278+ expect ( response ) . to . equal ( "Remote server says hi!" ) ;
2279+
2280+ // And it didn't use the proxy
2281+ expect ( ( await proxyEndpoint . getSeenRequests ( ) ) . length ) . to . equal ( 0 ) ;
2282+ } ) ;
2283+
2284+ it ( "should not skip the proxy if an unrelated URL is in the no-proxy list" , async ( ) => {
2285+ // Remote server sends fixed response on this one URL:
2286+ await remoteServer . get ( '/test-url' ) . thenReply ( 200 , "Remote server says hi!" ) ;
2287+
2288+ // Mockttp forwards requests via our intermediate proxy
2289+ await server . anyRequest ( ) . thenPassThrough ( {
2290+ proxyConfig : {
2291+ proxyUrl : intermediateProxy . url ,
2292+ noProxy : [ 'example.com' ]
2293+ }
2294+ } ) ;
2295+
2296+ const response = await request . get ( remoteServer . urlFor ( "/test-url" ) ) ;
2297+
2298+ // We get a successful response
2299+ expect ( response ) . to . equal ( "Remote server says hi!" ) ;
2300+
2301+ // And it went via the intermediate proxy
2302+ expect ( ( await proxyEndpoint . getSeenRequests ( ) ) . length ) . to . equal ( 1 ) ;
2303+ } ) ;
2304+
2305+ it ( "should not skip the proxy if the target's port is not in the no-proxy list" , async ( ) => {
2306+ // Remote server sends fixed response on this one URL:
2307+ await remoteServer . get ( '/test-url' ) . thenReply ( 200 , "Remote server says hi!" ) ;
2308+
2309+ // Mockttp forwards requests via our intermediate proxy
2310+ await server . anyRequest ( ) . thenPassThrough ( {
2311+ proxyConfig : {
2312+ proxyUrl : intermediateProxy . url ,
2313+ noProxy : [ 'localhost:1234' ]
2314+ }
2315+ } ) ;
2316+
2317+ const response = await request . get ( remoteServer . urlFor ( "/test-url" ) ) ;
2318+
2319+ // We get a successful response
2320+ expect ( response ) . to . equal ( "Remote server says hi!" ) ;
2321+
2322+ // And it went via the intermediate proxy
2323+ expect ( ( await proxyEndpoint . getSeenRequests ( ) ) . length ) . to . equal ( 1 ) ;
2324+ } ) ;
2325+
2326+ it ( "should not skip the proxy if the target's implicit port is not in the no-proxy list" , async ( ) => {
2327+ // Mockttp forwards requests via our intermediate proxy
2328+ await server . anyRequest ( ) . thenPassThrough ( {
2329+ proxyConfig : {
2330+ proxyUrl : intermediateProxy . url ,
2331+ noProxy : [ 'example.com:443' ]
2332+ }
2333+ } ) ;
2334+
2335+ await request . get ( 'http://example.com/' ) . catch ( ( ) => { } ) ;
2336+
2337+ // And it didn't use the proxy
2338+ expect ( ( await proxyEndpoint . getSeenRequests ( ) ) . length ) . to . equal ( 1 ) ;
2339+ } ) ;
22032340 } ) ;
22042341
22052342 describe ( "when configured with custom DNS options" , function ( ) {
0 commit comments