< prev index next >

test/jdk/javax/net/ssl/compatibility/Compatibility.java

Print this page


   1 /*
   2  * Copyright (c) 2017, 2018, 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  * @summary This test is used to check the interop compatibility on JSSE among
  27  *     different JDK releases.
  28  *     Note that, this is a manual test. For more details about the test and
  29  *     its usages, please look through README.
  30  *
  31  * @library /test/lib
  32  * @compile -source 1.7 -target 1.7 JdkUtils.java Parameter.java Server.java Client.java
  33  * @run main/manual Compatibility
  34  */
  35 
  36 import java.io.File;
  37 import java.io.FileOutputStream;
  38 import java.io.FileWriter;
  39 import java.io.IOException;
  40 import java.io.PrintStream;
  41 import java.nio.file.Files;
  42 import java.nio.file.Paths;
  43 import java.util.ArrayList;
  44 import java.util.LinkedHashMap;
  45 import java.util.LinkedHashSet;
  46 import java.util.List;
  47 import java.util.Map;
  48 import java.util.Set;
  49 import java.util.concurrent.ExecutorService;
  50 import java.util.concurrent.Executors;
  51 import java.util.concurrent.Future;
  52 import java.util.concurrent.TimeUnit;


  64 
  65         Set<JdkInfo> jdkInfos = jdkInfoList();
  66 
  67         System.out.println("Test start");
  68 
  69         List<TestCase> testCases = new ArrayList<>();
  70         ExecutorService executor = Executors.newCachedThreadPool();
  71         PrintStream origStdOut = System.out;
  72         PrintStream origStdErr = System.err;
  73 
  74         try (PrintStream printStream = new PrintStream(
  75                 new FileOutputStream(Utils.TEST_LOG, true))) {
  76             System.setOut(printStream);
  77             System.setErr(printStream);
  78 
  79             System.out.println(Utils.startHtml());
  80             System.out.println(Utils.startPre());
  81 
  82             for (UseCase useCase : UseCase.getAllUseCases()) {
  83                 for (JdkInfo serverJdk : jdkInfos) {
  84                     if (useCase.ignoredByJdk(serverJdk)) {
  85                         continue;
  86                     }
  87 
  88                     Map<String, String> props = new LinkedHashMap<>();
  89                     if (debug) {
  90                         props.put("javax.net.debug", "ssl");
  91                     }
  92                     props.put("java.security.properties", javaSecurityFile);
  93 
  94                     props.put(Utils.PROP_PROTOCOL, useCase.protocol.version);
  95                     props.put(Utils.PROP_CIPHER_SUITE, useCase.cipherSuite.name());
  96                     props.put(Utils.PROP_CLIENT_AUTH, useCase.clientAuth.name());
  97                     if (useCase.appProtocol != AppProtocol.NONE) {
  98                         props.put(Utils.PROP_APP_PROTOCOLS,
  99                                 Utils.join(Utils.VALUE_DELIMITER,
 100                                         useCase.appProtocol.appProtocols));
 101                         props.put(Utils.PROP_NEGO_APP_PROTOCOL,
 102                                 useCase.appProtocol.negoAppProtocol);
 103                     }
 104                     props.put(Utils.PROP_SERVER_JDK, serverJdk.version);
 105 
 106                     props.put(Utils.PROP_SUPPORTS_SNI_ON_SERVER,
 107                             serverJdk.supportsSNI + "");
 108                     props.put(Utils.PROP_SUPPORTS_ALPN_ON_SERVER,
 109                             serverJdk.supportsALPN + "");
 110 
 111                     for (JdkInfo clientJdk : jdkInfos) {
 112                         if (useCase.ignoredByJdk(clientJdk)) {
 113                             continue;
 114                         }
 115 
 116                         TestCase testCase = new TestCase(serverJdk, clientJdk,
 117                                 useCase);
 118                         System.out.println(Utils.anchorName(testCase.toString(),
 119                                 "----- Case start -----"));
 120                         System.out.println(testCase.toString());
 121 
 122                         props.put(Utils.PROP_NEGATIVE_CASE_ON_SERVER,
 123                                 testCase.negativeCaseOnServer + "");
 124                         props.put(Utils.PROP_NEGATIVE_CASE_ON_CLIENT,
 125                                 testCase.negativeCaseOnClient + "");
 126 
 127                         Future<OutputAnalyzer> serverFuture = executor.submit(() -> {
 128                             return runServer(serverJdk.jdkPath, props);
 129                         });
 130                         int port = waitForServerStarted();
 131                         System.out.println("port=" + port);
 132 
 133                         props.put(Utils.PROP_PORT, port + "");
 134 
 135                         props.put(Utils.PROP_CLIENT_JDK, clientJdk.version);
 136 
 137                         props.put(Utils.PROP_SUPPORTS_SNI_ON_CLIENT,
 138                                 clientJdk.supportsSNI + "");
 139                         props.put(Utils.PROP_SUPPORTS_ALPN_ON_CLIENT,
 140                                 clientJdk.supportsALPN + "");
 141                         if (useCase.serverName != ServerName.NONE) {
 142                             props.put(Utils.PROP_SERVER_NAME,
 143                                     useCase.serverName.name);
 144                         }
 145 
 146                         Status clientStatus = null;
 147                         if (port != -1) {
 148                             String clientOutput = runClient(clientJdk.jdkPath,
 149                                     props).getOutput();
 150                             clientStatus = getStatus(clientOutput);
 151                         }
 152 
 153                         String serverOutput = serverFuture.get().getOutput();
 154                         Status serverStatus = getStatus(serverOutput);
 155                         testCase.setStatus(caseStatus(serverStatus, clientStatus));
 156                         testCases.add(testCase);
 157                         System.out.printf(
 158                                 "ServerStatus=%s, ClientStatus=%s, CaseStatus=%s%n",
 159                                 serverStatus, clientStatus, testCase.getStatus());
 160 
 161                         System.out.println("----- Case end -----");
 162                     }
 163                 }
 164             }
 165 
 166             System.out.println(Utils.endPre());
 167             System.out.println(Utils.endHtml());
 168         }
 169         System.setOut(origStdOut);
 170         System.setErr(origStdErr);
 171         executor.shutdown();
 172 
 173         System.out.println("Test end");
 174         System.out.println("Report is being generated...");
 175         boolean failed = generateReport(testCases);
 176         System.out.println("Report is generated.");
 177         if (failed) {
 178             throw new RuntimeException("At least one case failed. "
 179                     + "Please check logs for more details.");
 180         }
 181     }


 292         report.append(Utils.row(
 293                 "No.",
 294                 "ServerJDK",
 295                 "ClientJDK",
 296                 "Protocol",
 297                 "CipherSuite",
 298                 "ClientAuth",
 299                 "SNI",
 300                 "ALPN",
 301                 "Status"));
 302         for (int i = 0, size = testCases.size(); i < size; i++) {
 303             TestCase testCase = testCases.get(i);
 304 
 305             report.append(Utils.row(
 306                     Utils.anchorLink(
 307                             Utils.TEST_LOG,
 308                             testCase.toString(),
 309                             i + ""),
 310                     testCase.serverJdk.version,
 311                     testCase.clientJdk.version,
 312                     testCase.useCase.protocol.version,
 313                     testCase.useCase.cipherSuite,
 314                     Utils.boolToStr(
 315                             testCase.useCase.clientAuth == ClientAuth.TRUE),
 316                     Utils.boolToStr(
 317                             testCase.useCase.serverName == ServerName.EXAMPLE),
 318                     Utils.boolToStr(
 319                             testCase.useCase.appProtocol == AppProtocol.EXAMPLE),
 320                     testCase.getStatus()));
 321             failed = failed
 322                     || testCase.getStatus() == Status.FAIL
 323                     || testCase.getStatus() == Status.UNEXPECTED_SUCCESS;
 324         }
 325         report.append(Utils.endTable());
 326         report.append(Utils.endHtml());
 327 
 328         generateFile("report.html", report.toString());
 329         return failed;
 330     }
 331 
 332     private static void generateFile(String path, String content)
 333             throws IOException {
 334         try(FileWriter writer = new FileWriter(new File(path))) {
 335             writer.write(content);
 336         }
 337     }
 338 }
   1 /*
   2  * Copyright (c) 2017, 2019, 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  * @summary This test is used to check the interop compatibility on JSSE among
  27  *     different JDK releases.
  28  *     Note that, this is a manual test. For more details about the test and
  29  *     its usages, please look through README.
  30  *
  31  * @library /test/lib ../TLSCommon
  32  * @compile -source 1.7 -target 1.7 JdkUtils.java Server.java Client.java
  33  * @run main/manual Compatibility
  34  */
  35 
  36 import java.io.File;
  37 import java.io.FileOutputStream;
  38 import java.io.FileWriter;
  39 import java.io.IOException;
  40 import java.io.PrintStream;
  41 import java.nio.file.Files;
  42 import java.nio.file.Paths;
  43 import java.util.ArrayList;
  44 import java.util.LinkedHashMap;
  45 import java.util.LinkedHashSet;
  46 import java.util.List;
  47 import java.util.Map;
  48 import java.util.Set;
  49 import java.util.concurrent.ExecutorService;
  50 import java.util.concurrent.Executors;
  51 import java.util.concurrent.Future;
  52 import java.util.concurrent.TimeUnit;


  64 
  65         Set<JdkInfo> jdkInfos = jdkInfoList();
  66 
  67         System.out.println("Test start");
  68 
  69         List<TestCase> testCases = new ArrayList<>();
  70         ExecutorService executor = Executors.newCachedThreadPool();
  71         PrintStream origStdOut = System.out;
  72         PrintStream origStdErr = System.err;
  73 
  74         try (PrintStream printStream = new PrintStream(
  75                 new FileOutputStream(Utils.TEST_LOG, true))) {
  76             System.setOut(printStream);
  77             System.setErr(printStream);
  78 
  79             System.out.println(Utils.startHtml());
  80             System.out.println(Utils.startPre());
  81 
  82             for (UseCase useCase : UseCase.getAllUseCases()) {
  83                 for (JdkInfo serverJdk : jdkInfos) {




  84                     Map<String, String> props = new LinkedHashMap<>();
  85                     if (debug) {
  86                         props.put("javax.net.debug", "all");
  87                     }
  88                     props.put("java.security.properties", javaSecurityFile);
  89 
  90                     props.put(Utils.PROP_PROTOCOL, useCase.protocol.name);
  91                     props.put(Utils.PROP_CIPHER_SUITE, useCase.cipherSuite.name());
  92                     props.put(Utils.PROP_CLIENT_AUTH, String.valueOf(useCase.clientAuth));
  93                     if (useCase.appProtocol != UseCase.AppProtocol.NONE) {
  94                         props.put(Utils.PROP_APP_PROTOCOLS,
  95                                 Utils.join(Utils.VALUE_DELIMITER,
  96                                         useCase.appProtocol.appProtocols));
  97                         props.put(Utils.PROP_NEGO_APP_PROTOCOL,
  98                                 useCase.appProtocol.negoAppProtocol);
  99                     }
 100                     props.put(Utils.PROP_SERVER_JDK, serverJdk.version);
 101 
 102                     props.put(Utils.PROP_SUPPORTS_SNI_ON_SERVER,
 103                             serverJdk.supportsSNI + "");
 104                     props.put(Utils.PROP_SUPPORTS_ALPN_ON_SERVER,
 105                             serverJdk.supportsALPN + "");
 106 
 107                     for (JdkInfo clientJdk : jdkInfos) {




 108                         TestCase testCase = new TestCase(serverJdk, clientJdk,
 109                                 useCase);
 110                         System.out.println(Utils.anchorName(testCase.toString(),
 111                                 "===== Case start ====="));
 112                         System.out.println(testCase.toString());
 113 
 114                         props.put(Utils.PROP_NEGATIVE_CASE_ON_SERVER,
 115                                 testCase.negativeCaseOnServer + "");
 116                         props.put(Utils.PROP_NEGATIVE_CASE_ON_CLIENT,
 117                                 testCase.negativeCaseOnClient + "");
 118 
 119                         Future<OutputAnalyzer> serverFuture = executor.submit(() -> {
 120                             return runServer(serverJdk.jdkPath, props);
 121                         });
 122                         int port = waitForServerStarted();
 123                         System.out.println("port=" + port);
 124 
 125                         props.put(Utils.PROP_PORT, port + "");
 126 
 127                         props.put(Utils.PROP_CLIENT_JDK, clientJdk.version);
 128 
 129                         props.put(Utils.PROP_SUPPORTS_SNI_ON_CLIENT,
 130                                 clientJdk.supportsSNI + "");
 131                         props.put(Utils.PROP_SUPPORTS_ALPN_ON_CLIENT,
 132                                 clientJdk.supportsALPN + "");
 133                         if (useCase.serverName != UseCase.ServerName.NONE) {
 134                             props.put(Utils.PROP_SERVER_NAME,
 135                                     useCase.serverName.name);
 136                         }
 137 
 138                         Status clientStatus = null;
 139                         if (port != -1) {
 140                             String clientOutput = runClient(clientJdk.jdkPath,
 141                                     props).getOutput();
 142                             clientStatus = getStatus(clientOutput);
 143                         }
 144 
 145                         String serverOutput = serverFuture.get().getOutput();
 146                         Status serverStatus = getStatus(serverOutput);
 147                         testCase.setStatus(caseStatus(serverStatus, clientStatus));
 148                         testCases.add(testCase);
 149                         System.out.printf(
 150                                 "ServerStatus=%s, ClientStatus=%s, CaseStatus=%s%n",
 151                                 serverStatus, clientStatus, testCase.getStatus());
 152 
 153                         System.out.println("===== Case end =====");
 154                     }
 155                 }
 156             }
 157 
 158             System.out.println(Utils.endPre());
 159             System.out.println(Utils.endHtml());
 160         }
 161         System.setOut(origStdOut);
 162         System.setErr(origStdErr);
 163         executor.shutdown();
 164 
 165         System.out.println("Test end");
 166         System.out.println("Report is being generated...");
 167         boolean failed = generateReport(testCases);
 168         System.out.println("Report is generated.");
 169         if (failed) {
 170             throw new RuntimeException("At least one case failed. "
 171                     + "Please check logs for more details.");
 172         }
 173     }


 284         report.append(Utils.row(
 285                 "No.",
 286                 "ServerJDK",
 287                 "ClientJDK",
 288                 "Protocol",
 289                 "CipherSuite",
 290                 "ClientAuth",
 291                 "SNI",
 292                 "ALPN",
 293                 "Status"));
 294         for (int i = 0, size = testCases.size(); i < size; i++) {
 295             TestCase testCase = testCases.get(i);
 296 
 297             report.append(Utils.row(
 298                     Utils.anchorLink(
 299                             Utils.TEST_LOG,
 300                             testCase.toString(),
 301                             i + ""),
 302                     testCase.serverJdk.version,
 303                     testCase.clientJdk.version,
 304                     testCase.useCase.protocol.name,
 305                     testCase.useCase.cipherSuite,
 306                     Utils.boolToStr(
 307                             testCase.useCase.clientAuth),
 308                     Utils.boolToStr(
 309                             testCase.useCase.serverName == UseCase.ServerName.EXAMPLE),
 310                     Utils.boolToStr(
 311                             testCase.useCase.appProtocol == UseCase.AppProtocol.EXAMPLE),
 312                     testCase.getStatus()));
 313             failed = failed
 314                     || testCase.getStatus() == Status.FAIL
 315                     || testCase.getStatus() == Status.UNEXPECTED_SUCCESS;
 316         }
 317         report.append(Utils.endTable());
 318         report.append(Utils.endHtml());
 319 
 320         generateFile("report.html", report.toString());
 321         return failed;
 322     }
 323 
 324     private static void generateFile(String path, String content)
 325             throws IOException {
 326         try(FileWriter writer = new FileWriter(new File(path))) {
 327             writer.write(content);
 328         }
 329     }
 330 }
< prev index next >