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());
}
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();
}
}
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();
}
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));
}
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());
}
}
Aggregations