@@ -15,29 +15,53 @@ public class HttpSystemProxyTest : RemoteExecutorTestBase
1515 {
1616 private readonly ITestOutputHelper _output ;
1717 private const string FakeProxyString = "http://proxy.contoso.com" ;
18- private readonly Uri fakeProxyUri = new Uri ( "http://proxy.contoso.com" ) ;
19- private readonly Uri fooHttp = new Uri ( "http://foo.com" ) ;
20- private readonly Uri fooHttps = new Uri ( "https://foo.com" ) ;
18+ private const string insecureProxyUri = "http://proxy.insecure.com" ;
19+ private const string secureProxyUri = "http://proxy.secure.com" ;
20+ private const string fooHttp = "http://foo.com" ;
21+ private const string fooHttps = "https://foo.com" ;
22+ private const string fooWs = "ws://foo.com" ;
23+ private const string fooWss = "wss://foo.com" ;
2124
2225 public HttpSystemProxyTest ( ITestOutputHelper output )
2326 {
2427 _output = output ;
2528 }
2629
27- [ Fact ]
28- public void HttpProxy_SystemProxy_Loaded ( )
30+ [ Theory ]
31+ [ InlineData ( "http://proxy.insecure.com" , true , false ) ]
32+ [ InlineData ( "http=proxy.insecure.com" , true , false ) ]
33+ [ InlineData ( "http://proxy.insecure.com http://proxy.wrong.com" , true , false ) ]
34+ [ InlineData ( "https=proxy.secure.com http=proxy.insecure.com" , true , true ) ]
35+ [ InlineData ( "https://proxy.secure.com\n http://proxy.insecure.com" , true , true ) ]
36+ [ InlineData ( "https=proxy.secure.com\n http=proxy.insecure.com" , true , true ) ]
37+ [ InlineData ( "https://proxy.secure.com;http://proxy.insecure.com" , true , true ) ]
38+ [ InlineData ( "https=proxy.secure.com;http=proxy.insecure.com" , true , true ) ]
39+ [ InlineData ( ";http=proxy.insecure.com;;" , true , false ) ]
40+ [ InlineData ( " http=proxy.insecure.com " , true , false ) ]
41+ [ InlineData ( "http=proxy.insecure.com;http=proxy.wrong.com" , true , false ) ]
42+ [ InlineData ( "http=http://proxy.insecure.com" , true , false ) ]
43+ [ InlineData ( "https=https://proxy.secure.com" , false , true ) ]
44+ public void HttpProxy_SystemProxy_Loaded ( string rawProxyString , bool hasInsecureProxy , bool hasSecureProxy )
2945 {
30- IWebProxy p ;
46+ RemoteInvoke ( ( proxyString , insecureProxy , secureProxy ) =>
47+ {
48+ IWebProxy p ;
3149
32- FakeRegistry . Reset ( ) ;
33- Assert . False ( HttpSystemProxy . TryCreate ( out p ) ) ;
50+ FakeRegistry . Reset ( ) ;
51+ Assert . False ( HttpSystemProxy . TryCreate ( out p ) ) ;
3452
35- FakeRegistry . WinInetProxySettings . Proxy = FakeProxyString ;
53+ FakeRegistry . WinInetProxySettings . Proxy = proxyString ;
54+ WinInetProxyHelper proxyHelper = new WinInetProxyHelper ( ) ;
3655
37- Assert . True ( HttpSystemProxy . TryCreate ( out p ) ) ;
38- Assert . NotNull ( p ) ;
39- Assert . Equal ( fakeProxyUri , p . GetProxy ( fooHttp ) ) ;
40- Assert . Equal ( fakeProxyUri , p . GetProxy ( fooHttps ) ) ;
56+ Assert . True ( HttpSystemProxy . TryCreate ( out p ) ) ;
57+ Assert . NotNull ( p ) ;
58+
59+ Assert . Equal ( Boolean . Parse ( insecureProxy ) ? new Uri ( insecureProxyUri ) : null , p . GetProxy ( new Uri ( fooHttp ) ) ) ;
60+ Assert . Equal ( Boolean . Parse ( secureProxy ) ? new Uri ( secureProxyUri ) : null , p . GetProxy ( new Uri ( fooHttps ) ) ) ;
61+ Assert . Equal ( Boolean . Parse ( insecureProxy ) ? new Uri ( insecureProxyUri ) : null , p . GetProxy ( new Uri ( fooWs ) ) ) ;
62+ Assert . Equal ( Boolean . Parse ( secureProxy ) ? new Uri ( secureProxyUri ) : null , p . GetProxy ( new Uri ( fooWss ) ) ) ;
63+ return SuccessExitCode ;
64+ } , rawProxyString , hasInsecureProxy . ToString ( ) , hasSecureProxy . ToString ( ) ) . Dispose ( ) ;
4165 }
4266
4367 [ Theory ]
@@ -66,7 +90,7 @@ public void HttpProxy_Local_Bypassed(string name, bool shouldBypass)
6690 IWebProxy p ;
6791
6892 FakeRegistry . Reset ( ) ;
69- FakeRegistry . WinInetProxySettings . Proxy = FakeProxyString ;
93+ FakeRegistry . WinInetProxySettings . Proxy = insecureProxyUri ;
7094 FakeRegistry . WinInetProxySettings . ProxyBypass = "23.23.86.44;*.foo.com;<local>;BAR.COM; ; 162*;[2002::11];[*:f8b0:4005:80a::200e]; http://www.xn--mnchhausen-9db.at;http://*.xn--bb-bjab.eu;http://xn--bb-bjab.eu;" ;
7195
7296 Assert . True ( HttpSystemProxy . TryCreate ( out p ) ) ;
@@ -93,7 +117,7 @@ public void HttpProxy_Local_Parsing(string bypass, int count)
93117 IWebProxy p ;
94118
95119 FakeRegistry . Reset ( ) ;
96- FakeRegistry . WinInetProxySettings . Proxy = FakeProxyString ;
120+ FakeRegistry . WinInetProxySettings . Proxy = insecureProxyUri ;
97121 FakeRegistry . WinInetProxySettings . ProxyBypass = bypassValue ;
98122
99123 Assert . True ( HttpSystemProxy . TryCreate ( out p ) ) ;
@@ -112,7 +136,36 @@ public void HttpProxy_Local_Parsing(string bypass, int count)
112136 }
113137 return SuccessExitCode ;
114138 } , bypass , count . ToString ( ) ) . Dispose ( ) ;
139+ }
115140
141+ [ Theory ]
142+ [ InlineData ( "http://" ) ]
143+ [ InlineData ( "http=" ) ]
144+ [ InlineData ( "http://;" ) ]
145+ [ InlineData ( "http=;" ) ]
146+ [ InlineData ( " ; " ) ]
147+ [ InlineData ( "proxy.contoso.com" ) ]
148+ public void HttpProxy_InvalidSystemProxy_Null ( string rawProxyString )
149+ {
150+ RemoteInvoke ( ( proxyString ) =>
151+ {
152+ IWebProxy p ;
153+
154+ FakeRegistry . Reset ( ) ;
155+ Assert . False ( HttpSystemProxy . TryCreate ( out p ) ) ;
156+
157+ FakeRegistry . WinInetProxySettings . Proxy = proxyString ;
158+ WinInetProxyHelper proxyHelper = new WinInetProxyHelper ( ) ;
159+
160+ Assert . True ( HttpSystemProxy . TryCreate ( out p ) ) ;
161+ Assert . NotNull ( p ) ;
162+
163+ Assert . Equal ( null , p . GetProxy ( new Uri ( fooHttp ) ) ) ;
164+ Assert . Equal ( null , p . GetProxy ( new Uri ( fooHttps ) ) ) ;
165+ Assert . Equal ( null , p . GetProxy ( new Uri ( fooWs ) ) ) ;
166+ Assert . Equal ( null , p . GetProxy ( new Uri ( fooWss ) ) ) ;
167+ return SuccessExitCode ;
168+ } , rawProxyString ) . Dispose ( ) ;
116169 }
117170 }
118171}
0 commit comments