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
2121 * questions.
2222 */
2323
24+ import jdk .test .lib .Utils ;
2425import jdk .test .lib .process .OutputAnalyzer ;
2526import jdk .test .lib .process .ProcessTools ;
2627
3031
3132import java .security .Provider ;
3233import java .security .Security ;
34+ import java .util .ArrayList ;
3335import java .util .Arrays ;
36+ import java .util .Collections ;
3437import 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:" )
0 commit comments