Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
Former-commit-id: 5fa05b063b7a37c7c14c93ee2d35895b156d1d33
  • Loading branch information
dkocher committed May 6, 2015
1 parent 12fa735 commit 610dcd9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion test/ch/cyberduck/core/ProxySocketFactoryTest.java
Expand Up @@ -25,11 +25,14 @@

import org.junit.Test;

import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class ProxySocketFactoryTest extends AbstractTestCase {

Expand Down Expand Up @@ -65,4 +68,30 @@ public Proxy find(final Host target) {
assertNotNull(socket);
socket.connect(new InetSocketAddress("test.cyberduck.ch", 21));
}
}

@Test
public void testCreateSocketIPv6Localhost() throws Exception {
System.setProperty("java.net.preferIPv6Addresses", String.valueOf(true));
final Socket socket = new ProxySocketFactory(ProtocolFactory.SFTP, new TrustManagerHostnameCallback() {
@Override
public String getTarget() {
return "localhost";
}
}).createSocket("::1", 22);
assertNotNull(socket);
assertTrue(socket.getInetAddress() instanceof Inet6Address);
}

@Test
public void testCreateSocketDualStackGoogle() throws Exception {
final Socket socket = new ProxySocketFactory(ProtocolFactory.WEBDAV, new TrustManagerHostnameCallback() {
@Override
public String getTarget() {
return "localhost";
}
}).createSocket("ipv6test.google.com", 80);
assertNotNull(socket);
// We have set `java.net.preferIPv6Addresses` to `false` by default
assertTrue(socket.getInetAddress() instanceof Inet4Address);
}
}

0 comments on commit 610dcd9

Please sign in to comment.