changeset 54183:7418b266e1c7

8220410: sun/security/tools/jarsigner/warnings/NoTimestampTest.java failed with missing expected output Summary: Using the same timezone for jar verifying and date formatting Reviewed-by: weijun
author jjiang
date Tue, 19 Mar 2019 10:36:24 +0800
parents 2e586b74722e
children 5f4dedb4dcf5
files test/jdk/sun/security/tools/jarsigner/warnings/NoTimestampTest.java test/jdk/sun/security/tools/jarsigner/warnings/Test.java
diffstat 2 files changed, 22 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/sun/security/tools/jarsigner/warnings/NoTimestampTest.java	Mon Mar 18 15:26:59 2019 -0700
+++ b/test/jdk/sun/security/tools/jarsigner/warnings/NoTimestampTest.java	Tue Mar 19 10:36:24 2019 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 import java.security.cert.X509Certificate;
 import java.util.Date;
 import java.util.Locale;
+import java.util.TimeZone;
 
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.util.JarUtils;
@@ -46,6 +47,7 @@
      * and checks that proper warnings are shown.
      */
     public static void main(String[] args) throws Throwable {
+
         Locale reservedLocale = Locale.getDefault();
         Locale.setDefault(Locale.US);
 
@@ -61,6 +63,9 @@
     private void start() throws Throwable {
         String timezone = System.getProperty("user.timezone");
         System.out.println(String.format("Timezone = %s", timezone));
+        if (timezone != null) {
+            TimeZone.setDefault(TimeZone.getTimeZone(timezone));
+        }
 
         // create a jar file that contains one class file
         Utils.createFiles(FIRST_FILE);
@@ -73,10 +78,11 @@
                 "-validity", Integer.toString(VALIDITY));
 
         Date expirationDate = getCertExpirationDate();
+        System.out.println("Cert expiration: " + expirationDate);
 
         // sign jar file
         OutputAnalyzer analyzer = jarsigner(
-                "-J-Duser.timezone=" + timezone,
+                userTimezoneOpt(timezone),
                 "-keystore", KEYSTORE,
                 "-storepass", PASSWORD,
                 "-keypass", PASSWORD,
@@ -90,7 +96,7 @@
 
         // verify signed jar
         analyzer = jarsigner(
-                "-J-Duser.timezone=" + timezone,
+                userTimezoneOpt(timezone),
                 "-verify",
                 "-keystore", KEYSTORE,
                 "-storepass", PASSWORD,
@@ -103,7 +109,7 @@
 
         // verify signed jar in strict mode
         analyzer = jarsigner(
-                "-J-Duser.timezone=" + timezone,
+                userTimezoneOpt(timezone),
                 "-verify",
                 "-strict",
                 "-keystore", KEYSTORE,
@@ -117,6 +123,10 @@
         System.out.println("Test passed");
     }
 
+    private static String userTimezoneOpt(String timezone) {
+        return timezone == null ? null : "-J-Duser.timezone=" + timezone;
+    }
+
     private static Date getCertExpirationDate() throws Exception {
         KeyStore ks = KeyStore.getInstance("JKS");
         try (InputStream in = new FileInputStream(KEYSTORE)) {
--- a/test/jdk/sun/security/tools/jarsigner/warnings/Test.java	Mon Mar 18 15:26:59 2019 -0700
+++ b/test/jdk/sun/security/tools/jarsigner/warnings/Test.java	Tue Mar 19 10:36:24 2019 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,12 +21,13 @@
  * questions.
  */
 
-import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
+
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.process.ProcessTools;
 
 /**
  * Base class.
@@ -259,7 +260,9 @@
         cmd.add(tool);
         cmd.add("-J-Duser.language=en");
         cmd.add("-J-Duser.country=US");
-        cmd.addAll(Arrays.asList(args));
+        cmd.addAll(Arrays.asList(args).stream().filter(arg -> {
+            return arg != null && !arg.isEmpty();
+        }).collect(Collectors.toList()));
         return ProcessTools.executeCommand(cmd.toArray(new String[cmd.size()]));
     }
 }