Search in sources :

Example 1 with Proxies

use of org.eclipse.ceylon.common.config.Proxies 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();
}
Also used : Proxy(org.eclipse.ceylon.common.config.Proxies.Proxy) Proxies(org.eclipse.ceylon.common.config.Proxies) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) Authentication(org.eclipse.ceylon.common.config.Authentication) PasswordAuthentication(java.net.PasswordAuthentication) InetSocketAddress(java.net.InetSocketAddress) PasswordAuthentication(java.net.PasswordAuthentication) Test(org.junit.Test)

Example 2 with Proxies

use of org.eclipse.ceylon.common.config.Proxies 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();
}
Also used : Proxy(org.eclipse.ceylon.common.config.Proxies.Proxy) Proxies(org.eclipse.ceylon.common.config.Proxies) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) Authentication(org.eclipse.ceylon.common.config.Authentication) PasswordAuthentication(java.net.PasswordAuthentication) InetSocketAddress(java.net.InetSocketAddress) PasswordAuthentication(java.net.PasswordAuthentication) Test(org.junit.Test)

Example 3 with Proxies

use of org.eclipse.ceylon.common.config.Proxies 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();
}
Also used : Proxy(org.eclipse.ceylon.common.config.Proxies.Proxy) Proxies(org.eclipse.ceylon.common.config.Proxies) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) Authentication(org.eclipse.ceylon.common.config.Authentication) PasswordAuthentication(java.net.PasswordAuthentication) InetSocketAddress(java.net.InetSocketAddress) File(java.io.File) PasswordAuthentication(java.net.PasswordAuthentication) Test(org.junit.Test)

Example 4 with Proxies

use of org.eclipse.ceylon.common.config.Proxies 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();
}
Also used : Proxy(org.eclipse.ceylon.common.config.Proxies.Proxy) Proxies(org.eclipse.ceylon.common.config.Proxies) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) Authentication(org.eclipse.ceylon.common.config.Authentication) PasswordAuthentication(java.net.PasswordAuthentication) File(java.io.File) PasswordAuthentication(java.net.PasswordAuthentication) Test(org.junit.Test)

Example 5 with Proxies

use of org.eclipse.ceylon.common.config.Proxies 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();
}
Also used : Proxy(org.eclipse.ceylon.common.config.Proxies.Proxy) Proxies(org.eclipse.ceylon.common.config.Proxies) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) Authentication(org.eclipse.ceylon.common.config.Authentication) PasswordAuthentication(java.net.PasswordAuthentication) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Aggregations

PasswordAuthentication (java.net.PasswordAuthentication)6 Authentication (org.eclipse.ceylon.common.config.Authentication)6 CeylonConfig (org.eclipse.ceylon.common.config.CeylonConfig)6 Proxies (org.eclipse.ceylon.common.config.Proxies)6 Proxy (org.eclipse.ceylon.common.config.Proxies.Proxy)6 Test (org.junit.Test)6 InetSocketAddress (java.net.InetSocketAddress)5 File (java.io.File)2