|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/** |
| 25 | + * @test |
| 26 | + * @bug 8255148 |
| 27 | + * @library /test/lib /javax/net/ssl/templates ../../ |
| 28 | + * @summary Checks for clarified exception messages for non-fatal SSLSocketImpl exceptions which |
| 29 | + * can be ignored by the user |
| 30 | + * @run main IgnorableExceptionMessages |
| 31 | + */ |
| 32 | + |
| 33 | +/* |
| 34 | + * This test runs in another process so we can monitor the debug |
| 35 | + * results. The OutputAnalyzer must see correct debug output to return a |
| 36 | + * success. |
| 37 | + */ |
| 38 | + |
| 39 | +import jdk.test.lib.process.OutputAnalyzer; |
| 40 | +import jdk.test.lib.process.ProcessTools; |
| 41 | + |
| 42 | +import javax.net.ssl.SSLHandshakeException; |
| 43 | +import java.io.BufferedReader; |
| 44 | +import java.io.InputStreamReader; |
| 45 | +import java.net.URL; |
| 46 | +import java.util.List; |
| 47 | + |
| 48 | +public class IgnorableExceptionMessages extends SSLSocketTemplate { |
| 49 | + public static void main(String[] args) throws Exception { |
| 50 | + if (args.length > 0) { |
| 51 | + // A non-empty set of arguments occurs when the "runTest" argument |
| 52 | + // is passed to the test via ProcessTools::executeTestJvm. |
| 53 | + // |
| 54 | + // This is done because an OutputAnalyzer is unable to read |
| 55 | + // the output of the current running JVM, and must therefore create |
| 56 | + // a test JVM. When this case occurs, it will inherit all specified |
| 57 | + // properties passed to the test JVM - debug flags, tls version, etc. |
| 58 | + new IgnorableExceptionMessages().run(); |
| 59 | + } else { |
| 60 | + String clientTLSVersion = "-Djdk.tls.client.protocols=TLSv1.2"; |
| 61 | + String javaxDebugFlag = "-Djavax.net.debug=all"; |
| 62 | + String className = "IgnorableExceptionMessages"; |
| 63 | + String extraArgument = "runTest"; // Triggers the test JVM to execute when args.length > 0 |
| 64 | + List<String> jvmArgs = List.of( |
| 65 | + clientTLSVersion, |
| 66 | + javaxDebugFlag, |
| 67 | + className, |
| 68 | + extraArgument); |
| 69 | + |
| 70 | + OutputAnalyzer output = ProcessTools.executeTestJvm(jvmArgs); |
| 71 | + |
| 72 | + if (output.getExitValue() != 0) { |
| 73 | + output.asLines().forEach(System.out::println); // No need to dump the output unless the test fails |
| 74 | + throw new RuntimeException("Test JVM process failed"); |
| 75 | + } |
| 76 | + |
| 77 | + try { |
| 78 | + output.shouldContain("SSLSocket duplex close failed. Debug info only. Exception details:"); |
| 79 | + } catch (Exception ex) { |
| 80 | + output.asLines().forEach(System.out::println); // No need to dump the output unless the test fails |
| 81 | + throw ex; |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + protected void runClientApplication(int serverPort) throws Exception { |
| 88 | + String urlString = "https://localhost:" + serverPort + "/"; |
| 89 | + URL url = new URL(urlString); |
| 90 | + |
| 91 | + try { |
| 92 | + new BufferedReader(new InputStreamReader(url.openStream())); |
| 93 | + for(int i = 0; i < 10; i++) { |
| 94 | + Thread.sleep(1000); |
| 95 | + System.gc(); |
| 96 | + } |
| 97 | + } catch (SSLHandshakeException sslEx) { |
| 98 | + System.out.println(sslEx.getCause()); |
| 99 | + System.out.println(sslEx.getMessage()); |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments