Path: blob/master/test/jdk/sun/security/ssl/SSLSocketImpl/IgnorableExceptionMessages.java
66645 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 825514826* @library /test/lib /javax/net/ssl/templates ../../27* @summary Checks for clarified exception messages for non-fatal SSLSocketImpl exceptions which28* can be ignored by the user29* @run main IgnorableExceptionMessages30*/3132/*33* This test runs in another process so we can monitor the debug34* results. The OutputAnalyzer must see correct debug output to return a35* success.36*/3738import jdk.test.lib.process.OutputAnalyzer;39import jdk.test.lib.process.ProcessTools;4041import javax.net.ssl.SSLHandshakeException;42import java.io.BufferedReader;43import java.io.InputStreamReader;44import java.net.URL;45import java.util.List;4647public class IgnorableExceptionMessages extends SSLSocketTemplate {48public static void main(String[] args) throws Exception {49if (args.length > 0) {50// A non-empty set of arguments occurs when the "runTest" argument51// is passed to the test via ProcessTools::executeTestJvm.52//53// This is done because an OutputAnalyzer is unable to read54// the output of the current running JVM, and must therefore create55// a test JVM. When this case occurs, it will inherit all specified56// properties passed to the test JVM - debug flags, tls version, etc.57new IgnorableExceptionMessages().run();58} else {59String clientTLSVersion = "-Djdk.tls.client.protocols=TLSv1.2";60String javaxDebugFlag = "-Djavax.net.debug=all";61String className = "IgnorableExceptionMessages";62String extraArgument = "runTest"; // Triggers the test JVM to execute when args.length > 063List<String> jvmArgs = List.of(64clientTLSVersion,65javaxDebugFlag,66className,67extraArgument);6869OutputAnalyzer output = ProcessTools.executeTestJvm(jvmArgs);7071if (output.getExitValue() != 0) {72output.asLines().forEach(System.out::println); // No need to dump the output unless the test fails73throw new RuntimeException("Test JVM process failed");74}7576try {77output.shouldContain("SSLSocket duplex close failed. Debug info only. Exception details:");78} catch (Exception ex) {79output.asLines().forEach(System.out::println); // No need to dump the output unless the test fails80throw ex;81}82}83}8485@Override86protected void runClientApplication(int serverPort) throws Exception {87String urlString = "https://localhost:" + serverPort + "/";88URL url = new URL(urlString);8990try {91new BufferedReader(new InputStreamReader(url.openStream()));92for(int i = 0; i < 10; i++) {93Thread.sleep(1000);94System.gc();95}96} catch (SSLHandshakeException sslEx) {97System.out.println(sslEx.getCause());98System.out.println(sslEx.getMessage());99}100}101}102103104