Cyberduck Mountain Duck CLI

Changeset 17648


Ignore:
Timestamp:
May 25, 2015 12:28:23 PM (5 years ago)
Author:
dkocher
Message:

Add tests.

Location:
trunk/test/ch/cyberduck/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/ch/cyberduck/core/ProxySocketFactoryTest.java

    r17595 r17648  
    131131    // We have no IPv6 in the test environment
    132132    @Test(expected = NoRouteToHostException.class)
    133     public void testCreateSocketIPv6Only() throws Exception {
     133    public void testCreateSocketIPv6OnlyWithInetAddress() throws Exception {
    134134        for(String address : Arrays.asList("ftp6.netbsd.org")) {
    135135            final Socket socket = new ProxySocketFactory(ProtocolFactory.FTP, new TrustManagerHostnameCallback() {
     
    147147            }).withBlacklistedNetworkInterfaces(Arrays.asList("awdl0")).createSocket(address, 21);
    148148            assertNotNull(socket);
     149            assertTrue(socket.getInetAddress() instanceof Inet6Address);
     150        }
     151    }
     152
     153    // We have no IPv6 in the test environment
     154    @Test(expected = NoRouteToHostException.class)
     155    public void testCreateSocketIPv6OnlyUnknownDestination() throws Exception {
     156        for(String address : Arrays.asList("ftp6.netbsd.org")) {
     157            final Socket socket = new ProxySocketFactory(ProtocolFactory.FTP, new TrustManagerHostnameCallback() {
     158                @Override
     159                public String getTarget() {
     160                    return "ftp6.netbsd.org";
     161                }
     162            }, new SocketConfigurator() {
     163                @Override
     164                public void configure(final Socket socket) throws IOException {
     165                    // Not yet connected
     166                    assertNull(socket.getInetAddress());
     167                }
     168            }).withBlacklistedNetworkInterfaces(Arrays.asList("awdl0")).createSocket();
     169            assertNotNull(socket);
     170            assertNull(socket.getInetAddress());
     171            socket.connect(new InetSocketAddress(address, 21), 0);
     172            assertTrue(socket.getInetAddress() instanceof Inet6Address);
     173            assertEquals(((Inet6Address) socket.getInetAddress()).getScopeId(),
     174                    ((Inet6Address) InetAddress.getByName("::1%en0")).getScopeId());
    149175            assertTrue(socket.getInetAddress() instanceof Inet6Address);
    150176        }
  • trunk/test/ch/cyberduck/core/socket/NetworkInterfaceAwareSocketFactoryTest.java

    r17647 r17648  
    2424import java.net.Inet6Address;
    2525import java.net.InetAddress;
     26import java.net.InetSocketAddress;
    2627import java.net.NetworkInterface;
    2728import java.net.Socket;
     
    5253                NetworkInterface.getByName("en0").getIndex());
    5354    }
     55
     56    @Test
     57    public void testFindEn0DefaultWithUnknownHost() throws Exception {
     58        final Socket socket = new NetworkInterfaceAwareSocketFactory(Arrays.<String>asList("awdl0")).createSocket();
     59        assertNotNull(socket);
     60        assertNull(socket.getInetAddress());
     61        socket.connect(new InetSocketAddress("ftp6.netbsd.org", 22), 0);
     62        assertTrue(socket.getInetAddress() instanceof Inet6Address);
     63        assertEquals(((Inet6Address) socket.getInetAddress()).getScopeId(),
     64                NetworkInterface.getByName("en0").getIndex());
     65    }
    5466}
Note: See TracChangeset for help on using the changeset viewer.
swiss made software