Lines 1-26
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2007 IBM Corporation and others. All rights reserved. This |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* program and the accompanying materials are made available under the terms of |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* the Eclipse Public License v1.0 which accompanies this distribution, and is |
5 |
* which accompanies this distribution, and is available at |
5 |
* available at http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* |
7 |
* |
7 |
* Contributors: IBM Corporation - initial API and implementation |
8 |
* Contributors: |
8 |
******************************************************************************/ |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
*******************************************************************************/ |
11 |
package org.eclipse.core.tests.net; |
9 |
package org.eclipse.core.tests.net; |
12 |
|
10 |
|
|
|
11 |
import java.net.URI; |
13 |
import java.util.*; |
12 |
import java.util.*; |
14 |
|
13 |
|
15 |
import junit.framework.*; |
14 |
import junit.framework.*; |
16 |
|
15 |
|
17 |
import org.eclipse.core.internal.net.ProxyType; |
16 |
import org.eclipse.core.internal.net.ProxyType; |
|
|
17 |
import org.eclipse.core.internal.net.UnixProxyProvider; |
18 |
import org.eclipse.core.net.proxy.AbstractProxyProvider; |
18 |
import org.eclipse.core.net.proxy.IProxyData; |
19 |
import org.eclipse.core.net.proxy.IProxyData; |
19 |
import org.eclipse.core.net.proxy.IProxyService; |
20 |
import org.eclipse.core.net.proxy.IProxyService; |
20 |
import org.eclipse.core.runtime.CoreException; |
21 |
import org.eclipse.core.runtime.CoreException; |
21 |
|
22 |
|
22 |
public class NetTest extends TestCase { |
23 |
public class NetTest extends TestCase { |
23 |
|
24 |
|
24 |
private boolean isSetEnabled; |
25 |
private boolean isSetEnabled; |
25 |
private Map dataCache = new HashMap(); |
26 |
private Map dataCache = new HashMap(); |
26 |
|
27 |
|
Lines 31-37
Link Here
|
31 |
public NetTest(String name) { |
32 |
public NetTest(String name) { |
32 |
super(name); |
33 |
super(name); |
33 |
} |
34 |
} |
34 |
|
35 |
|
35 |
public static Test suite() { |
36 |
public static Test suite() { |
36 |
return new TestSuite(NetTest.class); |
37 |
return new TestSuite(NetTest.class); |
37 |
} |
38 |
} |
Lines 43-49
Link Here
|
43 |
dataCache.clear(); |
44 |
dataCache.clear(); |
44 |
ProxyType.socksSystemPropertySetting = ProxyType.ALWAYS_SET; |
45 |
ProxyType.socksSystemPropertySetting = ProxyType.ALWAYS_SET; |
45 |
} |
46 |
} |
46 |
|
47 |
|
47 |
protected void tearDown() throws Exception { |
48 |
protected void tearDown() throws Exception { |
48 |
super.tearDown(); |
49 |
super.tearDown(); |
49 |
setProxiesEnabled(false); |
50 |
setProxiesEnabled(false); |
Lines 54-75
Link Here
|
54 |
} |
55 |
} |
55 |
getProxyManager().setProxyData(data); |
56 |
getProxyManager().setProxyData(data); |
56 |
} |
57 |
} |
57 |
|
58 |
|
58 |
private IProxyService getProxyManager() { |
59 |
private IProxyService getProxyManager() { |
59 |
return Activator.getDefault().getProxyService(); |
60 |
return Activator.getDefault().getProxyService(); |
60 |
} |
61 |
} |
61 |
|
62 |
|
62 |
private void assertProxyDataEqual(IProxyData expectedData) { |
63 |
private void assertProxyDataEqual(IProxyData expectedData) { |
63 |
IProxyData data = getProxyManager().getProxyData(expectedData.getType()); |
64 |
IProxyData data = getProxyManager() |
|
|
65 |
.getProxyData(expectedData.getType()); |
64 |
assertEquals(expectedData.getType(), data.getType()); |
66 |
assertEquals(expectedData.getType(), data.getType()); |
65 |
assertEquals(expectedData.getHost(), data.getHost()); |
67 |
assertEquals(expectedData.getHost(), data.getHost()); |
66 |
assertEquals(expectedData.getPort(), data.getPort()); |
68 |
assertEquals(expectedData.getPort(), data.getPort()); |
67 |
assertEquals(expectedData.getUserId(), data.getUserId()); |
69 |
assertEquals(expectedData.getUserId(), data.getUserId()); |
68 |
assertEquals(expectedData.getPassword(), data.getPassword()); |
70 |
assertEquals(expectedData.getPassword(), data.getPassword()); |
69 |
assertEquals(expectedData.isRequiresAuthentication(), data.isRequiresAuthentication()); |
71 |
assertEquals(expectedData.isRequiresAuthentication(), data |
|
|
72 |
.isRequiresAuthentication()); |
70 |
assertSystemPropertiesMatch(data); |
73 |
assertSystemPropertiesMatch(data); |
71 |
} |
74 |
} |
72 |
|
75 |
|
73 |
public void assertSystemPropertiesMatch(IProxyData proxyData) { |
76 |
public void assertSystemPropertiesMatch(IProxyData proxyData) { |
74 |
if (proxyData.getType().equals(IProxyData.HTTP_PROXY_TYPE)) { |
77 |
if (proxyData.getType().equals(IProxyData.HTTP_PROXY_TYPE)) { |
75 |
assertHttpSystemProperties(proxyData, "http"); |
78 |
assertHttpSystemProperties(proxyData, "http"); |
Lines 80-104
Link Here
|
80 |
} |
83 |
} |
81 |
} |
84 |
} |
82 |
|
85 |
|
83 |
private void assertHttpSystemProperties(IProxyData proxyData, String keyPrefix) { |
86 |
private void assertHttpSystemProperties(IProxyData proxyData, |
|
|
87 |
String keyPrefix) { |
84 |
Properties sysProps = System.getProperties(); |
88 |
Properties sysProps = System.getProperties(); |
85 |
|
89 |
|
86 |
if (this.getProxyManager().isProxiesEnabled()) { |
90 |
if (this.getProxyManager().isProxiesEnabled()) { |
87 |
boolean isSet = Boolean.getBoolean(keyPrefix + ".proxySet"); |
91 |
boolean isSet = Boolean.getBoolean(keyPrefix + ".proxySet"); |
88 |
assertEquals(proxyData.getHost() != null, isSet); //$NON-NLS-1$ |
92 |
assertEquals(proxyData.getHost() != null, isSet); //$NON-NLS-1$ |
89 |
assertEquals(proxyData.getHost(), sysProps.get(keyPrefix + ".proxyHost")); //$NON-NLS-1$ |
93 |
assertEquals(proxyData.getHost(), sysProps.get(keyPrefix |
90 |
String portString = (String)sysProps.get(keyPrefix + ".proxyPort"); //$NON-NLS-1$ |
94 |
+ ".proxyHost")); //$NON-NLS-1$ |
|
|
95 |
String portString = (String) sysProps.get(keyPrefix + ".proxyPort"); //$NON-NLS-1$ |
91 |
int port = -1; |
96 |
int port = -1; |
92 |
if (portString != null) |
97 |
if (portString != null) |
93 |
port = Integer.parseInt(portString); |
98 |
port = Integer.parseInt(portString); |
94 |
assertEquals(proxyData.getPort(), port); |
99 |
assertEquals(proxyData.getPort(), port); |
95 |
if (isSet) |
100 |
if (isSet) |
96 |
assertEquals(ProxyType.convertHostsToPropertyString(this.getProxyManager().getNonProxiedHosts()), sysProps.get(keyPrefix + ".nonProxyHosts")); //$NON-NLS-1$ |
101 |
assertEquals(ProxyType.convertHostsToPropertyString(this |
97 |
else |
102 |
.getProxyManager().getNonProxiedHosts()), sysProps |
|
|
103 |
.get(keyPrefix + ".nonProxyHosts")); //$NON-NLS-1$ |
104 |
else |
98 |
assertNull(sysProps.get(keyPrefix + ".nonProxyHosts")); |
105 |
assertNull(sysProps.get(keyPrefix + ".nonProxyHosts")); |
99 |
assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix + ".proxyUser")); //$NON-NLS-1$ |
106 |
assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix |
100 |
assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix + ".proxyUserName")); //$NON-NLS-1$ |
107 |
+ ".proxyUser")); //$NON-NLS-1$ |
101 |
assertEquals(proxyData.getPassword(), sysProps.get(keyPrefix + ".proxyPassword")); //$NON-NLS-1$ |
108 |
assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix |
|
|
109 |
+ ".proxyUserName")); //$NON-NLS-1$ |
110 |
assertEquals(proxyData.getPassword(), sysProps.get(keyPrefix |
111 |
+ ".proxyPassword")); //$NON-NLS-1$ |
102 |
} else { |
112 |
} else { |
103 |
assertNull(sysProps.get(keyPrefix + ".proxySet")); |
113 |
assertNull(sysProps.get(keyPrefix + ".proxySet")); |
104 |
assertNull(sysProps.get(keyPrefix + ".proxyHost")); |
114 |
assertNull(sysProps.get(keyPrefix + ".proxyHost")); |
Lines 114-120
Link Here
|
114 |
Properties sysProps = System.getProperties(); |
124 |
Properties sysProps = System.getProperties(); |
115 |
if (this.getProxyManager().isProxiesEnabled()) { |
125 |
if (this.getProxyManager().isProxiesEnabled()) { |
116 |
assertEquals(proxyData.getHost(), sysProps.get("socksProxyHost")); //$NON-NLS-1$ |
126 |
assertEquals(proxyData.getHost(), sysProps.get("socksProxyHost")); //$NON-NLS-1$ |
117 |
String portString = (String)sysProps.get("socksProxyPort"); //$NON-NLS-1$ |
127 |
String portString = (String) sysProps.get("socksProxyPort"); //$NON-NLS-1$ |
118 |
int port = -1; |
128 |
int port = -1; |
119 |
if (portString != null) |
129 |
if (portString != null) |
120 |
port = Integer.parseInt(portString); |
130 |
port = Integer.parseInt(portString); |
Lines 124-139
Link Here
|
124 |
assertNull(sysProps.get("socksProxyPort")); |
134 |
assertNull(sysProps.get("socksProxyPort")); |
125 |
} |
135 |
} |
126 |
} |
136 |
} |
127 |
|
137 |
|
128 |
private IProxyData getProxyData(String type) { |
138 |
private IProxyData getProxyData(String type) { |
129 |
IProxyData data = (IProxyData)dataCache.get(type); |
139 |
IProxyData data = (IProxyData) dataCache.get(type); |
130 |
if (data == null) { |
140 |
if (data == null) { |
131 |
data = this.getProxyManager().getProxyData(type); |
141 |
data = this.getProxyManager().getProxyData(type); |
132 |
assertProxyDataEqual(data); |
142 |
assertProxyDataEqual(data); |
133 |
} |
143 |
} |
134 |
return data; |
144 |
return data; |
135 |
} |
145 |
} |
136 |
|
146 |
|
137 |
private void setProxyData(IProxyData data) throws CoreException { |
147 |
private void setProxyData(IProxyData data) throws CoreException { |
138 |
if (isSetEnabled) { |
148 |
if (isSetEnabled) { |
139 |
this.getProxyManager().setProxyData(new IProxyData[] { data }); |
149 |
this.getProxyManager().setProxyData(new IProxyData[] { data }); |
Lines 142-153
Link Here
|
142 |
dataCache.put(data.getType(), data); |
152 |
dataCache.put(data.getType(), data); |
143 |
} |
153 |
} |
144 |
} |
154 |
} |
145 |
|
155 |
|
146 |
private void disableProxy(IProxyData proxyData) throws CoreException { |
156 |
private void disableProxy(IProxyData proxyData) throws CoreException { |
147 |
proxyData.disable(); |
157 |
proxyData.disable(); |
148 |
setProxyData(proxyData); |
158 |
setProxyData(proxyData); |
149 |
} |
159 |
} |
150 |
|
160 |
|
151 |
private void changeProxyData(IProxyData oldData, IProxyData data) |
161 |
private void changeProxyData(IProxyData oldData, IProxyData data) |
152 |
throws CoreException { |
162 |
throws CoreException { |
153 |
// Make sure that setting the host doesn't change the persisted settings |
163 |
// Make sure that setting the host doesn't change the persisted settings |
Lines 156-162
Link Here
|
156 |
// Now set it in the manager and assert that it is set |
166 |
// Now set it in the manager and assert that it is set |
157 |
setProxyData(data); |
167 |
setProxyData(data); |
158 |
} |
168 |
} |
159 |
|
169 |
|
160 |
private void setHost(String type) throws CoreException { |
170 |
private void setHost(String type) throws CoreException { |
161 |
String host = "www.eclipse.org"; |
171 |
String host = "www.eclipse.org"; |
162 |
setHost(type, host); |
172 |
setHost(type, host); |
Lines 168-206
Link Here
|
168 |
data.setHost(host); |
178 |
data.setHost(host); |
169 |
changeProxyData(oldData, data); |
179 |
changeProxyData(oldData, data); |
170 |
} |
180 |
} |
171 |
|
181 |
|
172 |
private void setPort(String type, int port) throws CoreException { |
182 |
private void setPort(String type, int port) throws CoreException { |
173 |
IProxyData data = getProxyData(type); |
183 |
IProxyData data = getProxyData(type); |
174 |
IProxyData oldData = getProxyData(type); |
184 |
IProxyData oldData = getProxyData(type); |
175 |
data.setPort(port); |
185 |
data.setPort(port); |
176 |
changeProxyData(oldData, data); |
186 |
changeProxyData(oldData, data); |
177 |
} |
187 |
} |
178 |
|
188 |
|
179 |
private void setUser(String type, String user, String password) throws CoreException { |
189 |
private void setUser(String type, String user, String password) |
|
|
190 |
throws CoreException { |
180 |
IProxyData data = getProxyData(type); |
191 |
IProxyData data = getProxyData(type); |
181 |
IProxyData oldData = getProxyData(type); |
192 |
IProxyData oldData = getProxyData(type); |
182 |
data.setUserid(user); |
193 |
data.setUserid(user); |
183 |
data.setPassword(password); |
194 |
data.setPassword(password); |
184 |
changeProxyData(oldData, data); |
195 |
changeProxyData(oldData, data); |
185 |
} |
196 |
} |
186 |
|
197 |
|
187 |
private void setDataTest(String type) throws CoreException { |
198 |
private void setDataTest(String type) throws CoreException { |
188 |
setHost(type, "www.eclipse.org"); |
199 |
setHost(type, "www.eclipse.org"); |
189 |
setPort(type, 1024); |
200 |
setPort(type, 1024); |
190 |
setUser(type, "me", "passw0rd"); |
201 |
setUser(type, "me", "passw0rd"); |
191 |
} |
202 |
} |
192 |
|
203 |
|
193 |
private void setProxiesEnabled(boolean enabled) { |
204 |
private void setProxiesEnabled(boolean enabled) { |
194 |
this.getProxyManager().setProxiesEnabled(enabled); |
205 |
this.getProxyManager().setProxiesEnabled(enabled); |
195 |
assertEquals(enabled, this.getProxyManager().isProxiesEnabled()); |
206 |
assertEquals(enabled, this.getProxyManager().isProxiesEnabled()); |
196 |
} |
207 |
} |
197 |
|
208 |
|
198 |
private void delaySettingData() { |
209 |
private void delaySettingData() { |
199 |
isSetEnabled = false; |
210 |
isSetEnabled = false; |
200 |
} |
211 |
} |
201 |
|
212 |
|
202 |
private void performSettingData() throws CoreException { |
213 |
private void performSettingData() throws CoreException { |
203 |
IProxyData[] data = (IProxyData[]) dataCache.values().toArray(new IProxyData[dataCache.size()]); |
214 |
IProxyData[] data = (IProxyData[]) dataCache.values().toArray( |
|
|
215 |
new IProxyData[dataCache.size()]); |
204 |
this.getProxyManager().setProxyData(data); |
216 |
this.getProxyManager().setProxyData(data); |
205 |
for (int i = 0; i < data.length; i++) { |
217 |
for (int i = 0; i < data.length; i++) { |
206 |
IProxyData proxyData = data[i]; |
218 |
IProxyData proxyData = data[i]; |
Lines 209-215
Link Here
|
209 |
isSetEnabled = true; |
221 |
isSetEnabled = true; |
210 |
dataCache.clear(); |
222 |
dataCache.clear(); |
211 |
} |
223 |
} |
212 |
|
224 |
|
213 |
public void testIndividualSetAndClear() throws CoreException { |
225 |
public void testIndividualSetAndClear() throws CoreException { |
214 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
226 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
215 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
227 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
Lines 220-233
Link Here
|
220 |
disableProxy(proxyData); |
232 |
disableProxy(proxyData); |
221 |
} |
233 |
} |
222 |
} |
234 |
} |
223 |
|
235 |
|
224 |
public void testAllSetAndClear() throws CoreException { |
236 |
public void testAllSetAndClear() throws CoreException { |
225 |
delaySettingData(); |
237 |
delaySettingData(); |
226 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
238 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
227 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
239 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
228 |
setDataTest(IProxyData.SOCKS_PROXY_TYPE); |
240 |
setDataTest(IProxyData.SOCKS_PROXY_TYPE); |
229 |
performSettingData(); |
241 |
performSettingData(); |
230 |
|
242 |
|
231 |
delaySettingData(); |
243 |
delaySettingData(); |
232 |
IProxyData[] data = this.getProxyManager().getProxyData(); |
244 |
IProxyData[] data = this.getProxyManager().getProxyData(); |
233 |
for (int i = 0; i < data.length; i++) { |
245 |
for (int i = 0; i < data.length; i++) { |
Lines 250-301
Link Here
|
250 |
setProxiesEnabled(false); |
262 |
setProxiesEnabled(false); |
251 |
assertProxyDataEqual(data); |
263 |
assertProxyDataEqual(data); |
252 |
} |
264 |
} |
253 |
|
265 |
|
254 |
public void testSimpleHost() throws CoreException { |
266 |
public void testSimpleHost() throws CoreException { |
255 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
267 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
256 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
268 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
257 |
setDataTest(IProxyData.SOCKS_PROXY_TYPE); |
269 |
setDataTest(IProxyData.SOCKS_PROXY_TYPE); |
258 |
|
270 |
|
259 |
IProxyData[] allData = this.getProxyManager().getProxyDataForHost("www.randomhot.com"); |
271 |
IProxyData[] allData = this.getProxyManager().getProxyDataForHost( |
|
|
272 |
"www.randomhot.com"); |
260 |
assertEquals(3, allData.length); |
273 |
assertEquals(3, allData.length); |
261 |
|
274 |
|
262 |
IProxyData data = this.getProxyManager().getProxyDataForHost("www.randomhot.com", IProxyData.HTTP_PROXY_TYPE); |
275 |
IProxyData data = this.getProxyManager().getProxyDataForHost( |
|
|
276 |
"www.randomhot.com", IProxyData.HTTP_PROXY_TYPE); |
263 |
assertNotNull(data); |
277 |
assertNotNull(data); |
264 |
|
278 |
|
265 |
allData = this.getProxyManager().getProxyDataForHost("localhost"); |
279 |
allData = this.getProxyManager().getProxyDataForHost("localhost"); |
266 |
assertEquals(0, allData.length); |
280 |
assertEquals(0, allData.length); |
267 |
|
281 |
|
268 |
data = this.getProxyManager().getProxyDataForHost("localhost", IProxyData.HTTP_PROXY_TYPE); |
282 |
data = this.getProxyManager().getProxyDataForHost("localhost", |
|
|
283 |
IProxyData.HTTP_PROXY_TYPE); |
269 |
assertNull(data); |
284 |
assertNull(data); |
270 |
} |
285 |
} |
271 |
|
286 |
|
272 |
public void testHostPattern() throws CoreException { |
287 |
public void testHostPattern() throws CoreException { |
273 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
288 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
274 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
289 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
275 |
setDataTest(IProxyData.SOCKS_PROXY_TYPE); |
290 |
setDataTest(IProxyData.SOCKS_PROXY_TYPE); |
276 |
|
291 |
|
277 |
String[] oldHosts = this.getProxyManager().getNonProxiedHosts(); |
292 |
String[] oldHosts = this.getProxyManager().getNonProxiedHosts(); |
278 |
this.getProxyManager().setNonProxiedHosts(new String[] { "*ignore.com" }); |
293 |
this.getProxyManager().setNonProxiedHosts( |
279 |
|
294 |
new String[] { "*ignore.com" }); |
280 |
IProxyData[] allData = this.getProxyManager().getProxyDataForHost("www.randomhot.com"); |
295 |
|
|
|
296 |
IProxyData[] allData = this.getProxyManager().getProxyDataForHost( |
297 |
"www.randomhot.com"); |
281 |
assertEquals(3, allData.length); |
298 |
assertEquals(3, allData.length); |
282 |
|
299 |
|
283 |
IProxyData data = this.getProxyManager().getProxyDataForHost("www.randomhot.com", IProxyData.HTTP_PROXY_TYPE); |
300 |
IProxyData data = this.getProxyManager().getProxyDataForHost( |
|
|
301 |
"www.randomhot.com", IProxyData.HTTP_PROXY_TYPE); |
284 |
assertNotNull(data); |
302 |
assertNotNull(data); |
285 |
|
303 |
|
286 |
allData = this.getProxyManager().getProxyDataForHost("www.ignore.com"); |
304 |
allData = this.getProxyManager().getProxyDataForHost("www.ignore.com"); |
287 |
assertEquals(0, allData.length); |
305 |
assertEquals(0, allData.length); |
288 |
|
306 |
|
289 |
data = this.getProxyManager().getProxyDataForHost("www.ignore.com", IProxyData.HTTP_PROXY_TYPE); |
307 |
data = this.getProxyManager().getProxyDataForHost("www.ignore.com", |
|
|
308 |
IProxyData.HTTP_PROXY_TYPE); |
290 |
assertNull(data); |
309 |
assertNull(data); |
291 |
|
310 |
|
292 |
allData = this.getProxyManager().getProxyDataForHost("ignore.com"); |
311 |
allData = this.getProxyManager().getProxyDataForHost("ignore.com"); |
293 |
assertEquals(0, allData.length); |
312 |
assertEquals(0, allData.length); |
294 |
|
313 |
|
295 |
data = this.getProxyManager().getProxyDataForHost("ignore.com", IProxyData.HTTP_PROXY_TYPE); |
314 |
data = this.getProxyManager().getProxyDataForHost("ignore.com", |
|
|
315 |
IProxyData.HTTP_PROXY_TYPE); |
296 |
assertNull(data); |
316 |
assertNull(data); |
297 |
|
317 |
|
298 |
this.getProxyManager().setNonProxiedHosts(oldHosts); |
318 |
this.getProxyManager().setNonProxiedHosts(oldHosts); |
299 |
} |
319 |
} |
300 |
|
320 |
|
|
|
321 |
// This test case has to be manually setup and run because it depends on |
322 |
// whether the proxy is set in the native environment. It is here as |
323 |
// a convenience to test the native support. |
324 |
public void testNativeLinux() throws Exception { |
325 |
|
326 |
// Leave this test off for the automatic test runs so we don't |
327 |
// get confused by the settings that happen to be on the test machine |
328 |
if (true) |
329 |
return; |
330 |
|
331 |
AbstractProxyProvider pp = new UnixProxyProvider(); |
332 |
|
333 |
IProxyData[] pd; |
334 |
|
335 |
// Test the following cases |
336 |
// 1) No proxy set anywhere |
337 |
// 2) http_proxy environment variable (use proxyIsSet) |
338 |
// 3) gconf-edit proxy (use proxyIsSet and proxyAuthIsSet) |
339 |
// 4) KDE proxy (use proxyIsSet and proxyAuthIsSet) |
340 |
|
341 |
// Toggle this if you have the proxy set up in the native environment |
342 |
boolean proxyIsSet = true; |
343 |
|
344 |
// Toggle this if you have the proxy authentication information setup |
345 |
boolean proxyAuthIsSet = true; |
346 |
|
347 |
String proxyHost = null; |
348 |
String proxyUser = null; |
349 |
String proxyPassword = null; |
350 |
boolean proxyReqAuth = false; |
351 |
int proxyPort = 0; |
352 |
|
353 |
if (proxyIsSet) { |
354 |
proxyHost = "berlioz"; |
355 |
proxyPort = 3128; |
356 |
if (proxyAuthIsSet) { |
357 |
proxyUser = "user"; |
358 |
proxyPassword = "password"; |
359 |
proxyReqAuth = true; |
360 |
} |
361 |
} |
362 |
|
363 |
// Test HTTP |
364 |
pd = pp.select(new URI("http://bbc.com")); |
365 |
if (proxyIsSet) { |
366 |
assertEquals(1, pd.length); |
367 |
assertEquals(proxyHost, pd[0].getHost()); |
368 |
assertEquals(proxyPort, pd[0].getPort()); |
369 |
if (proxyAuthIsSet) { |
370 |
assertEquals(proxyUser, pd[0].getUserId()); |
371 |
assertEquals(proxyPassword, pd[0].getPassword()); |
372 |
assertEquals(proxyReqAuth, pd[0].isRequiresAuthentication()); |
373 |
} |
374 |
|
375 |
} else { |
376 |
assertEquals(0, pd.length); |
377 |
} |
378 |
|
379 |
// Test HTTPS |
380 |
pd = pp.select(new URI("https://bbc.com")); |
381 |
if (proxyIsSet) { |
382 |
assertEquals(1, pd.length); |
383 |
assertEquals("https_" + proxyHost, pd[0].getHost()); |
384 |
assertEquals(1 + proxyPort, pd[0].getPort()); |
385 |
} else { |
386 |
assertEquals(0, pd.length); |
387 |
} |
388 |
|
389 |
// Test SOCKS |
390 |
pd = pp.select(new URI("SOCKS://bbc.com")); |
391 |
if (proxyIsSet) { |
392 |
assertEquals(1, pd.length); |
393 |
assertEquals("socks_" + proxyHost, pd[0].getHost()); |
394 |
assertEquals(2 + proxyPort, pd[0].getPort()); |
395 |
} else { |
396 |
assertEquals(0, pd.length); |
397 |
} |
398 |
|
399 |
// Test FTP |
400 |
pd = pp.select(new URI("FTP://bbc.com")); |
401 |
if (proxyIsSet) { |
402 |
assertEquals(1, pd.length); |
403 |
assertEquals("ftp_" + proxyHost, pd[0].getHost()); |
404 |
assertEquals(3 + proxyPort, pd[0].getPort()); |
405 |
} else { |
406 |
assertEquals(0, pd.length); |
407 |
} |
408 |
|
409 |
// Assume that localhost is a non-proxy host |
410 |
pd = pp.select(new URI("http://localhost")); |
411 |
assertEquals(0, pd.length); |
412 |
} |
413 |
|
301 |
} |
414 |
} |