Skip to content

Commit 65e7759

Browse files
i556354GoeLin
authored andcommitted
8220410: sun/security/tools/jarsigner/warnings/NoTimestampTest.java failed with missing expected output
Using the same timezone for jar verifying and date formatting Reviewed-by: goetz Backport-of: 3c34b7a
1 parent 32e16ae commit 65e7759

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

test/jdk/sun/security/tools/jarsigner/warnings/NoTimestampTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.security.cert.X509Certificate;
2828
import java.util.Date;
2929
import java.util.Locale;
30+
import java.util.TimeZone;
3031

3132
import jdk.test.lib.process.OutputAnalyzer;
3233
import jdk.test.lib.util.JarUtils;
@@ -46,6 +47,7 @@ public class NoTimestampTest extends Test {
4647
* and checks that proper warnings are shown.
4748
*/
4849
public static void main(String[] args) throws Throwable {
50+
4951
Locale reservedLocale = Locale.getDefault();
5052
Locale.setDefault(Locale.US);
5153

@@ -61,6 +63,9 @@ public static void main(String[] args) throws Throwable {
6163
private void start() throws Throwable {
6264
String timezone = System.getProperty("user.timezone");
6365
System.out.println(String.format("Timezone = %s", timezone));
66+
if (timezone != null) {
67+
TimeZone.setDefault(TimeZone.getTimeZone(timezone));
68+
}
6469

6570
// create a jar file that contains one class file
6671
Utils.createFiles(FIRST_FILE);
@@ -73,10 +78,11 @@ private void start() throws Throwable {
7378
"-validity", Integer.toString(VALIDITY));
7479

7580
Date expirationDate = getCertExpirationDate();
81+
System.out.println("Cert expiration: " + expirationDate);
7682

7783
// sign jar file
7884
OutputAnalyzer analyzer = jarsigner(
79-
"-J-Duser.timezone=" + timezone,
85+
userTimezoneOpt(timezone),
8086
"-keystore", KEYSTORE,
8187
"-storepass", PASSWORD,
8288
"-keypass", PASSWORD,
@@ -90,7 +96,7 @@ private void start() throws Throwable {
9096

9197
// verify signed jar
9298
analyzer = jarsigner(
93-
"-J-Duser.timezone=" + timezone,
99+
userTimezoneOpt(timezone),
94100
"-verify",
95101
"-keystore", KEYSTORE,
96102
"-storepass", PASSWORD,
@@ -103,7 +109,7 @@ private void start() throws Throwable {
103109

104110
// verify signed jar in strict mode
105111
analyzer = jarsigner(
106-
"-J-Duser.timezone=" + timezone,
112+
userTimezoneOpt(timezone),
107113
"-verify",
108114
"-strict",
109115
"-keystore", KEYSTORE,
@@ -117,6 +123,10 @@ private void start() throws Throwable {
117123
System.out.println("Test passed");
118124
}
119125

126+
private static String userTimezoneOpt(String timezone) {
127+
return timezone == null ? null : "-J-Duser.timezone=" + timezone;
128+
}
129+
120130
private static Date getCertExpirationDate() throws Exception {
121131
KeyStore ks = KeyStore.getInstance("JKS");
122132
try (InputStream in = new FileInputStream(KEYSTORE)) {

test/jdk/sun/security/tools/jarsigner/warnings/Test.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,12 +21,13 @@
2121
* questions.
2222
*/
2323

24-
import jdk.test.lib.process.OutputAnalyzer;
25-
import jdk.test.lib.process.ProcessTools;
26-
2724
import java.util.ArrayList;
2825
import java.util.Arrays;
2926
import java.util.List;
27+
import java.util.stream.Collectors;
28+
29+
import jdk.test.lib.process.OutputAnalyzer;
30+
import jdk.test.lib.process.ProcessTools;
3031

3132
/**
3233
* Base class.
@@ -263,7 +264,9 @@ private OutputAnalyzer tool(String tool, String... args) throws Throwable {
263264
cmd.add(tool);
264265
cmd.add("-J-Duser.language=en");
265266
cmd.add("-J-Duser.country=US");
266-
cmd.addAll(Arrays.asList(args));
267+
cmd.addAll(Arrays.asList(args).stream().filter(arg -> {
268+
return arg != null && !arg.isEmpty();
269+
}).collect(Collectors.toList()));
267270
return ProcessTools.executeCommand(cmd.toArray(new String[cmd.size()]));
268271
}
269272
}

0 commit comments

Comments
 (0)