Search in sources :

Example 1 with Proxy

use of ch.cyberduck.core.proxy.Proxy in project cyberduck by iterate-ch.

the class FTPSessionTest method testConnectionTlsUpgrade.

@Test
@Category(IntegrationTest.class)
public void testConnectionTlsUpgrade() throws Exception {
    final Host host = new Host(new FTPProtocol(), "test.cyberduck.ch", new Credentials(System.getProperties().getProperty("ftp.user"), System.getProperties().getProperty("ftp.password")));
    final FTPSession session = new FTPSession(host) {

        @Override
        public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
            assertEquals(Session.State.open, this.getState());
            super.login(proxy, prompt, cancel);
            assertEquals(new FTPTLSProtocol(), host.getProtocol());
        }
    };
    assertNotNull(session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback()));
    assertTrue(session.isConnected());
    assertNotNull(session.getClient());
    assertEquals(new FTPProtocol(), host.getProtocol());
    final AtomicBoolean warned = new AtomicBoolean();
    ConnectionService l = new LoginConnectionService(new DisabledLoginCallback() {

        @Override
        public void warn(final Host bookmark, final String title, final String message, final String continueButton, final String disconnectButton, final String preference) throws LoginCanceledException {
            warned.set(true);
            // Cancel to switch
            throw new LoginCanceledException();
        }
    }, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    l.connect(session, new DisabledCancelCallback());
    assertEquals(new FTPTLSProtocol(), host.getProtocol());
    assertTrue(warned.get());
}
Also used : LoginCanceledException(ch.cyberduck.core.exception.LoginCanceledException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Proxy(ch.cyberduck.core.proxy.Proxy) CancelCallback(ch.cyberduck.core.threading.CancelCallback) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 2 with Proxy

use of ch.cyberduck.core.proxy.Proxy in project cyberduck by iterate-ch.

the class DAVSessionTest method testConnectProxyHttps.

@Test
@Ignore
public void testConnectProxyHttps() throws Throwable {
    final Host host = new Host(new DAVSSLProtocol(), "svn.cyberduck.io");
    final AtomicBoolean verified = new AtomicBoolean();
    final DAVSession session = new DAVSession(host, new DefaultX509TrustManager() {

        @Override
        public void verify(final String hostname, final X509Certificate[] certs, final String cipher) throws CertificateException {
            assertNotNull(hostname);
            verified.set(true);
            super.verify(hostname, certs, cipher);
        }
    }, new KeychainX509KeyManager(new DisabledCertificateIdentityCallback(), host, new DisabledCertificateStore())) {
    };
    final LoginConnectionService c = new LoginConnectionService(new DisabledLoginCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String username, final String title, final String reason, final LoginOptions options) {
            return new Credentials("test", "test");
        }
    }, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener(), new ProxyFinder() {

        @Override
        public Proxy find(final String target) {
            return new Proxy(Proxy.Type.HTTPS, "localhost", 8080);
        }
    });
    try {
        Executors.newSingleThreadExecutor().submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                c.connect(session, new DisabledCancelCallback());
                return null;
            }
        }).get();
    } catch (ExecutionException e) {
        throw e.getCause();
    } finally {
        assertTrue(verified.get());
        session.close();
    }
}
Also used : KeychainX509KeyManager(ch.cyberduck.core.ssl.KeychainX509KeyManager) CertificateException(java.security.cert.CertificateException) Callable(java.util.concurrent.Callable) Proxy(ch.cyberduck.core.proxy.Proxy) ExecutionException(java.util.concurrent.ExecutionException) X509Certificate(java.security.cert.X509Certificate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProxyFinder(ch.cyberduck.core.proxy.ProxyFinder) DefaultX509TrustManager(ch.cyberduck.core.ssl.DefaultX509TrustManager) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 3 with Proxy

use of ch.cyberduck.core.proxy.Proxy in project cyberduck by iterate-ch.

the class DAVSessionTest method testConnectProxyInvalidCredentials.

@Ignore
@Test(expected = ProxyLoginFailureException.class)
public void testConnectProxyInvalidCredentials() throws Exception {
    final Host host = new Host(new DAVSSLProtocol(), "svn.cyberduck.io");
    final DAVSession session = new DAVSession(host, new DefaultX509TrustManager(), new KeychainX509KeyManager(new DisabledCertificateIdentityCallback(), host, new DisabledCertificateStore())) {
    };
    final LoginConnectionService c = new LoginConnectionService(new DisabledLoginCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String username, final String title, final String reason, final LoginOptions options) {
            return new Credentials("test", "n");
        }
    }, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener(), new ProxyFinder() {

        @Override
        public Proxy find(final String target) {
            return new Proxy(Proxy.Type.HTTP, "localhost", 3128);
        }
    });
    c.connect(session, new DisabledCancelCallback());
    session.close();
}
Also used : KeychainX509KeyManager(ch.cyberduck.core.ssl.KeychainX509KeyManager) ProxyFinder(ch.cyberduck.core.proxy.ProxyFinder) Proxy(ch.cyberduck.core.proxy.Proxy) DefaultX509TrustManager(ch.cyberduck.core.ssl.DefaultX509TrustManager) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 4 with Proxy

