use of org.eclipse.ceylon.common.config.Proxies.Proxy in project ceylon by eclipse.
the class ProxiesTest method testProxyWithUser.
@Test
public void testProxyWithUser() throws Exception {
CeylonConfig testConfig = loadTestConfig("proxy+user.config");
Proxies proxies = getProxies(testConfig);
Proxy proxy = proxies.getProxy();
Assert.assertEquals("myproxy", proxy.getHost());
Assert.assertEquals(1234, proxy.getPort());
Authentication auth = Authentication.fromConfig(testConfig);
auth.installProxy();
Assert.assertNotNull(auth.getProxyAuthenticator());
this.mockPrompt.prompts.put("Password for HTTP proxy myproxy:1234: ", "wibble");
PasswordAuthentication up = Authenticator.requestPasswordAuthentication(null, 80, "ceylon-lang.org", "Hello, world", "fnar");
Assert.assertEquals("me", up.getUserName());
Assert.assertEquals("wibble", new String(up.getPassword()));
InetSocketAddress address = (InetSocketAddress) auth.getProxy().address();
Assert.assertEquals("myproxy", address.getHostName());
Assert.assertEquals(1234, address.getPort());
List<java.net.Proxy> selectedProxies = auth.getProxySelector().select(URI.create("anything"));
Assert.assertEquals(1, selectedProxies.size());
Assert.assertEquals(java.net.Proxy.Type.HTTP, selectedProxies.get(0).type());
Assert.assertEquals("myproxy", ((InetSocketAddress) selectedProxies.get(0).address()).getHostName());
Assert.assertEquals(1234, ((InetSocketAddress) selectedProxies.get(0).address()).getPort());
mockPrompt.assertSeenOnlyGivenPrompts();
}
use of org.eclipse.ceylon.common.config.Proxies.Proxy in project ceylon by eclipse.
the class ProxiesTest method testProxyWithPassword.
@Test
public void testProxyWithPassword() throws Exception {
CeylonConfig testConfig = loadTestConfig("proxy+password.config");
Proxies proxies = getProxies(testConfig);
Proxy proxy = proxies.getProxy();
Assert.assertEquals("myproxy", proxy.getHost());
Assert.assertEquals(1234, proxy.getPort());
Authentication auth = Authentication.fromConfig(testConfig);
auth.installProxy();
Assert.assertNotNull(auth.getProxyAuthenticator());
PasswordAuthentication up = Authenticator.requestPasswordAuthentication(null, 80, "ceylon-lang.org", "Hello, world", "fnar");
Assert.assertEquals("me", up.getUserName());
Assert.assertEquals("mypassword", new String(up.getPassword()));
InetSocketAddress address = (InetSocketAddress) auth.getProxy().address();
Assert.assertEquals("myproxy", address.getHostName());
Assert.assertEquals(1234, address.getPort());
List<java.net.Proxy> selectedProxies = auth.getProxySelector().select(URI.create("anything"));
Assert.assertEquals(1, selectedProxies.size());
Assert.assertEquals(java.net.Proxy.Type.HTTP, selectedProxies.get(0).type());
Assert.assertEquals("myproxy", ((InetSocketAddress) selectedProxies.get(0).address()).getHostName());
Assert.assertEquals(1234, ((InetSocketAddress) selectedProxies.get(0).address()).getPort());
// Check there were no prompts
mockPrompt.assertSeenOnlyGivenPrompts();
}
use of org.eclipse.ceylon.common.config.Proxies.Proxy in project ceylon by eclipse.
the class ProxiesTest method testProxyWithAlias.
@Test
public void testProxyWithAlias() throws Exception {
CeylonConfig testConfig = loadTestConfig("proxy+alias.config");
createStore(testConfig, new File("keystore"), null).setPassword("proxy-password", "ffff".toCharArray(), "mypassword".toCharArray());
Proxies proxies = getProxies(testConfig);
Proxy proxy = proxies.getProxy();
Assert.assertEquals("myproxy", proxy.getHost());
Assert.assertEquals(1234, proxy.getPort());
Authentication auth = Authentication.fromConfig(testConfig);
Assert.assertNotNull(auth.getProxyAuthenticator());
auth.installProxy();
mockPrompt.prompts.put("Password for default keystore (keystore):", "ffff");
PasswordAuthentication up = Authenticator.requestPasswordAuthentication(null, 80, "ceylon-lang.org", "Hello, world", "fnar");
Assert.assertEquals("me", up.getUserName());
Assert.assertEquals("mypassword", new String(up.getPassword()));
InetSocketAddress address = (InetSocketAddress) auth.getProxy().address();
Assert.assertEquals("myproxy", address.getHostName());
Assert.assertEquals(1234, address.getPort());
List<java.net.Proxy> selectedProxies = auth.getProxySelector().select(URI.create("anything"));
Assert.assertEquals(1, selectedProxies.size());
Assert.assertEquals(java.net.Proxy.Type.HTTP, selectedProxies.get(0).type());
Assert.assertEquals("myproxy", ((InetSocketAddress) selectedProxies.get(0).address()).getHostName());
Assert.assertEquals(1234, ((InetSocketAddress) selectedProxies.get(0).address()).getPort());
// Check there were no prompts
mockPrompt.assertSeenOnlyGivenPrompts();
}
use of org.eclipse.ceylon.common.config.Proxies.Proxy in project ceylon by eclipse.
the class ProxiesTest method testProxyNone.
@Test
public void testProxyNone() throws Exception {
CeylonConfig testConfig = loadTestConfig("proxy-none.config");
createStore(testConfig, new File("keystore"), null).setPassword("proxy-password", "ffff".toCharArray(), "mypassword".toCharArray());
Proxies proxies = getProxies(testConfig);
Proxy proxy = proxies.getProxy();
Assert.assertNull(proxy.getHost());
Assert.assertEquals(8080, proxy.getPort());
Authentication auth = Authentication.fromConfig(testConfig);
Assert.assertNull(auth.getProxyAuthenticator());
auth.installProxy();
Assert.assertNull(auth.getProxyAuthenticator());
PasswordAuthentication up = Authenticator.requestPasswordAuthentication(null, 80, "ceylon-lang.org", "Hello, world", "fnar");
Assert.assertNull(up);
Assert.assertNull(auth.getProxy());
Assert.assertNull(auth.getProxySelector());
// Check there were no prompts
mockPrompt.assertSeenOnlyGivenPrompts();
}
use of org.eclipse.ceylon.common.config.Proxies.Proxy in project ceylon by eclipse.
the class ProxiesTest method testProxy.
@Test
public void testProxy() throws Exception {
CeylonConfig testConfig = loadTestConfig("proxy.config");
Proxies proxies = getProxies(testConfig);
Proxy proxy = proxies.getProxy();
Assert.assertEquals("myproxy", proxy.getHost());
Assert.assertEquals(1234, proxy.getPort());
Authentication auth = Authentication.fromConfig(testConfig);
Assert.assertNull(auth.getProxyAuthenticator());
auth.installProxy();
Assert.assertEquals(null, auth.getProxyAuthenticator());
InetSocketAddress address = (InetSocketAddress) auth.getProxy().address();
Assert.assertEquals("myproxy", address.getHostName());
Assert.assertEquals(1234, address.getPort());
List<java.net.Proxy> selectedProxies = auth.getProxySelector().select(URI.create("anything"));
Assert.assertEquals(1, selectedProxies.size());
Assert.assertEquals(java.net.Proxy.Type.HTTP, selectedProxies.get(0).type());
mockPrompt.assertSeenOnlyGivenPrompts();
}
Aggregations