jdk/test/java/net/Socks/SocksIPv6Test.java
author coleenp
Wed, 17 Jun 2015 21:44:48 +0000
changeset 31362 8957ccbb5821
parent 22276 7fc4c8b08e49
child 38883 d5de564f8089
permissions -rw-r--r--
8098821: Crash in system dictionary initialization with shared strings Summary: map string regions after the compressed class base is known Reviewed-by: iklam, dcubed Contributed-by: coleen.phillimore@oracle.com, mikhailo.seledtsov@oracle.com
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
/*
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
     2
 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
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
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    26
 * @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
    27
 * @run testng SocksIPv6Test
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    28
 */
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
import java.io.BufferedReader;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    31
import java.io.IOException;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    32
import java.io.InputStream;
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.net.UnknownHostException;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    46
import java.util.Collections;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    47
import java.util.List;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    48
import com.sun.net.httpserver.*;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    49
import java.io.BufferedWriter;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    50
import org.testng.annotations.AfterClass;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    51
import org.testng.annotations.BeforeClass;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    52
import org.testng.annotations.Test;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    53
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    54
import static org.testng.Assert.*;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    55
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    56
public class SocksIPv6Test {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    57
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    58
    private HttpServer server;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    59
    private SocksServer socks;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    60
    private String response = "Hello.";
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    61
    private static boolean shouldRun = false;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    62
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    63
    @BeforeClass
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    64
    public void setUp() throws Exception {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    65
        shouldRun = ensureInet6AddressFamily() && ensureIPv6OnLoopback();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    66
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    67
        server = HttpServer.create(new InetSocketAddress(0), 0);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    68
        server.createContext("/", ex -> {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    69
            ex.sendResponseHeaders(200, response.length());
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    70
            try (BufferedWriter writer = new BufferedWriter(
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    71
                    new OutputStreamWriter(ex.getResponseBody(), "UTF-8"))) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    72
                writer.write(response);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    73
            }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    74
            ex.close();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    75
        });
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    76
        server.start();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    77
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    78
        socks = new SocksServer(0, false);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    79
        socks.addUser("user", "pass");
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    80
        socks.start();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    81
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    82
        Authenticator.setDefault(new Authenticator() {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    83
            @Override
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    84
            protected java.net.PasswordAuthentication getPasswordAuthentication() {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    85
                return new java.net.PasswordAuthentication(
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    86
                        "user", "pass".toCharArray());
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
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    91
    private boolean ensureIPv6OnLoopback() throws Exception {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    92
        boolean ipv6 = false;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    93
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    94
        List<NetworkInterface> nics = Collections.list(NetworkInterface.getNetworkInterfaces());
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    95
        for (NetworkInterface nic : nics) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    96
            if (!nic.isLoopback()) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    97
                continue;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    98
            }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
    99
            List<InetAddress> addrs = Collections.list(nic.getInetAddresses());
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   100
            for (InetAddress addr : addrs) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   101
                if (addr instanceof Inet6Address) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   102
                    ipv6 = true;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   103
                    break;
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
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   107
        if (!ipv6)
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   108
            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
   109
        return ipv6;
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
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   112
    private boolean ensureInet6AddressFamily() throws IOException {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   113
        try (ServerSocket s = new ServerSocket()) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   114
            s.bind(new InetSocketAddress("::1", 0));
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   115
            return true;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   116
        } catch (SocketException e) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   117
            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
   118
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   119
        return false;
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
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   122
    @Test(groups = "unit")
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   123
    public void testSocksOverIPv6() throws Exception {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   124
        if (!shouldRun) return;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   125
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   126
        Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("::1",
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   127
                socks.getPort()));
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   128
        URL url = new URL("http://[::1]:" + server.getAddress().getPort());
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   129
        java.net.URLConnection conn = url.openConnection(proxy);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   130
        String actual = "";
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   131
        try (BufferedReader reader = new BufferedReader(
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   132
                new InputStreamReader(conn.getInputStream()))) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   133
            actual = reader.readLine();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   134
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   135
        assertEquals(actual, response);
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
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   138
    @Test(groups = "unit")
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   139
    public void testSocksOverIPv6Hostname() throws Exception {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   140
        if (!shouldRun) return;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   141
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   142
        String ipv6Hostname = InetAddress.getByName("::1").getHostName();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   143
        String ipv4Hostname = InetAddress.getByName("127.0.0.1").getHostName();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   144
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   145
        if (ipv6Hostname.equals(InetAddress.getByName("::1").getHostAddress())) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   146
            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
   147
                    + "address. Skipping test case.");
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   148
            return;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   149
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   150
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   151
        if (ipv6Hostname.equals(ipv4Hostname)) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   152
            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
   153
                    + " same hostname. Skipping test case.");
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   154
            return;
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   155
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   156
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   157
        Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(ipv6Hostname,
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   158
                socks.getPort()));
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   159
        URL url = new URL("http://" + ipv6Hostname + ":" + server.getAddress().getPort());
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   160
        java.net.URLConnection conn = url.openConnection(proxy);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   161
        String actual = "";
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   162
        try (BufferedReader reader = new BufferedReader(
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   163
                new InputStreamReader(conn.getInputStream()))) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   164
            actual = reader.readLine();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   165
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   166
        assertEquals(actual, response);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   167
    }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   168
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   169
    @AfterClass
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   170
    public void tearDown() {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   171
        if (server != null) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   172
            server.stop(1);
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   173
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   174
        if (socks != null) {
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   175
            socks.terminate();
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   176
        }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   177
    }
7fc4c8b08e49 7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff changeset
   178
}