1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
package com.btr.proxy.selector.whitelist;
import static org.junit.Assert.*;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import org.junit.Test;
import com.btr.proxy.TestUtil;
import com.btr.proxy.selector.fixed.FixedProxySelector;
/*****************************************************************************
* Some unit tests for the white list selector.
*
* @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
****************************************************************************/
public class NoProxyTest {
/*************************************************************************
* Test method
************************************************************************/
@Test
public void testWhiteList() {
ProxySelector delegate = new FixedProxySelector(TestUtil.HTTP_TEST_PROXY);
ProxyBypassListSelector ps = new ProxyBypassListSelector("no_prox.*", delegate);
assertEquals(delegate.select(TestUtil.HTTP_TEST_URI).get(0), ps.select(TestUtil.HTTP_TEST_URI).get(0));
}
/*************************************************************************
* Test method
************************************************************************/
@Test
public void testWhiteList2() {
ProxySelector delegate = new FixedProxySelector(TestUtil.HTTP_TEST_PROXY);
ProxyBypassListSelector ps = new ProxyBypassListSelector("*.unit-test.invalid", delegate);
List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
assertEquals(Proxy.NO_PROXY, result.get(0));
}
/*************************************************************************
* Test method
* @throws URISyntaxException on invalid URL syntax.
************************************************************************/
@Test
public void testWhiteList3() throws URISyntaxException {
ProxySelector delegate = new FixedProxySelector(TestUtil.HTTP_TEST_PROXY);
ProxyBypassListSelector ps = new ProxyBypassListSelector("*.unit-test.invalid, localhost, 127.0.0.1", delegate);
List<Proxy> result = ps.select(new URI("http://localhost:65/getDocument"));
assertEquals(Proxy.NO_PROXY, result.get(0));
result = ps.select(new URI("http://127.0.0.1:65/getDocument"));
assertEquals(Proxy.NO_PROXY, result.get(0));
}
/*************************************************************************
* Test method
************************************************************************/
@Test
public void testWhiteList4() {
ProxySelector delegate = new FixedProxySelector(TestUtil.HTTP_TEST_PROXY);
ProxyBypassListSelector ps = new ProxyBypassListSelector("*.unit-test.invalid, ", delegate);
List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
assertEquals(Proxy.NO_PROXY, result.get(0));
}
/*************************************************************************
* Test method
* @throws URISyntaxException on invalid URL syntax.
************************************************************************/
@Test
public void testWhiteList5() throws URISyntaxException {
ProxySelector delegate = new FixedProxySelector(TestUtil.HTTP_TEST_PROXY);
ProxyBypassListSelector ps = new ProxyBypassListSelector("*.unit-test.invalid localhost 127.0.0.1", delegate);
List<Proxy> result = ps.select(new URI("http://localhost:65/getDocument"));
assertEquals(Proxy.NO_PROXY, result.get(0));
result = ps.select(new URI("http://127.0.0.1:65/getDocument"));
assertEquals(Proxy.NO_PROXY, result.get(0));
}
/*************************************************************************
* Test method
* @throws URISyntaxException on invalid URL syntax.
************************************************************************/
@Test
public void testIpRange() throws URISyntaxException {
ProxySelector delegate = new FixedProxySelector(TestUtil.HTTP_TEST_PROXY);
ProxyBypassListSelector ps = new ProxyBypassListSelector("192.168.0.0/24", delegate);
List<Proxy> result = ps.select(new URI("http://192.168.0.100:81/test.data"));
assertEquals(Proxy.NO_PROXY, result.get(0));
result = ps.select(new URI("http://192.168.1.100:81/test.data"));
assertEquals(delegate.select(TestUtil.HTTP_TEST_URI).get(0), result.get(0));
}
}
|