Path: blob/master/test/jdk/sun/security/ssl/SSLLogger/LoggingFormatConsistency.java
41152 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 821122726* @library /test/lib /javax/net/ssl/templates ../../27* @summary Tests for consistency in logging format of TLS Versions28* @run main/othervm LoggingFormatConsistency29*/3031/*32* This test runs in another process so we can monitor the debug33* results. The OutputAnalyzer must see correct debug output to return a34* success.35*/3637import jdk.test.lib.process.ProcessTools;38import jdk.test.lib.security.SecurityUtils;3940import java.net.InetAddress;4142public class LoggingFormatConsistency extends SSLSocketTemplate {4344LoggingFormatConsistency () {45serverAddress = InetAddress.getLoopbackAddress();46SecurityUtils.removeFromDisabledTlsAlgs("TLSv1", "TLSv1.1");47}4849public static void main(String[] args) throws Exception {50if (args.length != 0) {51// A non-empty set of arguments occurs when the "runTest" argument52// is passed to the test via ProcessTools::executeTestJvm.53//54// This is done because an OutputAnalyzer is unable to read55// the output of the current running JVM, and must therefore create56// a test JVM. When this case occurs, it will inherit all specified57// properties passed to the test JVM - debug flags, tls version, etc.58new LoggingFormatConsistency().run();59} else {60// We are in the test JVM that the test is being ran in.61var testSrc = "-Dtest.src=" + System.getProperty("test.src");62var javaxNetDebug = "-Djavax.net.debug=all";6364var correctTlsVersionsFormat = new String[]{"TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"};65var incorrectTLSVersionsFormat = new String[]{"TLS10", "TLS11", "TLS12", "TLS13"};6667for (var i = 0; i < correctTlsVersionsFormat.length; i++) {68var expectedTLSVersion = correctTlsVersionsFormat[i];69var incorrectTLSVersion = incorrectTLSVersionsFormat[i];7071System.out.println("TESTING " + expectedTLSVersion);72var activeTLSProtocol = "-Djdk.tls.client.protocols=" + expectedTLSVersion;73var output = ProcessTools.executeTestJvm(74testSrc,75activeTLSProtocol,76javaxNetDebug,77"LoggingFormatConsistency",78"runTest"); // Ensuring args.length is greater than 0 when test JVM starts7980output.asLines()81.stream()82.filter(line -> line.startsWith("Connecting to"))83.forEach(System.out::println); // prints connection info from test jvm output8485if (output.getExitValue() != 0) {86output.asLines().forEach(System.out::println);87throw new RuntimeException("Test JVM process failed");88}8990output.shouldContain(expectedTLSVersion);91output.shouldNotContain(incorrectTLSVersion);92}93}94}95}969798