@@ -137,9 +137,9 @@ describe('proxy option', function() {
137
137
} ) )
138
138
} )
139
139
140
- it ( 'proxies request if matching host in list but different port' , function ( done ) {
140
+ it ( 'does not proxy request if matching host in list and just has a different port' , function ( done ) {
141
141
process . env . NO_PROXY = 'localhost' ;
142
- send_request ( { proxy : nonexisting_host + ':123/done' } , proxied ( nonexisting_host , '123' , function ( ) {
142
+ send_request ( { proxy : nonexisting_host + ':123/done' } , not_proxied ( function ( ) {
143
143
delete process . env . NO_PROXY ;
144
144
done ( ) ;
145
145
} ) )
@@ -152,6 +152,96 @@ describe('proxy option', function() {
152
152
done ( ) ;
153
153
} ) )
154
154
} )
155
+
156
+ describe ( 'should_proxy_to()' , function ( ) {
157
+
158
+ const noProxy = ".ic1.mycorp,localhost,127.0.0.1,*.mycorp.org" ;
159
+ const noProxyWithPorts = " ,.mycorp.org:1234,.ic1.mycorp,localhost,127.0.0.1" ;
160
+ const URI = "http://registry.random.opr.mycorp.org" ;
161
+ const URIWithPort = "http://registry.random.opr.mycorp.org:9874" ;
162
+ const URIWithPort1234 = "http://registry.random.opr.mycorp.org:1234" ;
163
+ const URIlocalhost = "http://localhost" ;
164
+ const URIip = "http://127.0.0.1" ;
165
+
166
+ it ( "shall return true if NO_PROXY is undefined" , function ( done ) {
167
+ process . env . NO_PROXY = undefined ;
168
+ needle . should_proxy_to ( URI ) . should . true ( )
169
+ delete process . env . NO_PROXY ;
170
+ done ( ) ;
171
+ } ) ;
172
+
173
+ it ( "shall return true if NO_PROXY is empty" , function ( done ) {
174
+ process . env . NO_PROXY = "" ;
175
+ needle . should_proxy_to ( URI ) . should . true ( )
176
+ delete process . env . NO_PROXY ;
177
+ done ( ) ;
178
+ } ) ;
179
+
180
+ it ( "shall return true if the host matches and the ports don't (URI doesn't have port specified)" , function ( done ) {
181
+ process . env . NO_PROXY = noProxyWithPorts ;
182
+ needle . should_proxy_to ( URI ) . should . true ( )
183
+ delete process . env . NO_PROXY ;
184
+ done ( ) ;
185
+ } ) ;
186
+
187
+ it ( "shall return true if the host matches and the ports don't (both have a port specified but just different values)" , function ( done ) {
188
+ process . env . NO_PROXY = noProxyWithPorts ;
189
+ needle . should_proxy_to ( URIWithPort ) . should . true ( )
190
+ delete process . env . NO_PROXY ;
191
+ done ( ) ;
192
+ } ) ;
193
+
194
+ it ( "shall return false if the host matches and the ports don't (no_proxy pattern doesn't have a port)" , function ( done ) {
195
+ process . env . NO_PROXY = noProxy ;
196
+ needle . should_proxy_to ( URIWithPort ) . should . false ( )
197
+ delete process . env . NO_PROXY ;
198
+ done ( ) ;
199
+ } ) ;
200
+
201
+ it ( "shall return false if host matches" , function ( done ) {
202
+ process . env . NO_PROXY = noProxy ;
203
+ needle . should_proxy_to ( URI ) . should . false ( )
204
+ delete process . env . NO_PROXY ;
205
+ done ( ) ;
206
+ } ) ;
207
+
208
+ it ( "shall return false if the host and port matches" , function ( done ) {
209
+ process . env . NO_PROXY = noProxyWithPorts ;
210
+ needle . should_proxy_to ( URIWithPort1234 ) . should . false ( )
211
+ delete process . env . NO_PROXY ;
212
+ done ( ) ;
213
+ } ) ;
214
+
215
+ it ( "shall return false if the host matches (localhost)" , function ( done ) {
216
+ process . env . NO_PROXY = noProxy ;
217
+ needle . should_proxy_to ( URIlocalhost ) . should . false ( )
218
+ delete process . env . NO_PROXY ;
219
+ done ( ) ;
220
+ } ) ;
221
+
222
+ it ( "shall return false if the host matches (ip)" , function ( done ) {
223
+ process . env . NO_PROXY = noProxy ;
224
+ needle . should_proxy_to ( URIip ) . should . false ( )
225
+ delete process . env . NO_PROXY ;
226
+ done ( ) ;
227
+ } ) ;
228
+
229
+ it ( "shall return false if the host matches (ip)" , function ( done ) {
230
+ process . env . NO_PROXY = noProxy . replace ( / , g / , " " ) ;
231
+ needle . should_proxy_to ( URIip ) . should . false ( )
232
+ delete process . env . NO_PROXY ;
233
+ done ( ) ;
234
+ } ) ;
235
+
236
+ it ( "shall return false if the host matches (ip)" , function ( done ) {
237
+ process . env . NO_PROXY = noProxy . replace ( / , g / , " " ) ;
238
+ needle . should_proxy_to ( URIip ) . should . false ( )
239
+ delete process . env . NO_PROXY ;
240
+ done ( ) ;
241
+ } ) ;
242
+
243
+ } )
244
+
155
245
} )
156
246
157
247
describe ( 'and proxy url contains user:pass' , function ( ) {
0 commit comments