@@ -10,7 +10,7 @@ import { runProxiedRequest } from '../common/proxy-server.js';
1010const server = http . createServer ( common . mustCall ( ( req , res ) => {
1111 res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
1212 res . end ( 'Hello World\n' ) ;
13- } , 11 ) ) ;
13+ } , 8 ) ) ;
1414server . on ( 'error' , common . mustNotCall ( ( err ) => { console . error ( 'Server error' , err ) ; } ) ) ;
1515server . listen ( 0 , '127.0.0.1' ) ;
1616await once ( server , 'listening' ) ;
@@ -98,72 +98,32 @@ await once(proxy, 'listening');
9898}
9999
100100{
101- // Test NO_PROXY with a trailing comma still matching the real entries.
102- const { code, signal, stderr, stdout } = await runProxiedRequest ( {
103- NODE_USE_ENV_PROXY : 1 ,
104- REQUEST_URL : `http://test.example.com:${ server . address ( ) . port } /test` ,
105- HTTP_PROXY : `http://localhost:${ proxy . address ( ) . port } ` ,
106- RESOLVE_TO_LOCALHOST : 'test.example.com' ,
107- NO_PROXY : 'example.com,' ,
108- } ) ;
109-
110- // The request should succeed and bypass proxy.
111- assert . match ( stdout , / S t a t u s C o d e : 2 0 0 / ) ;
112- assert . match ( stdout , / H e l l o W o r l d / ) ;
113- assert . match ( stdout , / R e s o l v i n g l o o k u p f o r t e s t \. e x a m p l e \. c o m / ) ;
114- assert . strictEqual ( stderr . trim ( ) , '' ) ;
115- assert . strictEqual ( code , 0 ) ;
116- assert . strictEqual ( signal , null ) ;
117- }
118-
119- {
120- // Test NO_PROXY with an empty entry (trailing comma) should NOT match
121- // hostnames ending with a dot.
122- const { code, signal, stderr, stdout } = await runProxiedRequest ( {
123- NODE_USE_ENV_PROXY : 1 ,
124- REQUEST_URL : `http://evil.com.:${ server . address ( ) . port } /test` ,
125- HTTP_PROXY : `http://localhost:${ server . address ( ) . port } ` ,
126- RESOLVE_TO_LOCALHOST : 'evil.com.' ,
127- NO_PROXY : 'example.com,' ,
128- } ) ;
129-
130- // The request should go through the proxy (not bypass it): the empty
131- // entry must not match, and evil.com. does not match example.com.
132- assert . match ( stdout , / S t a t u s C o d e : 2 0 0 / ) ;
133- assert . doesNotMatch ( stdout , / R e s o l v i n g l o o k u p f o r e v i l \. c o m / ) ;
134- assert . strictEqual ( stderr . trim ( ) , '' ) ;
135- assert . strictEqual ( code , 0 ) ;
136- assert . strictEqual ( signal , null ) ;
137- }
138-
139- {
140- // Test NO_PROXY with a lone "." entry should NOT match hostnames ending
141- // with a dot.
101+ // Test NO_PROXY with a plain domain should NOT match partial domain names.
142102 const { code, signal, stderr, stdout } = await runProxiedRequest ( {
143103 NODE_USE_ENV_PROXY : 1 ,
144- REQUEST_URL : `http://evil .com. :${ server . address ( ) . port } /test` ,
104+ REQUEST_URL : `http://badexample .com:${ server . address ( ) . port } /test` ,
145105 HTTP_PROXY : `http://localhost:${ server . address ( ) . port } ` ,
146- RESOLVE_TO_LOCALHOST : 'evil .com. ' ,
147- NO_PROXY : '. ' ,
106+ RESOLVE_TO_LOCALHOST : 'badexample .com' ,
107+ NO_PROXY : 'example.com ' ,
148108 } ) ;
149109
150- // The request should go through the proxy (not bypass it).
110+ // The request should go through the proxy (not bypass it),
111+ // because badexample.com is not a subdomain of example.com.
151112 assert . match ( stdout , / S t a t u s C o d e : 2 0 0 / ) ;
152- assert . doesNotMatch ( stdout , / R e s o l v i n g l o o k u p f o r e v i l \. c o m / ) ;
113+ assert . doesNotMatch ( stdout , / R e s o l v i n g l o o k u p f o r b a d e x a m p l e \. c o m / ) ;
153114 assert . strictEqual ( stderr . trim ( ) , '' ) ;
154115 assert . strictEqual ( code , 0 ) ;
155116 assert . strictEqual ( signal , null ) ;
156117}
157118
158119{
159- // Test NO_PROXY with a bare "*." entry should NOT match hostnames ending
160- // with a dot.
120+ // Test that an empty plain entry does not match a hostname ending in a dot.
161121 const { code, signal, stderr, stdout } = await runProxiedRequest ( {
162122 NODE_USE_ENV_PROXY : 1 ,
163123 REQUEST_URL : `http://evil.com.:${ server . address ( ) . port } /test` ,
164124 HTTP_PROXY : `http://localhost:${ server . address ( ) . port } ` ,
165125 RESOLVE_TO_LOCALHOST : 'evil.com.' ,
166- NO_PROXY : '*. ' ,
126+ NO_PROXY : 'example.com, ' ,
167127 } ) ;
168128
169129 // The request should go through the proxy (not bypass it).
@@ -174,25 +134,6 @@ await once(proxy, 'listening');
174134 assert . strictEqual ( signal , null ) ;
175135}
176136
177- {
178- // Test NO_PROXY with a plain domain should NOT match partial domain names.
179- const { code, signal, stderr, stdout } = await runProxiedRequest ( {
180- NODE_USE_ENV_PROXY : 1 ,
181- REQUEST_URL : `http://badexample.com:${ server . address ( ) . port } /test` ,
182- HTTP_PROXY : `http://localhost:${ server . address ( ) . port } ` ,
183- RESOLVE_TO_LOCALHOST : 'badexample.com' ,
184- NO_PROXY : 'example.com' ,
185- } ) ;
186-
187- // The request should go through the proxy (not bypass it),
188- // because badexample.com is not a subdomain of example.com.
189- assert . match ( stdout , / S t a t u s C o d e : 2 0 0 / ) ;
190- assert . doesNotMatch ( stdout , / R e s o l v i n g l o o k u p f o r b a d e x a m p l e \. c o m / ) ;
191- assert . strictEqual ( stderr . trim ( ) , '' ) ;
192- assert . strictEqual ( code , 0 ) ;
193- assert . strictEqual ( signal , null ) ;
194- }
195-
196137// Test NO_PROXY with leading-dot entry should NOT match partial domain names.
197138// Regression test: .example.com must not match notexample.com or badexample.com.
198139{
0 commit comments