test/jdk/java/net/Socks/SocksIPv6Test.java
author dfuchs
Fri, 26 Apr 2019 16:25:43 +0100
changeset 54634 59c01214e478
parent 53478 0716631b907f
child 57832 da4cf75505a7
permissions -rw-r--r--
8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently Summary: tests are updated to use the loopback address instead of the wildcard to avoid traffic being routed to a different server than what was intended by the test. Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22276
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
     1
/*
54634
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
     2
 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
22276
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
     4
 *
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
     8
 *
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    13
 * accompanied this code).
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    14
 *
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    18
 *
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    21
 * questions.
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    22
 */
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    23
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    24
/* @test
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    25
 * @bug 7100957
38883
d5de564f8089 8151913: Fix module dependencies in java/net tests
mli
parents: 22276
diff changeset
    26
 * @modules jdk.httpserver
22276
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    27
 * @summary Java doesn't correctly handle the SOCKS protocol when used over IPv6.
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    28
 * @run testng SocksIPv6Test
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    29
 */
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    30
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    31
import java.io.BufferedReader;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    32
import java.io.IOException;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    33
import java.io.InputStreamReader;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    34
import java.io.OutputStreamWriter;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    35
import java.net.Authenticator;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    36
import java.net.InetSocketAddress;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    37
import java.net.URL;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    38
import java.net.Proxy;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    39
import java.lang.Override;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    40
import java.net.InetAddress;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    41
import java.net.Inet6Address;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    42
import java.net.ServerSocket;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    43
import java.net.SocketException;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    44
import java.net.NetworkInterface;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    45
import java.util.Collections;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    46
import java.util.List;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    47
import com.sun.net.httpserver.*;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    48
import java.io.BufferedWriter;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    49
import org.testng.annotations.AfterClass;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    50
import org.testng.annotations.BeforeClass;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    51
import org.testng.annotations.Test;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    52
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    53
import static org.testng.Assert.*;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    54
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    55
public class SocksIPv6Test {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    56
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    57
    private HttpServer server;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    58
    private SocksServer socks;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    59
    private String response = "Hello.";
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    60
    private static boolean shouldRun = false;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    61
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    62
    @BeforeClass
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    63
    public void setUp() throws Exception {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    64
        shouldRun = ensureInet6AddressFamily() && ensureIPv6OnLoopback();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    65
54634
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
    66
        server = HttpServer.create(new InetSocketAddress("::1", 0), 0);
22276
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    67
        server.createContext("/", ex -> {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    68
            ex.sendResponseHeaders(200, response.length());
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    69
            try (BufferedWriter writer = new BufferedWriter(
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    70
                    new OutputStreamWriter(ex.getResponseBody(), "UTF-8"))) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    71
                writer.write(response);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    72
            }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    73
            ex.close();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    74
        });
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    75
        server.start();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    76
54634
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
    77
        socks = new SocksServer(InetAddress.getByName("::1"), 0, false);
22276
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    78
        socks.addUser("user", "pass");
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    79
        socks.start();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    80
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    81
        Authenticator.setDefault(new Authenticator() {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    82
            @Override
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    83
            protected java.net.PasswordAuthentication getPasswordAuthentication() {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    84
                return new java.net.PasswordAuthentication(
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    85
                        "user", "pass".toCharArray());
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    86
            }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    87
        });
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    88
    }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    89
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    90
    private boolean ensureIPv6OnLoopback() throws Exception {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    91
        boolean ipv6 = false;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    92
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    93
        List<NetworkInterface> nics = Collections.list(NetworkInterface.getNetworkInterfaces());
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    94
        for (NetworkInterface nic : nics) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    95
            if (!nic.isLoopback()) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    96
                continue;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    97
            }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    98
            List<InetAddress> addrs = Collections.list(nic.getInetAddresses());
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    99
            for (InetAddress addr : addrs) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   100
                if (addr instanceof Inet6Address) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   101
                    ipv6 = true;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   102
                    break;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   103
                }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   104
            }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   105
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   106
        if (!ipv6)
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   107
            System.out.println("IPv6 is not enabled on loopback. Skipping test suite.");
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   108
        return ipv6;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   109
    }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   110
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   111
    private boolean ensureInet6AddressFamily() throws IOException {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   112
        try (ServerSocket s = new ServerSocket()) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   113
            s.bind(new InetSocketAddress("::1", 0));
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   114
            return true;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   115
        } catch (SocketException e) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   116
            System.out.println("Inet 6 address family is not available. Skipping test suite.");
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   117
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   118
        return false;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   119
    }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   120
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   121
    @Test(groups = "unit")
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   122
    public void testSocksOverIPv6() throws Exception {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   123
        if (!shouldRun) return;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   124
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   125
        Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("::1",
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   126
                socks.getPort()));
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   127
        URL url = new URL("http://[::1]:" + server.getAddress().getPort());
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   128
        java.net.URLConnection conn = url.openConnection(proxy);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   129
        String actual = "";
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   130
        try (BufferedReader reader = new BufferedReader(
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   131
                new InputStreamReader(conn.getInputStream()))) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   132
            actual = reader.readLine();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   133
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   134
        assertEquals(actual, response);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   135
    }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   136
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   137
    @Test(groups = "unit")
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   138
    public void testSocksOverIPv6Hostname() throws Exception {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   139
        if (!shouldRun) return;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   140
54634
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   141
        InetAddress ipv6Loopback = InetAddress.getByName("::1");
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   142
        String ipv6Hostname = ipv6Loopback.getHostName();
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   143
        String ipv6HostAddress = ipv6Loopback.getHostAddress();
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   144
        InetAddress ipv4Loopback;
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   145
        String ipv4Hostname;
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   146
        String ipv4HostAddress;
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   147
        try {
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   148
            ipv4Loopback = InetAddress.getByName("127.0.0.1");
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   149
            ipv4Hostname = ipv4Loopback == null ? null : ipv4Loopback.getHostName();
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   150
            ipv4HostAddress = ipv4Loopback == null ? null : ipv4Loopback.getHostAddress();
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   151
        } catch (IOException io) {
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   152
            ipv4Hostname = null;
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   153
            ipv4HostAddress = null;
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   154
        }
22276
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   155
54634
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   156
        System.out.println("ipv6Hostname: " + ipv6Hostname + " / " + ipv6HostAddress);
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   157
        System.out.println("ipv4Hostname: " + ipv4Hostname + " / " + ipv4HostAddress);
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   158
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   159
        if (ipv6Hostname.equals(ipv6HostAddress)) {
22276
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   160
            System.out.println("Unable to get the hostname of the IPv6 loopback "
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   161
                    + "address. Skipping test case.");
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   162
            return;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   163
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   164
54634
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   165
        if (ipv4Hostname != null && ipv6Hostname.equals(ipv4Hostname)) {
22276
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   166
            System.out.println("IPv6 and IPv4 loopback addresses map to the"
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   167
                    + " same hostname. Skipping test case.");
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   168
            return;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   169
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   170
54634
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   171
        if (!InetAddress.getByName(ipv6Hostname).getHostAddress()
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   172
                .equals(ipv6HostAddress)) {
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   173
            System.out.println(ipv6Hostname + " resolves to \""
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   174
                    + InetAddress.getByName(ipv6Hostname).getHostAddress()
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   175
                    + "\", not \"" + ipv6HostAddress +
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   176
                    "\". Skipping test case.");
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   177
            return;
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   178
        }
59c01214e478 8129315: java/net/Socket/LingerTest.java and java/net/Socket/ShutdownBoth.java timeout intermittently
dfuchs
parents: 53478
diff changeset
   179
22276
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   180
        Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(ipv6Hostname,
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   181
                socks.getPort()));
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   182
        URL url = new URL("http://" + ipv6Hostname + ":" + server.getAddress().getPort());
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   183
        java.net.URLConnection conn = url.openConnection(proxy);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   184
        String actual = "";
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   185
        try (BufferedReader reader = new BufferedReader(
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   186
                new InputStreamReader(conn.getInputStream()))) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   187
            actual = reader.readLine();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   188
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   189
        assertEquals(actual, response);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   190
    }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   191
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   192
    @AfterClass
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   193
    public void tearDown() {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   194
        if (server != null) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   195
            server.stop(1);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   196
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   197
        if (socks != null) {
53478
0716631b907f 8217740: SocksIPv6Test compilation error
rriggs
parents: 47216
diff changeset
   198
            socks.close();
22276
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   199
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   200
    }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   201
}