28
28
import java .io .UncheckedIOException ;
29
29
import java .nio .file .*;
30
30
31
+ import java .security .Provider ;
31
32
import java .security .Security ;
32
33
import java .util .Arrays ;
33
34
import java .util .Optional ;
34
35
35
36
/*
36
37
* @test
37
38
* @summary Throw error if default java.security file is missing
38
- * @bug 8155246
39
+ * @bug 8155246 8292297
39
40
* @library /test/lib
40
41
* @run main ConfigFileTest
41
42
*/
@@ -50,39 +51,66 @@ public static void main(String[] args) throws Exception {
50
51
51
52
if (args .length == 1 ) {
52
53
// set up is complete. Run code to exercise loading of java.security
53
- System .out .println (Arrays .toString (Security .getProviders ()));
54
+ Provider [] provs = Security .getProviders ();
55
+ System .out .println (Arrays .toString (provs ) + "NumProviders: " + provs .length );
54
56
} else {
55
57
Files .createDirectory (copyJdkDir );
56
58
Path jdkTestDir = Path .of (Optional .of (System .getProperty ("test.jdk" ))
57
59
.orElseThrow (() -> new RuntimeException ("Couldn't load JDK Test Dir" ))
58
60
);
59
61
60
- copyJDKMinusJavaSecurity (jdkTestDir , copyJdkDir );
62
+ copyJDK (jdkTestDir , copyJdkDir );
61
63
String extraPropsFile = Path .of (System .getProperty ("test.src" ), "override.props" ).toString ();
62
64
63
65
// exercise some debug flags while we're here
64
- // launch JDK without java.security file being present or specified
65
- exerciseSecurity (copiedJava .toString (), "-cp" , System .getProperty ("test.classes" ),
66
+ // regular JDK install - should expect success
67
+ exerciseSecurity (0 , "java" ,
68
+ copiedJava .toString (), "-cp" , System .getProperty ("test.classes" ),
66
69
"-Djava.security.debug=all" , "-Djavax.net.debug=all" , "ConfigFileTest" , "runner" );
67
70
71
+ // given an overriding security conf file that doesn't exist, we shouldn't
72
+ // overwrite the properties from original/master security conf file
73
+ exerciseSecurity (0 , "SUN version" ,
74
+ copiedJava .toString (), "-cp" , System .getProperty ("test.classes" ),
75
+ "-Djava.security.debug=all" , "-Djavax.net.debug=all" ,
76
+ "-Djava.security.properties==file:///" + extraPropsFile + "badFileName" ,
77
+ "ConfigFileTest" , "runner" );
78
+
79
+ // test JDK launch with customized properties file
80
+ exerciseSecurity (0 , "NumProviders: 6" ,
81
+ copiedJava .toString (), "-cp" , System .getProperty ("test.classes" ),
82
+ "-Djava.security.debug=all" , "-Djavax.net.debug=all" ,
83
+ "-Djava.security.properties==file:///" + extraPropsFile ,
84
+ "ConfigFileTest" , "runner" );
85
+
86
+ // delete the master conf file
87
+ Files .delete (Path .of (copyJdkDir .toString (), "conf" ,
88
+ "security" ,"java.security" ));
89
+
90
+ // launch JDK without java.security file being present or specified
91
+ exerciseSecurity (1 , "Error loading java.security file" ,
92
+ copiedJava .toString (), "-cp" , System .getProperty ("test.classes" ),
93
+ "-Djava.security.debug=all" , "-Djavax.net.debug=all" ,
94
+ "ConfigFileTest" , "runner" );
95
+
68
96
// test the override functionality also. Should not be allowed since
69
97
// "security.overridePropertiesFile=true" Security property is missing.
70
- exerciseSecurity (copiedJava .toString (), "-cp" , System .getProperty ("test.classes" ),
98
+ exerciseSecurity (1 , "Error loading java.security file" ,
99
+ copiedJava .toString (), "-cp" , System .getProperty ("test.classes" ),
71
100
"-Djava.security.debug=all" , "-Djavax.net.debug=all" ,
72
- "-Djava.security.properties==file://" + extraPropsFile , "ConfigFileTest" , "runner" );
101
+ "-Djava.security.properties==file:/// " + extraPropsFile , "ConfigFileTest" , "runner" );
73
102
}
74
103
}
75
104
76
- private static void exerciseSecurity (String ... args ) throws Exception {
105
+ private static void exerciseSecurity (int exitCode , String output , String ... args ) throws Exception {
77
106
ProcessBuilder process = new ProcessBuilder (args );
78
107
OutputAnalyzer oa = ProcessTools .executeProcess (process );
79
- oa .shouldHaveExitValue (1 ).shouldContain ("java.security file missing" );
108
+ oa .shouldHaveExitValue (exitCode ).shouldContain (output );
80
109
}
81
110
82
- private static void copyJDKMinusJavaSecurity (Path src , Path dst ) throws Exception {
111
+ private static void copyJDK (Path src , Path dst ) throws Exception {
83
112
Files .walk (src )
84
113
.skip (1 )
85
- .filter (p -> !p .toString ().endsWith ("java.security" ))
86
114
.forEach (file -> {
87
115
try {
88
116
Files .copy (file , dst .resolve (src .relativize (file )), StandardCopyOption .COPY_ATTRIBUTES );
@@ -91,4 +119,4 @@ private static void copyJDKMinusJavaSecurity(Path src, Path dst) throws Exceptio
91
119
}
92
120
});
93
121
}
94
- }
122
+ }
0 commit comments