@@ -308,11 +308,15 @@ describe("networkProxy", () => {
308308
309309 describe ( "getSystemProxyUrl" , ( ) => {
310310 beforeEach ( ( ) => {
311- // Clear env vars before each test
311+ vi . clearAllMocks ( )
312+ // Clear all proxy env vars and VS Code setting before each test
312313 delete process . env . HTTPS_PROXY
313314 delete process . env . https_proxy
314315 delete process . env . HTTP_PROXY
315316 delete process . env . http_proxy
317+ delete process . env . NO_PROXY
318+ delete process . env . no_proxy
319+ mockConfig . get . mockReturnValue ( undefined )
316320 } )
317321
318322 it ( "should return proxy from HTTPS_PROXY env var" , ( ) => {
@@ -368,5 +372,101 @@ describe("networkProxy", () => {
368372 const result = getSystemProxyUrl ( )
369373 expect ( result ) . toBe ( "http://env-proxy:3128" )
370374 } )
375+
376+ it ( "should trim whitespace from env var proxy values" , ( ) => {
377+ process . env . HTTPS_PROXY = " http://proxy.corp:3128 "
378+ const result = getSystemProxyUrl ( )
379+ expect ( result ) . toBe ( "http://proxy.corp:3128" )
380+ } )
381+
382+ it ( "should reject whitespace-only proxy values" , ( ) => {
383+ process . env . HTTPS_PROXY = " "
384+ const result = getSystemProxyUrl ( )
385+ expect ( result ) . toBeUndefined ( )
386+ } )
387+
388+ it ( "should skip empty env var and try next fallback" , ( ) => {
389+ process . env . HTTP_PROXY = " http://http-proxy:3128 "
390+ const result = getSystemProxyUrl ( )
391+ expect ( result ) . toBe ( "http://http-proxy:3128" )
392+ } )
393+
394+ it ( "should use VS Code setting when all env vars are empty" , ( ) => {
395+ mockConfig . get . mockReturnValue ( " http://vscode-proxy:8080 " )
396+ const result = getSystemProxyUrl ( )
397+ expect ( result ) . toBe ( "http://vscode-proxy:8080" )
398+ } )
399+
400+ describe ( "NO_PROXY handling" , ( ) => {
401+ it ( "should bypass proxy when NO_PROXY exactly matches the target host" , ( ) => {
402+ process . env . HTTPS_PROXY = "http://proxy.corp:3128"
403+ process . env . NO_PROXY = "bedrock.vpce.internal"
404+ const result = getSystemProxyUrl ( "https://bedrock.vpce.internal" )
405+ expect ( result ) . toBeUndefined ( )
406+ } )
407+
408+ it ( "should bypass proxy when NO_PROXY is a domain suffix of the target host" , ( ) => {
409+ process . env . HTTPS_PROXY = "http://proxy.corp:3128"
410+ process . env . NO_PROXY = "amazonaws.com"
411+ const result = getSystemProxyUrl ( "https://bedrock-runtime.us-east-1.amazonaws.com" )
412+ expect ( result ) . toBeUndefined ( )
413+ } )
414+
415+ it ( "should bypass proxy for all hosts when NO_PROXY is '*'" , ( ) => {
416+ process . env . HTTPS_PROXY = "http://proxy.corp:3128"
417+ process . env . NO_PROXY = "*"
418+ const result = getSystemProxyUrl ( "https://bedrock-runtime.us-east-1.amazonaws.com" )
419+ expect ( result ) . toBeUndefined ( )
420+ } )
421+
422+ it ( "should use the proxy when NO_PROXY does not match the target host" , ( ) => {
423+ process . env . HTTPS_PROXY = "http://proxy.corp:3128"
424+ process . env . NO_PROXY = "example.com"
425+ const result = getSystemProxyUrl ( "https://bedrock-runtime.us-east-1.amazonaws.com" )
426+ expect ( result ) . toBe ( "http://proxy.corp:3128" )
427+ } )
428+
429+ it ( "should handle leading dot and trailing port in NO_PROXY entries" , ( ) => {
430+ process . env . HTTPS_PROXY = "http://proxy.corp:3128"
431+ process . env . NO_PROXY = ".amazonaws.com:443"
432+ const result = getSystemProxyUrl ( "https://bedrock-runtime.us-east-1.amazonaws.com" )
433+ expect ( result ) . toBeUndefined ( )
434+ } )
435+
436+ it ( "should match one entry out of a comma-separated NO_PROXY list" , ( ) => {
437+ process . env . HTTPS_PROXY = "http://proxy.corp:3128"
438+ process . env . NO_PROXY = "example.com, amazonaws.com, other.net"
439+ const result = getSystemProxyUrl ( "https://bedrock-runtime.us-east-1.amazonaws.com" )
440+ expect ( result ) . toBeUndefined ( )
441+ } )
442+
443+ it ( "should use the proxy when no entry in a comma-separated NO_PROXY list matches" , ( ) => {
444+ process . env . HTTPS_PROXY = "http://proxy.corp:3128"
445+ process . env . NO_PROXY = "example.com, foo.net, other.org"
446+ const result = getSystemProxyUrl ( "https://bedrock-runtime.us-east-1.amazonaws.com" )
447+ expect ( result ) . toBe ( "http://proxy.corp:3128" )
448+ } )
449+
450+ it ( "should also bypass the VS Code proxy when NO_PROXY matches" , ( ) => {
451+ process . env . NO_PROXY = "amazonaws.com"
452+ mockConfig . get . mockReturnValue ( "http://vscode-proxy:8080" )
453+ const result = getSystemProxyUrl ( "https://bedrock-runtime.us-east-1.amazonaws.com" )
454+ expect ( result ) . toBeUndefined ( )
455+ } )
456+
457+ it ( "should ignore NO_PROXY when no target URL is provided" , ( ) => {
458+ process . env . HTTPS_PROXY = "http://proxy.corp:3128"
459+ process . env . NO_PROXY = "*"
460+ const result = getSystemProxyUrl ( )
461+ expect ( result ) . toBe ( "http://proxy.corp:3128" )
462+ } )
463+
464+ it ( "should not bypass when target URL is malformed" , ( ) => {
465+ process . env . HTTPS_PROXY = "http://proxy.corp:3128"
466+ process . env . NO_PROXY = "amazonaws.com"
467+ const result = getSystemProxyUrl ( "not-a-valid-url" )
468+ expect ( result ) . toBe ( "http://proxy.corp:3128" )
469+ } )
470+ } )
371471 } )
372472} )
0 commit comments