use of ch.cyberduck.core.proxy.Proxy in project cyberduck by iterate-ch.

the class ProxySocketFactoryTest method testCreateSocketWithProxy.

@Test(expected = SocketException.class)
public void testCreateSocketWithProxy() throws Exception {
    final Socket socket = new ProxySocketFactory(new Host(new TestProtocol(), "localhost"), new DefaultSocketConfigurator(), new ProxyFinder() {

        @Override
        public Proxy find(final String target) {
            return new Proxy(Proxy.Type.SOCKS, "localhost", 7000);
        }
    }).createSocket();
    assertNotNull(socket);
    socket.connect(new InetSocketAddress("test.cyberduck.ch", 21));
}
Also used : ProxySocketFactory(ch.cyberduck.core.proxy.ProxySocketFactory) ProxyFinder(ch.cyberduck.core.proxy.ProxyFinder) Proxy(ch.cyberduck.core.proxy.Proxy) InetSocketAddress(java.net.InetSocketAddress) Socket(java.net.Socket) DefaultSocketConfigurator(ch.cyberduck.core.socket.DefaultSocketConfigurator) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 5 with Proxy

use of ch.cyberduck.core.proxy.Proxy in project cyberduck by iterate-ch.

the class LoginConnectionServiceTest method testPasswordChange.

@Test(expected = LoginCanceledException.class)
public void testPasswordChange() throws Exception {
    final AtomicBoolean connected = new AtomicBoolean();
    final AtomicBoolean keychain = new AtomicBoolean();
    final AtomicBoolean prompt = new AtomicBoolean();
    final LoginConnectionService s = new LoginConnectionService(new DisabledLoginCallback() {

        @Override
        public void warn(final Host bookmark, final String title, final String message, final String continueButton, final String disconnectButton, final String preference) {
        // 
        }

        @Override
        public Credentials prompt(final Host bookmark, final String username, final String title, final String reason, final LoginOptions options) {
            prompt.set(true);
            // New password entered
            return new Credentials(username, "b");
        }
    }, new DisabledHostKeyCallback(), new DisabledPasswordStore() {

        @Override
        public String findLoginPassword(final Host bookmark) {
            keychain.set(true);
            // Old password stored
            return "a";
        }
    }, new DisabledProgressListener());
    final Session session = new NullSession(new Host(new TestProtocol(), "localhost", new Credentials("user", ""))) {

        @Override
        public Void connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt, final CancelCallback cancel) {
            connected.set(true);
            return null;
        }

        @Override
        public boolean isConnected() {
            return connected.get();
        }

        @Override
        public void login(final Proxy proxy, final LoginCallback l, final CancelCallback cancel) throws BackgroundException {
            if (prompt.get()) {
                assertEquals("b", host.getCredentials().getPassword());
                throw new LoginCanceledException();
            }
            if (keychain.get()) {
                assertFalse(prompt.get());
                assertEquals("a", host.getCredentials().getPassword());
                throw new LoginFailureException("f");
            }
        }
    };
    try {
        s.check(session, new DisabledCancelCallback());
    } finally {
        assertTrue(keychain.get());
        assertTrue(prompt.get());
    }
}
Also used : LoginCanceledException(ch.cyberduck.core.exception.LoginCanceledException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Proxy(ch.cyberduck.core.proxy.Proxy) LoginFailureException(ch.cyberduck.core.exception.LoginFailureException) CancelCallback(ch.cyberduck.core.threading.CancelCallback) Test(org.junit.Test)

Aggregations

Proxy (ch.cyberduck.core.proxy.Proxy)13 Test (org.junit.Test)11 IntegrationTest (ch.cyberduck.test.IntegrationTest)9 ProxyFinder (ch.cyberduck.core.proxy.ProxyFinder)8 DefaultX509TrustManager (ch.cyberduck.core.ssl.DefaultX509TrustManager)5 KeychainX509KeyManager (ch.cyberduck.core.ssl.KeychainX509KeyManager)5 Ignore (org.junit.Ignore)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 LoginCanceledException (ch.cyberduck.core.exception.LoginCanceledException)2 LoginFailureException (ch.cyberduck.core.exception.LoginFailureException)2 CancelCallback (ch.cyberduck.core.threading.CancelCallback)2 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)2 InetSocketAddress (java.net.InetSocketAddress)2 CertificateException (java.security.cert.CertificateException)2 X509Certificate (java.security.cert.X509Certificate)2 Callable (java.util.concurrent.Callable)2 ExecutionException (java.util.concurrent.ExecutionException)2 PreferencesUseragentProvider (ch.cyberduck.core.PreferencesUseragentProvider)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 ConnectionRefusedException (ch.cyberduck.core.exception.ConnectionRefusedException)1