@@ -73,3 +73,81 @@ describe('with http proxy only', () => {
7373 } )
7474 } )
7575} )
76+
77+ describe ( 'with no_proxy' , ( ) => {
78+ beforeEach ( ( ) => {
79+ Proxy . env . HTTP_PROXY = 'http://user:[email protected] ' 80+ Proxy . env . NO_PROXY = 'some.com,test-domain.com'
81+ } )
82+
83+ test ( 'is an exact match of no_proxy' , ( ) => {
84+ expect ( Proxy . agent ( false , 'test-domain.com' ) ) . toBeUndefined ( )
85+ } )
86+
87+ test ( 'is a subdomain of no_proxy' , ( ) => {
88+ expect ( Proxy . agent ( false , 'something.prod.test-domain.com' ) ) . toBeUndefined ( )
89+ } )
90+
91+ test ( 'should be proxied' , ( ) => {
92+ expect ( Proxy . agent ( false , 'proxied-domain.com' ) ) . toMatchObject ( {
93+ options : {
94+ proxy : {
95+ host : 'foo.com' ,
96+ port : '8080' ,
97+ proxyAuth : 'user:pass' ,
98+ } ,
99+ } ,
100+ proxyOptions : {
101+ host : 'foo.com' ,
102+ port : '8080' ,
103+ proxyAuth : 'user:pass' ,
104+ } ,
105+ } )
106+ } )
107+ } )
108+
109+ describe ( 'proxy dodging' , ( ) => {
110+ test ( 'not set should proxy' , ( ) => {
111+ Proxy . env . NO_PROXY = ''
112+ expect ( Proxy . shouldDodgeProxy ( 'test-domain.com' ) ) . toBe ( false )
113+ expect ( Proxy . shouldDodgeProxy ( 'other-domain.com' ) ) . toBe ( false )
114+ } )
115+
116+ test ( 'wildcard proxies any' , ( ) => {
117+ Proxy . env . NO_PROXY = '*'
118+ expect ( Proxy . shouldDodgeProxy ( 'test-domain.com' ) ) . toBe ( true )
119+ expect ( Proxy . shouldDodgeProxy ( 'anything.other-domain.com' ) ) . toBe ( true )
120+ } )
121+
122+ test ( 'exact domain should also match subdomains' , ( ) => {
123+ Proxy . env . NO_PROXY = 'test-domain.com'
124+ expect ( Proxy . shouldDodgeProxy ( 'test-domain.com' ) ) . toBe ( true )
125+ expect ( Proxy . shouldDodgeProxy ( 'anything.test-domain.com' ) ) . toBe ( true )
126+ expect ( Proxy . shouldDodgeProxy ( 'other-domain.com' ) ) . toBe ( false )
127+ expect ( Proxy . shouldDodgeProxy ( 'anything.other-domain.com' ) ) . toBe ( false )
128+ } )
129+
130+ test ( 'any sub domain should include the domain itself' , ( ) => {
131+ Proxy . env . NO_PROXY = '.test-domain.com'
132+ expect ( Proxy . shouldDodgeProxy ( 'test-domain.com' ) ) . toBe ( true )
133+ expect ( Proxy . shouldDodgeProxy ( 'anything.test-domain.com' ) ) . toBe ( true )
134+ expect ( Proxy . shouldDodgeProxy ( 'other-domain.com' ) ) . toBe ( false )
135+ expect ( Proxy . shouldDodgeProxy ( 'anything.other-domain.com' ) ) . toBe ( false )
136+ } )
137+
138+ test ( 'multiple domains' , ( ) => {
139+ Proxy . env . NO_PROXY = '.test-domain.com, .other-domain.com'
140+ expect ( Proxy . shouldDodgeProxy ( 'test-domain.com' ) ) . toBe ( true )
141+ expect ( Proxy . shouldDodgeProxy ( 'anything.test-domain.com' ) ) . toBe ( true )
142+ expect ( Proxy . shouldDodgeProxy ( 'other-domain.com' ) ) . toBe ( true )
143+ expect ( Proxy . shouldDodgeProxy ( 'anything.other-domain.com' ) ) . toBe ( true )
144+ } )
145+
146+ test ( 'match any subdomains' , ( ) => {
147+ Proxy . env . NO_PROXY = '.test-domain.com, other-domain.com'
148+ expect ( Proxy . shouldDodgeProxy ( 'test-domain.com' ) ) . toBe ( true )
149+ expect ( Proxy . shouldDodgeProxy ( 'something.something-else.anything.test-domain.com' ) ) . toBe ( true )
150+ expect ( Proxy . shouldDodgeProxy ( 'other-domain.com' ) ) . toBe ( true )
151+ expect ( Proxy . shouldDodgeProxy ( 'something.anything.other-domain.com' ) ) . toBe ( true )
152+ } )
153+ } )
0 commit comments