test/jdk/javax/net/ssl/TLS/TLSClientPropertyTest.java
author ssahoo
Thu, 28 Nov 2019 22:29:07 -0800
changeset 59316 753ab8dcdbba
parent 47241 be3d868a805a
permissions -rw-r--r--
8234723: javax/net/ssl/TLS tests support TLSv1.3 Summary: Missing TLSv1.3 test cases 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
/*
59316
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
     2
 * Copyright (c) 2014, 2019, 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
59316
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
    26
 * @bug 8049432 8069038 8234723
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
59316
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
    43
 * @run main/othervm TLSClientPropertyTest TLSv13
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
    44
 * @run main/othervm TLSClientPropertyTest TLS
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    45
 * @run main/othervm TLSClientPropertyTest WrongProperty
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    46
 */
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    47
40949
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    48
import java.security.KeyManagementException;
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    49
import java.security.NoSuchAlgorithmException;
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    50
import java.util.Arrays;
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    51
import java.util.List;
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    52
import javax.net.ssl.SSLContext;
be7a612613ae 8166032: Fix module dependencies for javax.SSL tests
skovalev
parents: 28570
diff changeset
    53
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    54
/**
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    55
 * 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
    56
 * 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
    57
 * 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
    58
 * protocols in the SSLContext.
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    59
 */
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    60
public class TLSClientPropertyTest {
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
    61
    private final String[] expectedSupportedProtos = new String[] {
59316
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
    62
            "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    63
    };
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
    public static void main(String[] args) throws Exception {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    66
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    67
        if (args.length < 1) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    68
            throw new RuntimeException(
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    69
                    "Incorrect arguments,expected arguments: testCase");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    70
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    71
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    72
        String[] expectedDefaultProtos;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    73
        String testCase = args[0];
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    74
        String contextProtocol;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    75
        switch (testCase) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    76
        case "NoProperty":
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    77
            if (System.getProperty("jdk.tls.client.protocols") != null) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    78
                System.getProperties().remove("jdk.tls.client.protocols");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    79
            }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    80
            contextProtocol = null;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    81
            expectedDefaultProtos = new String[] {
59316
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
    82
                    "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    83
            };
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    84
            break;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    85
        case "SSLv3":
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    86
            contextProtocol = "SSLv3";
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    87
            expectedDefaultProtos = new String[] {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    88
            };
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    89
            break;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    90
        case "TLSv1":
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    91
            contextProtocol = "TLSv1";
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    92
            expectedDefaultProtos = new String[] {
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
    93
                    "TLSv1"
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    94
            };
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    95
            break;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    96
        case "TLSv11":
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    97
            contextProtocol = "TLSv1.1";
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
    98
            expectedDefaultProtos = new String[] {
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
    99
                    "TLSv1", "TLSv1.1"
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   100
            };
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   101
            break;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   102
        case "TLSv12":
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   103
            contextProtocol = "TLSv1.2";
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   104
            expectedDefaultProtos = new String[] {
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
   105
                    "TLSv1", "TLSv1.1", "TLSv1.2"
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   106
            };
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   107
            break;
59316
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
   108
        case "TLSv13":
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
   109
        case "TLS":
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
   110
            contextProtocol = "TLSv1.3";
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
   111
            expectedDefaultProtos = new String[] {
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
   112
                    "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
   113
            };
753ab8dcdbba 8234723: javax/net/ssl/TLS tests support TLSv1.3
ssahoo
parents: 47241
diff changeset
   114
            break;
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   115
        case "WrongProperty":
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   116
            expectedDefaultProtos = new String[] {};
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   117
            contextProtocol = "TLSV";
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   118
            break;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   119
        default:
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   120
            throw new RuntimeException("test case is wrong");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   121
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   122
        if (contextProtocol != null) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   123
            System.setProperty("jdk.tls.client.protocols", contextProtocol);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   124
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   125
        try {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   126
            TLSClientPropertyTest test = new TLSClientPropertyTest();
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   127
            test.test(contextProtocol, expectedDefaultProtos);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   128
            if (testCase.equals("WrongProperty")) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   129
                throw new RuntimeException(
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   130
                        "Test failed: NoSuchAlgorithmException " +
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   131
                        "is expected when input wrong protocol");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   132
            } else {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   133
                System.out.println("Test " + contextProtocol + " passed");
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
        } catch (NoSuchAlgorithmException nsae) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   136
            if (testCase.equals("WrongProperty")) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   137
                System.out.println("NoSuchAlgorithmException is expected,"
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   138
                        + contextProtocol + " test passed");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   139
            } else {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   140
                throw nsae;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   141
            }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   142
        }
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
    }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   145
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   146
    /**
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   147
     * 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
   148
     * NoSuchAlgorithmException, WrongProperty test will use it.
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   149
     */
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   150
    public void test(String expectedContextProto,
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   151
            String[] expectedDefaultProtos) throws NoSuchAlgorithmException {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   152
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   153
        SSLContext context = null;
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   154
        try {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   155
            if (expectedContextProto != null) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   156
                context = SSLContext.getInstance(expectedContextProto);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   157
                context.init(null, null, null);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   158
            } else {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   159
                context = SSLContext.getDefault();
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
            printContextDetails(context);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   162
        } catch (KeyManagementException ex) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   163
            error(null, ex);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   164
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   165
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   166
        validateContext(expectedContextProto, expectedDefaultProtos, context);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   167
    }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   168
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   169
    /**
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   170
     * Simple print utility for SSLContext's protocol details.
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
    private void printContextDetails(SSLContext context) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   173
        System.out.println("Default   Protocols: "
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   174
                + Arrays.toString(context.getDefaultSSLParameters()
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   175
                        .getProtocols()));
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   176
        System.out.println("Supported Protocols: "
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   177
                + Arrays.toString(context.getSupportedSSLParameters()
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   178
                        .getProtocols()));
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   179
        System.out.println("Current   Protocol : " + context.getProtocol());
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   180
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
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
     * Error handler.
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
    private void error(String msg, Throwable tble) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   187
        String finalMsg = "FAILED " + (msg != null ? msg : "");
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   188
        if (tble != null) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   189
            throw new RuntimeException(finalMsg, tble);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   190
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   191
        throw new RuntimeException(finalMsg);
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
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   194
    /**
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   195
     * 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
   196
     */
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   197
    private void validateContext(String expectedProto,
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   198
            String[] expectedDefaultProtos, SSLContext context) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   199
        if (expectedProto == null) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   200
            expectedProto = "Default";
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   201
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   202
        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
   203
            error("Invalid current protocol: " + context.getProtocol()
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   204
                    + ", Expected:" + expectedProto, null);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   205
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   206
        List<String> actualDefaultProtos = Arrays.asList(context
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   207
                .getDefaultSSLParameters().getProtocols());
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
   208
        for (String p : expectedDefaultProtos) {
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   209
            if (!actualDefaultProtos.contains(p)) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   210
                error("Default protocol " + p + "missing", null);
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
        List<String> actualSupportedProtos = Arrays.asList(context
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   214
                .getSupportedSSLParameters().getProtocols());
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   215
28570
b00a1e9a9238 8069038: javax/net/ssl/TLS/TLSClientPropertyTest.java needs to be updated for JDK-8061210
wetmore
parents: 27939
diff changeset
   216
        for (String p : expectedSupportedProtos) {
27939
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   217
            if (!actualSupportedProtos.contains(p)) {
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   218
                error("Expected to support protocol:" + p, null);
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   219
            }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   220
        }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   221
    }
0a39982a7c6a 8049432: New tests for TLS property jdk.tls.client.protocols
xuelei
parents:
diff changeset
   222
}