test/jdk/java/net/httpclient/ALPNProxyFailureTest.java
author jboes
Fri, 08 Nov 2019 11:15:16 +0000
changeset 59029 3786a0962570
parent 53350 a47b8125b7cc
permissions -rw-r--r--
8232853: AuthenticationFilter.Cache::remove may throw ConcurrentModificationException Summary: Change implementation to use iterator instead of plain LinkedList Reviewed-by: dfuchs, vtewari
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53350
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
     1
/*
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
     4
 *
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
     8
 *
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    14
 *
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    18
 *
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    21
 * questions.
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    22
 */
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    23
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    24
/*
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    25
 * @test
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    26
 * @summary This test will timeout if the ALPN CF is not completed
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    27
 *          when a 'Connection reset by peer' exception is raised
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    28
 *          during the handshake.
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    29
 * @bug 8217094
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    30
 * @library /test/lib http2/server
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    31
 * @build jdk.test.lib.net.SimpleSSLContext HttpServerAdapters DigestEchoServer
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    32
 *        ALPNFailureTest ALPNProxyFailureTest
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    33
 * @modules java.net.http/jdk.internal.net.http.common
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    34
 *          java.net.http/jdk.internal.net.http.frame
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    35
 *          java.net.http/jdk.internal.net.http.hpack
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    36
 *          java.logging
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    37
 *          java.base/sun.net.www.http
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    38
 *          java.base/sun.net.www
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    39
 *          java.base/sun.net
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    40
 * @build ALPNFailureTest
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    41
 * @run main/othervm -Djdk.internal.httpclient.debug=true -Dtest.nolinger=true ALPNProxyFailureTest HTTP_1_1
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    42
 * @run main/othervm -Dtest.nolinger=true ALPNProxyFailureTest HTTP_2
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    43
 */
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    44
import javax.net.ServerSocketFactory;
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    45
import javax.net.ssl.SSLContext;
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    46
import jdk.test.lib.net.SimpleSSLContext;
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    47
import java.net.InetAddress;
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    48
import java.net.ProxySelector;
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    49
import java.net.ServerSocket;
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    50
import java.net.http.HttpClient;
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    51
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    52
public class ALPNProxyFailureTest extends ALPNFailureTest {
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    53
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    54
    static final SSLContext context;
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    55
    static {
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    56
        try {
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    57
            context = new SimpleSSLContext().get();
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    58
            SSLContext.setDefault(context);
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    59
        } catch (Exception x) {
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    60
            throw new ExceptionInInitializerError(x);
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    61
        }
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    62
    }
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    63
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    64
    public static void main(String[] args) throws Exception{
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    65
        if (args == null || args.length == 0) {
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    66
            args = new String[] {HttpClient.Version.HTTP_1_1.name()};
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    67
        }
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    68
        ServerSocket socket = ServerSocketFactory.getDefault()
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    69
                .createServerSocket(0, 10, InetAddress.getLoopbackAddress());
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    70
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    71
        DigestEchoServer.TunnelingProxy proxy = DigestEchoServer.createHttpsProxyTunnel(
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    72
                DigestEchoServer.HttpAuthSchemeType.NONE);
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    73
        ProxySelector ps = ProxySelector.of(proxy.getProxyAddress());
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    74
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    75
        try {
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    76
            test(socket, context, ps, args);
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    77
        } finally {
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    78
            proxy.stop();
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    79
        }
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    80
    }
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    81
a47b8125b7cc 8217094: HttpClient SSL race if a socket IOException is raised before ALPN is available
dfuchs
parents:
diff changeset
    82
}