Skip to content

Commit 199b8d3

Browse files
author
duke
committed
Backport 430290066c23d09166a84f2f6f89e770c6ba04ff
1 parent 9677a85 commit 199b8d3

File tree

3 files changed

+36
-37
lines changed

3 files changed

+36
-37
lines changed

test/jdk/com/sun/crypto/provider/KeyProtector/IterationCount.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252

5353
public class IterationCount {
5454
private static final String clientStr = "CLIENT";
55-
private static final String javaBinPath =
56-
System.getProperty("java.home", ".") + File.separator + "bin" +
57-
File.separator + "java";
5855

5956
public static void main(String[] args) throws Throwable {
6057
if (args[0].equals("HOST")) {
@@ -78,22 +75,14 @@ public static void main(String[] args) throws Throwable {
7875
System.out.println("TEST PASS - OK");
7976
}
8077

81-
private static List<String> getBasicCommand() {
82-
List<String> cmd = new ArrayList<>();
83-
cmd.add(javaBinPath);
84-
cmd.add("-cp");
85-
cmd.add(System.getProperty("test.classes", "."));
86-
return cmd;
87-
}
88-
8978
private static void executeCommand(List<String> cmd, String expectedCount)
9079
throws Throwable {
9180
cmd.add("--add-opens=java.base/com.sun.crypto.provider=ALL-UNNAMED");
9281
cmd.add(IterationCount.class.getName());
9382
cmd.add(clientStr);
9483
cmd.add(expectedCount);
95-
OutputAnalyzer out = ProcessTools.executeCommand(
96-
cmd.toArray(new String[cmd.size()]));
84+
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(cmd);
85+
OutputAnalyzer out = ProcessTools.executeCommand(pb);
9786
out.shouldHaveExitValue(0);
9887
}
9988

@@ -102,7 +91,7 @@ private static void testSystem(String expectedCount, String setValue)
10291
System.out.println("Test setting " +
10392
(setValue != null ? setValue : "nothing") +
10493
" as a System property");
105-
List<String> cmd = getBasicCommand();
94+
List<String> cmd = new ArrayList<>();
10695
if (setValue != null) {
10796
cmd.add("-Djdk.jceks.iterationCount=" + setValue);
10897
}
@@ -112,7 +101,7 @@ private static void testSystem(String expectedCount, String setValue)
112101

113102
private static void testSecurity(String expectedCount, String setValue)
114103
throws Throwable {
115-
testSecurity(expectedCount, setValue, getBasicCommand());
104+
testSecurity(expectedCount, setValue, new ArrayList<>());
116105
}
117106

118107
private static void testSecurity(String expectedCount, String setValue,
@@ -140,15 +129,14 @@ private static void testSystemOverridesSecurity() throws Throwable {
140129
" the Security one");
141130
String systemValue = Integer.toString(30000);
142131
System.out.println("System value: " + systemValue);
143-
List<String> cmd = getBasicCommand();
132+
List<String> cmd = new ArrayList<>();
144133
cmd.add("-Djdk.jceks.iterationCount=" + systemValue);
145134
testSecurity(systemValue, Integer.toString(40000), cmd);
146135
}
147136

148137
private static void writeJavaSecurityProp(String javaSecurityPath,
149138
String setValue) throws IOException {
150-
try (FileOutputStream fos = new FileOutputStream(
151-
new File(javaSecurityPath))) {
139+
try (FileOutputStream fos = new FileOutputStream(javaSecurityPath)) {
152140
fos.write(("jdk.jceks.iterationCount=" + setValue).getBytes());
153141
}
154142
}

test/jdk/java/security/Security/ConfigFileTest.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, 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,6 +21,7 @@
2121
* questions.
2222
*/
2323

24+
import jdk.test.lib.Utils;
2425
import jdk.test.lib.process.OutputAnalyzer;
2526
import jdk.test.lib.process.ProcessTools;
2627

@@ -30,7 +31,9 @@
3031

3132
import java.security.Provider;
3233
import java.security.Security;
34+
import java.util.ArrayList;
3335
import java.util.Arrays;
36+
import java.util.Collections;
3437
import java.util.Optional;
3538

3639
/*
@@ -50,6 +53,9 @@ public class ConfigFileTest {
5053

5154
private static boolean overrideDetected = false;
5255

56+
private static Path COPY_JDK_DIR = Path.of("./jdk-8155246-tmpdir");
57+
private static Path COPIED_JAVA = COPY_JDK_DIR.resolve("bin", "java");
58+
5359
public static void main(String[] args) throws Exception {
5460
Path copyJdkDir = Path.of("./jdk-8155246-tmpdir");
5561
Path copiedJava = Optional.of(
@@ -72,55 +78,61 @@ public static void main(String[] args) throws Exception {
7278
String extraPropsFile = Path.of(System.getProperty("test.src"), "override.props").toString();
7379

7480
// sanity test -XshowSettings:security option
75-
exerciseShowSettingsSecurity(copiedJava.toString(), "-cp", System.getProperty("test.classes"),
76-
"-Djava.security.debug=all", "-XshowSettings:security", "ConfigFileTest", "runner");
81+
exerciseShowSettingsSecurity(buildCommand("-cp", System.getProperty("test.classes"),
82+
"-Djava.security.debug=all", "-XshowSettings:security", "ConfigFileTest", "runner"));
7783

7884
// exercise some debug flags while we're here
7985
// regular JDK install - should expect success
8086
exerciseSecurity(0, "java",
81-
copiedJava.toString(), "-cp", System.getProperty("test.classes"),
82-
"-Djava.security.debug=all", "-Djavax.net.debug=all", "ConfigFileTest", "runner");
87+
buildCommand("-cp", System.getProperty("test.classes"),
88+
"-Djava.security.debug=all", "-Djavax.net.debug=all", "ConfigFileTest", "runner"));
8389

8490
// given an overriding security conf file that doesn't exist, we shouldn't
8591
// overwrite the properties from original/master security conf file
8692
exerciseSecurity(0, "SUN version",
87-
copiedJava.toString(), "-cp", System.getProperty("test.classes"),
93+
buildCommand("-cp", System.getProperty("test.classes"),
8894
"-Djava.security.debug=all", "-Djavax.net.debug=all",
8995
"-Djava.security.properties==file:///" + extraPropsFile + "badFileName",
90-
"ConfigFileTest", "runner");
96+
"ConfigFileTest", "runner"));
9197

9298
// test JDK launch with customized properties file
9399
exerciseSecurity(0, "NumProviders: 6",
94-
copiedJava.toString(), "-cp", System.getProperty("test.classes"),
100+
buildCommand("-cp", System.getProperty("test.classes"),
95101
"-Djava.security.debug=all", "-Djavax.net.debug=all",
96102
"-Djava.security.properties==file:///" + extraPropsFile,
97-
"ConfigFileTest", "runner");
103+
"ConfigFileTest", "runner"));
98104

99105
// delete the master conf file
100106
Files.delete(Path.of(copyJdkDir.toString(), "conf",
101107
"security","java.security"));
102108

103109
// launch JDK without java.security file being present or specified
104110
exerciseSecurity(1, "Error loading java.security file",
105-
copiedJava.toString(), "-cp", System.getProperty("test.classes"),
111+
buildCommand("-cp", System.getProperty("test.classes"),
106112
"-Djava.security.debug=all", "-Djavax.net.debug=all",
107-
"ConfigFileTest", "runner");
113+
"ConfigFileTest", "runner"));
108114

109115
// test the override functionality also. Should not be allowed since
110116
// "security.overridePropertiesFile=true" Security property is missing.
111117
exerciseSecurity(1, "Error loading java.security file",
112-
copiedJava.toString(), "-cp", System.getProperty("test.classes"),
118+
buildCommand("-cp", System.getProperty("test.classes"),
113119
"-Djava.security.debug=all", "-Djavax.net.debug=all",
114-
"-Djava.security.properties==file:///" + extraPropsFile, "ConfigFileTest", "runner");
120+
"-Djava.security.properties==file:///" + extraPropsFile, "ConfigFileTest", "runner"));
115121

116122
if (!overrideDetected) {
117123
throw new RuntimeException("Override scenario not seen");
118124
}
119125
}
120126
}
121127

122-
private static void exerciseSecurity(int exitCode, String output, String... args) throws Exception {
123-
ProcessBuilder process = new ProcessBuilder(args);
128+
private static ProcessBuilder buildCommand(String... command) {
129+
ArrayList<String> args = new ArrayList<>();
130+
args.add(COPIED_JAVA.toString());
131+
Collections.addAll(args, Utils.prependTestJavaOpts(command));
132+
return new ProcessBuilder(args);
133+
}
134+
135+
private static void exerciseSecurity(int exitCode, String output, ProcessBuilder process) throws Exception {
124136
OutputAnalyzer oa = ProcessTools.executeProcess(process);
125137
oa.shouldHaveExitValue(exitCode)
126138
.shouldContain(output);
@@ -141,8 +153,7 @@ private static void exerciseSecurity(int exitCode, String output, String... args
141153
}
142154

143155
// exercise the -XshowSettings:security launcher
144-
private static void exerciseShowSettingsSecurity(String... args) throws Exception {
145-
ProcessBuilder process = new ProcessBuilder(args);
156+
private static void exerciseShowSettingsSecurity(ProcessBuilder process) throws Exception {
146157
OutputAnalyzer oa = ProcessTools.executeProcess(process);
147158
oa.shouldHaveExitValue(0)
148159
.shouldContain("Security properties:")

test/jdk/sun/security/provider/KeyStore/DKSTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2024, 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
@@ -80,7 +80,7 @@ public class DKSTest {
8080
public static void main(String[] args) throws Exception {
8181
if (args.length == 0) {
8282
// Environment variable and system properties referred in domains.cfg used by this Test.
83-
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(List.of(
83+
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(List.of(
8484
"-Dtest.src=" + TEST_SRC , "-Duser.dir=" + USER_DIR, "DKSTest", "run"));
8585
pb.environment().putAll(System.getenv());
8686
pb.environment().put("KEYSTORE_PWD", "test12");

0 commit comments

Comments
 (0)