Skip to content

Commit b60e668

Browse files
author
Satyen Subramaniam
committed
8342238: Test javax/crypto/CryptoPermissions/InconsistentEntries.java writes files in tested JDK dir
Backport-of: 16033ea79a01b27a7f5cbb31d64da0e80afc7dc3
1 parent e57fbd4 commit b60e668

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed
Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, 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
@@ -29,14 +29,16 @@
2929
* @run testng/othervm InconsistentEntries
3030
*/
3131

32+
import java.util.List;
33+
import jdk.test.lib.Utils;
34+
import jdk.test.lib.cds.CDSTestUtils;
35+
import jdk.test.lib.process.ProcessTools;
3236
import org.testng.Assert;
33-
import org.testng.annotations.AfterTest;
3437
import org.testng.annotations.BeforeTest;
3538
import org.testng.annotations.Test;
3639

3740
import javax.crypto.*;
3841
import java.io.File;
39-
import java.io.IOException;
4042
import java.nio.file.Files;
4143
import java.nio.file.Path;
4244
import java.nio.file.Paths;
@@ -45,42 +47,35 @@
4547

4648
public class InconsistentEntries {
4749

48-
private static final String JDK_HOME = System.getProperty("test.jdk");
49-
private static final String TEST_SRC = System.getProperty("test.src");
50-
private static final Path POLICY_DIR = Paths.get(JDK_HOME, "conf", "security",
51-
"policy", "testlimited");
52-
private static final Path POLICY_FILE = Paths.get(TEST_SRC, "default_local.policy");
53-
54-
Path targetFile = null;
50+
private static final String JDK_HOME = System.getProperty("test.jdk", ".");
51+
private static final String TEST_SRC = System.getProperty("test.src", ".");
52+
private static final Path TEMP_JDK_HOME = Path.of("java");
53+
private static final Path POLICY_DIR = TEMP_JDK_HOME.resolve(Path.of("conf", "security",
54+
"policy", "testlimited"));
55+
private static final Path POLICY_FILE_SRC = Paths.get(TEST_SRC, "default_local.policy");
56+
private static final Path POLICY_FILE_TARGET = POLICY_DIR
57+
.resolve(POLICY_FILE_SRC.getFileName());
5558

5659
@BeforeTest
57-
public void setUp() throws IOException {
60+
public void setUp() throws Exception {
61+
// Clone the tested JDK to the scratch directory
62+
CDSTestUtils.clone(new File(JDK_HOME), new File(TEMP_JDK_HOME.toString()));
63+
64+
// create policy directory in the cloned JDK
5865
if (!POLICY_DIR.toFile().exists()) {
5966
Files.createDirectory(POLICY_DIR);
6067
}
6168

62-
targetFile = POLICY_DIR.resolve(POLICY_FILE.getFileName());
63-
Files.copy(POLICY_FILE, targetFile, StandardCopyOption.REPLACE_EXISTING);
64-
}
65-
66-
@AfterTest
67-
public void cleanUp() throws IOException {
68-
Files.delete(targetFile);
69+
// copy policy file into policy directory
70+
Files.copy(POLICY_FILE_SRC, POLICY_FILE_TARGET, StandardCopyOption.REPLACE_EXISTING);
6971
}
7072

71-
@Test
72-
public void test() throws Exception {
73-
String JAVA_HOME = System.getProperty("java.home");
74-
String FS = System.getProperty("file.separator");
75-
Path testlimited = Path.of(JAVA_HOME + FS + "conf" + FS + "security" +
76-
FS + "policy" + FS + "testlimited");
77-
if (!Files.exists(testlimited)) {
73+
public static void main(String[] args) throws Throwable {
74+
if (!Files.exists(POLICY_DIR)) {
7875
throw new RuntimeException(
7976
"custom policy subdirectory: testlimited does not exist");
8077
}
81-
82-
File testpolicy = new File(JAVA_HOME + FS + "conf" + FS + "security" +
83-
FS + "policy" + FS + "testlimited" + FS + "default_local.policy");
78+
File testpolicy = new File(POLICY_FILE_TARGET.toString());
8479
if (testpolicy.length() == 0) {
8580
throw new RuntimeException(
8681
"policy: default_local.policy does not exist or is empty");
@@ -91,4 +86,16 @@ public void test() throws Exception {
9186
Assert.assertThrows(ExceptionInInitializerError.class,
9287
() -> Cipher.getMaxAllowedKeyLength("AES"));
9388
}
89+
90+
@Test
91+
public void test() throws Exception {
92+
String tmpJava = TEMP_JDK_HOME.resolve("bin").resolve("java").toString();
93+
String[] args = Utils.prependTestJavaOpts(InconsistentEntries.class.getName());
94+
ProcessBuilder pb = new ProcessBuilder(tmpJava);
95+
pb.command().addAll(List.of(args));
96+
97+
ProcessTools
98+
.executeProcess(pb)
99+
.shouldHaveExitValue(0);
100+
}
94101
}

0 commit comments

Comments
 (0)