Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,6 +47,7 @@ public class NoTimestampTest extends Test {
* and checks that proper warnings are shown.
*/
public static void main(String[] args) throws Throwable {

Locale reservedLocale = Locale.getDefault();
Locale.setDefault(Locale.US);

Expand All @@ -61,6 +63,9 @@ public static void main(String[] args) throws Throwable {
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);
Expand All @@ -73,10 +78,11 @@ private void start() throws Throwable {
"-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,
Expand All @@ -90,7 +96,7 @@ private void start() throws Throwable {

// verify signed jar
analyzer = jarsigner(
"-J-Duser.timezone=" + timezone,
userTimezoneOpt(timezone),
"-verify",
"-keystore", KEYSTORE,
"-storepass", PASSWORD,
Expand All @@ -103,7 +109,7 @@ private void start() throws Throwable {

// verify signed jar in strict mode
analyzer = jarsigner(
"-J-Duser.timezone=" + timezone,
userTimezoneOpt(timezone),
"-verify",
"-strict",
"-keystore", KEYSTORE,
Expand All @@ -117,6 +123,10 @@ private void start() throws Throwable {
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)) {
Expand Down
13 changes: 8 additions & 5 deletions test/jdk/sun/security/tools/jarsigner/warnings/Test.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -263,7 +264,9 @@ private OutputAnalyzer tool(String tool, String... args) throws Throwable {
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()]));
}
}