@Test public void testJcloudsProxyHostsPreferredOverJvmProxy() throws URISyntaxException { ProxyConfig test = new MyProxyConfig(true, true, Proxy.Type.HTTP, hostAndPort, noCreds); ProxyConfig jclouds = new MyProxyConfig(false, false, Proxy.Type.HTTP, hostAndPort, noCreds); ProxyConfig jvm = new MyProxyConfig(false, true, Proxy.Type.HTTP, noHostAndPort, noCreds); URI uri = new URI("http://example.com/file"); assertEquals(new ProxyForURI(test).apply(uri), new ProxyForURI(jclouds).apply(uri)); assertNotEquals(new ProxyForURI(test).apply(uri), new ProxyForURI(jvm).apply(uri)); }
return getDefaultProxy(endpoint); return getDefaultProxy(endpoint);
return getDefaultProxy(endpoint); return getDefaultProxy(endpoint);
@Test public void testJvmProxyAlwaysPreferredOverSystem() throws URISyntaxException { ProxyConfig test = new MyProxyConfig(true, true, Proxy.Type.HTTP, noHostAndPort, noCreds); ProxyConfig jvm = new MyProxyConfig(false, true, Proxy.Type.HTTP, noHostAndPort, noCreds); URI uri = new URI("http://example.com/file"); assertEquals(new ProxyForURI(test).apply(uri), new ProxyForURI(jvm).apply(uri)); }
return getDefaultProxy(endpoint); return getDefaultProxy(endpoint);
@Test public void testSocketDirect() throws URISyntaxException { ProxyConfig config = new MyProxyConfig(false, Proxy.Type.DIRECT, noHostAndPort, noCreds); URI uri = new URI("socket://ssh.example.com:22"); assertEquals(new ProxyForURI(config).apply(uri), Proxy.NO_PROXY); }
@Test public void testFTPDirect() throws URISyntaxException { ProxyConfig config = new MyProxyConfig(false, Proxy.Type.DIRECT, noHostAndPort, noCreds); URI uri = new URI("ftp://ftp.example.com/file"); assertEquals(new ProxyForURI(config).apply(uri), Proxy.NO_PROXY); }
@Test public void testHTTPDirect() throws URISyntaxException { ProxyConfig config = new MyProxyConfig(false, Proxy.Type.DIRECT, noHostAndPort, noCreds); URI uri = new URI("http://example.com/file"); assertEquals(new ProxyForURI(config).apply(uri), Proxy.NO_PROXY); }
@Test public void testHTTPSDirect() throws URISyntaxException { ProxyConfig config = new MyProxyConfig(false, Proxy.Type.DIRECT, noHostAndPort, noCreds); URI uri = new URI("https://example.com/file"); assertEquals(new ProxyForURI(config).apply(uri), Proxy.NO_PROXY); }
@Test public void testHTTPThroughSystemProxy() throws URISyntaxException { ProxyConfig config = new MyProxyConfig(true, Proxy.Type.DIRECT, noHostAndPort, noCreds); URI uri = new URI("http://example.com/file"); // could return a proxy, could return NO_PROXY, depends on the tester's // environment assertNotNull(new ProxyForURI(config).apply(uri)); }
@Test public void testUseProxyForSocketsSettingShouldntAffectHTTP() throws Exception { ProxyConfig config = new MyProxyConfig(false, Proxy.Type.HTTP, hostAndPort, creds); ProxyForURI proxy = new ProxyForURI(config); Field useProxyForSockets = proxy.getClass().getDeclaredField("useProxyForSockets"); useProxyForSockets.setAccessible(true); useProxyForSockets.setBoolean(proxy, false); URI uri = new URI("http://example.com/file"); assertEquals(proxy.apply(uri), new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.example.com", 8080))); }
@Test public void testHTTPThroughHTTPProxy() throws URISyntaxException { ProxyConfig config = new MyProxyConfig(false, Proxy.Type.HTTP, hostAndPort, creds); URI uri = new URI("http://example.com/file"); assertEquals(new ProxyForURI(config).apply(uri), new Proxy(Proxy.Type.HTTP, new InetSocketAddress( "proxy.example.com", 8080))); }
@Test public void testThroughSystemProxy() throws URISyntaxException { ProxyConfig config = new MyProxyConfig(true, false, Proxy.Type.HTTP, noHostAndPort, noCreds); URI uri = new URI("http://example.com/file"); // could return a proxy, could return NO_PROXY, depends on the tester's environment assertNotNull(new ProxyForURI(config).apply(uri)); }
@Test public void testHTTPDirect() throws URISyntaxException { ProxyConfig config = new MyProxyConfig(false, false, Proxy.Type.DIRECT, noHostAndPort, noCreds); URI uri = new URI("http://example.com/file"); assertEquals(new ProxyForURI(config).apply(uri), Proxy.NO_PROXY); }
@Test public void testThroughJvmProxy() throws URISyntaxException { ProxyConfig config = new MyProxyConfig(false, true, Proxy.Type.HTTP, noHostAndPort, noCreds); URI uri = new URI("http://example.com/file"); // could return a proxy, could return NO_PROXY, depends on the tester's environment assertNotNull(new ProxyForURI(config).apply(uri)); }
@Test public void testSocketDirect() throws URISyntaxException { ProxyConfig config = new MyProxyConfig(false, false, Proxy.Type.DIRECT, noHostAndPort, noCreds); URI uri = new URI("socket://ssh.example.com:22"); assertEquals(new ProxyForURI(config).apply(uri), Proxy.NO_PROXY); }
@Test public void testDontUseProxyForSockets() throws Exception { ProxyConfig config = new MyProxyConfig(false, Proxy.Type.HTTP, hostAndPort, creds); ProxyForURI proxy = new ProxyForURI(config); Field useProxyForSockets = proxy.getClass().getDeclaredField("useProxyForSockets"); useProxyForSockets.setAccessible(true); useProxyForSockets.setBoolean(proxy, false); URI uri = new URI("socket://ssh.example.com:22"); assertEquals(proxy.apply(uri), Proxy.NO_PROXY); }
@Test public void testUseProxyForSockets() throws Exception { ProxyConfig config = new MyProxyConfig(false, Proxy.Type.HTTP, hostAndPort, creds); ProxyForURI proxy = new ProxyForURI(config); URI uri = new URI("socket://ssh.example.com:22"); assertEquals(proxy.apply(uri), new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.example.com", 8080))); }
@Test public void testHTTPSDirect() throws URISyntaxException { ProxyConfig config = new MyProxyConfig(false, false, Proxy.Type.DIRECT, noHostAndPort, noCreds); URI uri = new URI("https://example.com/file"); assertEquals(new ProxyForURI(config).apply(uri), Proxy.NO_PROXY); }
@Test public void testFTPDirect() throws URISyntaxException { ProxyConfig config = new MyProxyConfig(false, false, Proxy.Type.DIRECT, noHostAndPort, noCreds); URI uri = new URI("ftp://ftp.example.com/file"); assertEquals(new ProxyForURI(config).apply(uri), Proxy.NO_PROXY); }