test/jdk/javax/net/ssl/TLS/TLSClientPropertyTest.java
author weijun
Fri, 22 Sep 2017 09:49:08 +0800
changeset 47241 be3d868a805a
parent 47216 71c04702a3d5
child 59316 753ab8dcdbba
permissions -rw-r--r--
8187786: Many javax/net/ssl/DTLS tests failing Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
     1
/*
40949
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
     4
 *
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
     8
 *
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    13
 * accompanied this code).
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    14
 *
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    18
 *
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    21
 * questions.
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    22
 */
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    23
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    24
/*
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    25
 * @test
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
    26
 * @bug 8049432 8069038
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    27
 * @summary New tests for TLS property jdk.tls.client.protocols
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
    28
 * @summary javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
    29
 *     updated for JDK-8061210
40949
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    30
 * @modules java.security.jgss
47241
be3d868a805a 8187786: Many javax/net/ssl/DTLS tests failing
weijun
parents: 47216
diff changeset
    31
 *          java.security.jgss/sun.security.jgss.krb5
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40949
diff changeset
    32
 *          java.security.jgss/sun.security.krb5:+open
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40949
diff changeset
    33
 *          java.security.jgss/sun.security.krb5.internal:+open
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40949
diff changeset
    34
 *          java.security.jgss/sun.security.krb5.internal.ccache
40949
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    35
 *          java.security.jgss/sun.security.krb5.internal.crypto
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    36
 *          java.security.jgss/sun.security.krb5.internal.ktab
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    37
 *          java.base/sun.security.util
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    38
 * @run main/othervm TLSClientPropertyTest NoProperty
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    39
 * @run main/othervm TLSClientPropertyTest SSLv3
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    40
 * @run main/othervm TLSClientPropertyTest TLSv1
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    41
 * @run main/othervm TLSClientPropertyTest TLSv11
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    42
 * @run main/othervm TLSClientPropertyTest TLSv12
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    43
 * @run main/othervm TLSClientPropertyTest WrongProperty
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    44
 */
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    45
40949
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    46
import java.security.KeyManagementException;
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    47
import java.security.NoSuchAlgorithmException;
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    48
import java.util.Arrays;
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    49
import java.util.List;
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    50
import javax.net.ssl.SSLContext;
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    51
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    52
/**
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    53
 * Sets the property jdk.tls.client.protocols to one of this protocols:
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    54
 * SSLv3,TLSv1,TLSv1.1,TLSv1.2 and TLSV(invalid) or removes this
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    55
 * property (if any),then validates the default, supported and current
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    56
 * protocols in the SSLContext.
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    57
 */
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    58
public class TLSClientPropertyTest {
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
    59
    private final String[] expectedSupportedProtos = new String[] {
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    60
            "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    61
    };
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    62
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    63
    public static void main(String[] args) throws Exception {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    64
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    65
        if (args.length < 1) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    66
            throw new RuntimeException(
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    67
                    "Incorrect arguments,expected arguments: testCase");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    68
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    69
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    70
        String[] expectedDefaultProtos;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    71
        String testCase = args[0];
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    72
        String contextProtocol;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    73
        switch (testCase) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    74
        case "NoProperty":
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    75
            if (System.getProperty("jdk.tls.client.protocols") != null) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    76
                System.getProperties().remove("jdk.tls.client.protocols");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    77
            }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    78
            contextProtocol = null;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    79
            expectedDefaultProtos = new String[] {
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
    80
                    "TLSv1", "TLSv1.1", "TLSv1.2"
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    81
            };
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    82
            break;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    83
        case "SSLv3":
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    84
            contextProtocol = "SSLv3";
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    85
            expectedDefaultProtos = new String[] {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    86
            };
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    87
            break;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    88
        case "TLSv1":
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    89
            contextProtocol = "TLSv1";
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    90
            expectedDefaultProtos = new String[] {
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
    91
                    "TLSv1"
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    92
            };
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    93
            break;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    94
        case "TLSv11":
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    95
            contextProtocol = "TLSv1.1";
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    96
            expectedDefaultProtos = new String[] {
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
    97
                    "TLSv1", "TLSv1.1"
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    98
            };
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    99
            break;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   100
        case "TLSv12":
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   101
            contextProtocol = "TLSv1.2";
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   102
            expectedDefaultProtos = new String[] {
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
   103
                    "TLSv1", "TLSv1.1", "TLSv1.2"
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   104
            };
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   105
            break;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   106
        case "WrongProperty":
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   107
            expectedDefaultProtos = new String[] {};
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   108
            contextProtocol = "TLSV";
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   109
            break;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   110
        default:
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   111
            throw new RuntimeException("test case is wrong");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   112
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   113
        if (contextProtocol != null) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   114
            System.setProperty("jdk.tls.client.protocols", contextProtocol);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   115
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   116
        try {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   117
            TLSClientPropertyTest test = new TLSClientPropertyTest();
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   118
            test.test(contextProtocol, expectedDefaultProtos);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   119
            if (testCase.equals("WrongProperty")) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   120
                throw new RuntimeException(
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   121
                        "Test failed: NoSuchAlgorithmException " +
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   122
                        "is expected when input wrong protocol");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   123
            } else {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   124
                System.out.println("Test " + contextProtocol + " passed");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   125
            }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   126
        } catch (NoSuchAlgorithmException nsae) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   127
            if (testCase.equals("WrongProperty")) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   128
                System.out.println("NoSuchAlgorithmException is expected,"
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   129
                        + contextProtocol + " test passed");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   130
            } else {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   131
                throw nsae;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   132
            }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   133
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   134
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   135
    }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   136
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   137
    /**
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   138
     * The parameter passed is the user enforced protocol. Does not catch
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   139
     * NoSuchAlgorithmException, WrongProperty test will use it.
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   140
     */
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   141
    public void test(String expectedContextProto,
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   142
            String[] expectedDefaultProtos) throws NoSuchAlgorithmException {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   143
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   144
        SSLContext context = null;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   145
        try {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   146
            if (expectedContextProto != null) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   147
                context = SSLContext.getInstance(expectedContextProto);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   148
                context.init(null, null, null);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   149
            } else {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   150
                context = SSLContext.getDefault();
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   151
            }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   152
            printContextDetails(context);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   153
        } catch (KeyManagementException ex) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   154
            error(null, ex);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   155
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   156
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   157
        validateContext(expectedContextProto, expectedDefaultProtos, context);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   158
    }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   159
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   160
    /**
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   161
     * Simple print utility for SSLContext's protocol details.
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   162
     */
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   163
    private void printContextDetails(SSLContext context) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   164
        System.out.println("Default   Protocols: "
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   165
                + Arrays.toString(context.getDefaultSSLParameters()
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   166
                        .getProtocols()));
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   167
        System.out.println("Supported Protocols: "
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   168
                + Arrays.toString(context.getSupportedSSLParameters()
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   169
                        .getProtocols()));
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   170
        System.out.println("Current   Protocol : " + context.getProtocol());
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   171
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   172
    }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   173
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   174
    /**
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   175
     * Error handler.
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   176
     */
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   177
    private void error(String msg, Throwable tble) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   178
        String finalMsg = "FAILED " + (msg != null ? msg : "");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   179
        if (tble != null) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   180
            throw new RuntimeException(finalMsg, tble);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   181
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   182
        throw new RuntimeException(finalMsg);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   183
    }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   184
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   185
    /**
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   186
     * Validates the SSLContext's protocols against the user enforced protocol.
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   187
     */
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   188
    private void validateContext(String expectedProto,
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   189
            String[] expectedDefaultProtos, SSLContext context) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   190
        if (expectedProto == null) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   191
            expectedProto = "Default";
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   192
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   193
        if (!context.getProtocol().equals(expectedProto)) {
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
   194
            error("Invalid current protocol: " + context.getProtocol()
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   195
                    + ", Expected:" + expectedProto, null);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   196
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   197
        List<String> actualDefaultProtos = Arrays.asList(context
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   198
                .getDefaultSSLParameters().getProtocols());
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
   199
        for (String p : expectedDefaultProtos) {
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   200
            if (!actualDefaultProtos.contains(p)) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   201
                error("Default protocol " + p + "missing", null);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   202
            }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   203
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   204
        List<String> actualSupportedProtos = Arrays.asList(context
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   205
                .getSupportedSSLParameters().getProtocols());
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   206
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
   207
        for (String p : expectedSupportedProtos) {
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   208
            if (!actualSupportedProtos.contains(p)) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   209
                error("Expected to support protocol:" + p, null);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   210
            }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   211
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   212
    }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   213
}