2 // WebProxyTest.cs - NUnit Test Cases for System.Net.WebProxy
\r
5 // Lawrence Pit (loz@cable.a2000.nl)
\r
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
\r
8 // (C) 2003 Martin Willemoes Hansen
\r
11 using NUnit.Framework;
\r
13 using System.Collections;
\r
16 using System.Threading;
\r
18 namespace MonoTests.System.Net
\r
22 public class WebProxyTest
\r
24 private Uri googleUri;
\r
25 private Uri yahooUri;
\r
26 private Uri apacheUri;
\r
29 public void GetReady () {
\r
30 googleUri = new Uri ("http://www.google.com");
\r
31 yahooUri = new Uri ("http://www.yahoo.com");
\r
32 apacheUri = new Uri ("http://www.apache.org");
\r
36 public void Constructors ()
\r
38 WebProxy p = new WebProxy ();
\r
39 Assertion.Assert("#1", p.Address == null);
\r
40 Assertion.AssertEquals ("#2", 0, p.BypassArrayList.Count);
\r
41 Assertion.AssertEquals ("#3", 0, p.BypassList.Length);
\r
42 Assertion.AssertEquals ("#4", false, p.BypassProxyOnLocal);
\r
44 p.BypassList = null;
\r
45 Assertion.Fail ("#5 not spec'd, but should follow ms.net implementation");
\r
46 } catch (ArgumentNullException) {}
\r
48 p = new WebProxy ("webserver.com", 8080);
\r
49 Assertion.AssertEquals ("#6", new Uri ("http://webserver.com:8080/"), p.Address);
\r
51 p = new WebProxy ("webserver");
\r
52 Assertion.AssertEquals ("#7", new Uri ("http://webserver"), p.Address);
\r
54 p = new WebProxy ("webserver.com");
\r
55 Assertion.AssertEquals ("#8", new Uri ("http://webserver.com"), p.Address);
\r
57 p = new WebProxy ("http://webserver.com");
\r
58 Assertion.AssertEquals ("#9", new Uri ("http://webserver.com"), p.Address);
\r
60 p = new WebProxy ("file://webserver");
\r
61 Assertion.AssertEquals ("#10", new Uri ("file://webserver"), p.Address);
\r
63 p = new WebProxy ("http://www.contoso.com", true, null, null);
\r
64 Assertion.AssertEquals ("#11", 0, p.BypassList.Length);
\r
65 Assertion.AssertEquals ("#12", 0, p.BypassArrayList.Count);
\r
68 p = new WebProxy ("http://contoso.com", true,
\r
69 new string [] {"?^!@#$%^&}{]["}, null);
\r
70 Assertion.Fail ("#13: illegal regular expression");
\r
71 } catch (ArgumentException) {
\r
76 public void BypassArrayList ()
\r
78 Uri proxy1 = new Uri("http://proxy.contoso.com");
\r
79 Uri proxy2 = new Uri ("http://proxy2.contoso.com");
\r
81 WebProxy p = new WebProxy (proxy1, true);
\r
82 p.BypassArrayList.Add ("http://proxy2.contoso.com");
\r
83 p.BypassArrayList.Add ("http://proxy2.contoso.com");
\r
84 Assertion.AssertEquals ("#1", 2, p.BypassList.Length);
\r
85 Assertion.Assert ("#2", !p.IsBypassed (new Uri ("http://www.google.com")));
\r
86 Assertion.Assert ("#3", p.IsBypassed (proxy2));
\r
87 Assertion.AssertEquals ("#4", proxy2, p.GetProxy (proxy2));
\r
89 p.BypassArrayList.Add ("?^!@#$%^&}{][");
\r
90 Assertion.AssertEquals ("#10", 3, p.BypassList.Length);
\r
92 Assertion.Assert ("#11", !p.IsBypassed (proxy2));
\r
93 Assertion.Assert ("#12", !p.IsBypassed (new Uri ("http://www.x.com")));
\r
94 Assertion.AssertEquals ("#13", proxy1, p.GetProxy (proxy2));
\r
95 // hmm... although #11 and #13 succeeded before (#3 resp. #4),
\r
96 // it now fails to bypass, and the IsByPassed and GetProxy
\r
97 // methods do not fail.. so when an illegal regular
\r
98 // expression is added through this property it's ignored.
\r
99 // probably an ms.net bug?? :(
\r
100 } catch (ArgumentException) {
\r
101 Assertion.Fail ("#15: illegal regular expression");
\r
106 public void BypassList ()
\r
108 Uri proxy1 = new Uri("http://proxy.contoso.com");
\r
109 Uri proxy2 = new Uri ("http://proxy2.contoso.com");
\r
111 WebProxy p = new WebProxy (proxy1, true);
\r
113 p.BypassList = new string [] {"http://proxy2.contoso.com", "?^!@#$%^&}{]["};
\r
114 Assertion.Fail ("#1");
\r
115 } catch (ArgumentException) {
\r
116 // weird, this way invalid regex's fail again..
\r
119 Assertion.AssertEquals ("#2", 2, p.BypassList.Length);
\r
120 // but it did apparenly store the regex's !
\r
122 p.BypassList = new string [] {"http://www.x.com"};
\r
123 Assertion.AssertEquals ("#3", 1, p.BypassList.Length);
\r
126 p.BypassList = null;
\r
127 Assertion.Fail ("#4");
\r
128 } catch (ArgumentNullException) {}
\r
130 Assertion.AssertEquals ("#4", 1, p.BypassList.Length);
\r
134 public void GetProxy ()
\r
139 public void IsByPassed ()
\r
141 WebProxy p = new WebProxy ("http://proxy.contoso.com", true);
\r
142 Assertion.Assert ("#1", !p.IsBypassed (new Uri ("http://www.google.com")));
\r
143 Assertion.Assert ("#2", p.IsBypassed (new Uri ("http://localhost/index.html")));
\r
144 Assertion.Assert ("#3", p.IsBypassed (new Uri ("http://localhost:8080/index.html")));
\r
145 Assertion.Assert ("#4", p.IsBypassed (new Uri ("http://loopback:8080/index.html")));
\r
146 Assertion.Assert ("#5", p.IsBypassed (new Uri ("http://127.0.0.01:8080/index.html")));
\r
147 Assertion.Assert ("#6", p.IsBypassed (new Uri ("http://webserver/index.html")));
\r
148 Assertion.Assert ("#7", !p.IsBypassed (new Uri ("http://webserver.com/index.html")));
\r
150 p.IsBypassed (null);
\r
151 Assertion.Fail ("#8 not spec'd, but should follow ms.net implementation");
\r
152 } catch (NullReferenceException) {}
\r
154 p = new WebProxy ("http://proxy.contoso.com", false);
\r
155 Assertion.Assert ("#11", !p.IsBypassed (new Uri ("http://www.google.com")));
\r
156 Assertion.Assert ("#12: lamespec of ms.net", p.IsBypassed (new Uri ("http://localhost/index.html")));
\r
157 Assertion.Assert ("#13: lamespec of ms.net", p.IsBypassed (new Uri ("http://localhost:8080/index.html")));
\r
158 Assertion.Assert ("#14: lamespec of ms.net", p.IsBypassed (new Uri ("http://loopback:8080/index.html")));
\r
159 Assertion.Assert ("#15: lamespec of ms.net", p.IsBypassed (new Uri ("http://127.0.0.01:8080/index.html")));
\r
160 Assertion.Assert ("#16", !p.IsBypassed (new Uri ("http://webserver/index.html")));
\r
162 p.BypassList = new string [] { "google.com", "contoso.com" };
\r
163 Assertion.Assert ("#20", p.IsBypassed (new Uri ("http://www.google.com")));
\r
164 Assertion.Assert ("#21", p.IsBypassed (new Uri ("http://www.GOOGLE.com")));
\r
165 Assertion.Assert ("#22", p.IsBypassed (new Uri ("http://www.contoso.com:8080/foo/bar/index.html")));
\r
166 Assertion.Assert ("#23", !p.IsBypassed (new Uri ("http://www.contoso2.com:8080/foo/bar/index.html")));
\r
167 Assertion.Assert ("#24", !p.IsBypassed (new Uri ("http://www.foo.com:8080/contoso.com.html")));
\r
169 p.BypassList = new string [] { "https" };
\r
170 Assertion.Assert ("#30", !p.IsBypassed (new Uri ("http://www.google.com")));
\r
171 Assertion.Assert ("#31", p.IsBypassed (new Uri ("https://www.google.com")));
\r