1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
29
29
* @run testng/othervm InconsistentEntries
30
30
*/
31
31
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 ;
32
36
import org .testng .Assert ;
33
- import org .testng .annotations .AfterTest ;
34
37
import org .testng .annotations .BeforeTest ;
35
38
import org .testng .annotations .Test ;
36
39
37
40
import javax .crypto .*;
38
41
import java .io .File ;
39
- import java .io .IOException ;
40
42
import java .nio .file .Files ;
41
43
import java .nio .file .Path ;
42
44
import java .nio .file .Paths ;
45
47
46
48
public class InconsistentEntries {
47
49
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 ());
55
58
56
59
@ 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
58
65
if (!POLICY_DIR .toFile ().exists ()) {
59
66
Files .createDirectory (POLICY_DIR );
60
67
}
61
68
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 );
69
71
}
70
72
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 )) {
78
75
throw new RuntimeException (
79
76
"custom policy subdirectory: testlimited does not exist" );
80
77
}
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 ());
84
79
if (testpolicy .length () == 0 ) {
85
80
throw new RuntimeException (
86
81
"policy: default_local.policy does not exist or is empty" );
@@ -91,4 +86,16 @@ public void test() throws Exception {
91
86
Assert .assertThrows (ExceptionInInitializerError .class ,
92
87
() -> Cipher .getMaxAllowedKeyLength ("AES" ));
93
88
}
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
+ }
94
101
}
0 commit comments