test/jdk/javax/net/ssl/FixingJavadocs/ComURLNulls.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 30820 jdk/test/javax/net/ssl/FixingJavadocs/ComURLNulls.java@0d4717a011d3
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29615
b0057b63b4e7 8074531: Remove javax.security.cert.X509Certificate usage in internal networking packages
juh
parents: 29097
diff changeset
     2
 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4387882 4451038
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Need to revisit the javadocs for JSSE, especially the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *      promoted classes, and HttpsURLConnection.getCipherSuite throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *      NullPointerException
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 29615
diff changeset
    30
 * @modules java.base/com.sun.net.ssl
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 29615
diff changeset
    31
 *          java.base/com.sun.net.ssl.internal.www.protocol.https
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    32
 * @run main/othervm ComURLNulls
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    33
 *
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    34
 *     SunJSSE does not support dynamic system properties, no way to re-use
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    35
 *     system properties in samevm/agentvm mode.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @author Brad Wetmore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import com.sun.net.ssl.HttpsURLConnection;
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    43
import com.sun.net.ssl.HostnameVerifier;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Tests that the com null argument changes made it in ok.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class ComURLNulls {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
29097
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    51
    private static class ComSunHTTPSHandlerFactory implements URLStreamHandlerFactory {
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    52
        private static String SUPPORTED_PROTOCOL = "https";
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    53
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    54
        public URLStreamHandler createURLStreamHandler(String protocol) {
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    55
            if (!protocol.equalsIgnoreCase(SUPPORTED_PROTOCOL))
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    56
                return null;
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    57
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    58
            return new com.sun.net.ssl.internal.www.protocol.https.Handler();
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    59
        }
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    60
    }
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    61
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public static void main(String[] args) throws Exception {
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    63
        HostnameVerifier reservedHV =
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    64
            HttpsURLConnection.getDefaultHostnameVerifier();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        try {
29097
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    66
            URL.setURLStreamHandlerFactory(new ComSunHTTPSHandlerFactory());
01a70c01f5a1 8064924: Update java.net.URL to work with modules
chegar
parents: 23052
diff changeset
    67
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    68
            /**
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    69
             * This test does not establish any connection to the specified
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    70
             * URL, hence a dummy URL is used.
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    71
             */
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    72
            URL foobar = new URL("https://example.com/");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    73
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    74
            HttpsURLConnection urlc =
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    75
                (HttpsURLConnection) foobar.openConnection();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    77
            try {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    78
                urlc.getCipherSuite();
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    79
            } catch (IllegalStateException e) {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    80
                System.out.print("Caught proper exception: ");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    81
                System.out.println(e.getMessage());
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    82
            }
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    83
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    84
            try {
29615
b0057b63b4e7 8074531: Remove javax.security.cert.X509Certificate usage in internal networking packages
juh
parents: 29097
diff changeset
    85
                urlc.getServerCertificates();
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    86
            } catch (IllegalStateException e) {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    87
                System.out.print("Caught proper exception: ");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    88
                System.out.println(e.getMessage());
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    89
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    91
            try {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    92
                urlc.setDefaultHostnameVerifier(null);
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    93
            } catch (IllegalArgumentException e) {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    94
                System.out.print("Caught proper exception: ");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    95
                System.out.println(e.getMessage());
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    96
            }
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    97
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    98
            try {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    99
                urlc.setHostnameVerifier(null);
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   100
            } catch (IllegalArgumentException e) {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   101
                System.out.print("Caught proper exception: ");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   102
                System.out.println(e.getMessage());
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   103
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   105
            try {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   106
                urlc.setDefaultSSLSocketFactory(null);
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   107
            } catch (IllegalArgumentException e) {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   108
                System.out.print("Caught proper exception: ");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   109
                System.out.println(e.getMessage());
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   110
            }
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   111
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   112
            try {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   113
                urlc.setSSLSocketFactory(null);
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   114
            } catch (IllegalArgumentException e) {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   115
                System.out.print("Caught proper exception");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   116
                System.out.println(e.getMessage());
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   117
            }
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   118
            System.out.println("TESTS PASSED");
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   119
        } finally {
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   120
            HttpsURLConnection.setDefaultHostnameVerifier(reservedHV);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
}