3636
3737import java .security .Provider ;
3838import java .security .Security ;
39+ import java .util .ArrayList ;
3940import java .util .Arrays ;
4041import java .util .List ;
4142
@@ -47,12 +48,14 @@ public class TestProperties {
4748
4849 private String customprofile ;
4950 private String securityPropertyFile ;
51+ private String securityPropertyFileList ;
5052 private String expected ;
5153 private int expectedExitValue ;
5254
53- public TestProperties (String customprofile , String securityPropertyFile , String expected , int expectedExitValue ) {
55+ public TestProperties (String customprofile , String securityPropertyFile , String securityPropertyFileList , String expected , int expectedExitValue ) {
5456 this .customprofile = customprofile ;
5557 this .securityPropertyFile = securityPropertyFile ;
58+ this .securityPropertyFileList = securityPropertyFileList ;
5659 this .expected = expected ;
5760 this .expectedExitValue = expectedExitValue ;
5861 }
@@ -62,127 +65,148 @@ public static List<Object[]> data() {
6265 return Arrays .asList (new Object [][] {
6366 // 1 - Test property - Same beginnings of the profile name without version.
6467 {"Test-Profile-SameStartWithoutVersion" ,
65- System .getProperty ("test.src" ) + "/property-java.security" ,
68+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
6669 "(?s)(?=.*Sun)(?=.*\\ bSunJCE\\ b)(?=.*SunJSSE)" , 0 },
6770
6871 // 1 - Test profile - base profile misspell properties.
6972 {"Test-Profile.Base" ,
70- System .getProperty ("test.src" ) + "/property-java.security" ,
73+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
7174 "The property names: RestrictedSecurity.Test-Profile.Base.tls.disabledAlgorithmsWrongTypo "
7275 + "in profile RestrictedSecurity.Test-Profile.Base \\ (or a base profile\\ ) are not recognized" , 1 },
7376 // 2 - Test profile - extenstion profile misspell properties.
7477 {"Test-Profile.Extended_1" ,
75- System .getProperty ("test.src" ) + "/property-java.security" ,
78+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
7679 "The property names: RestrictedSecurity.Test-Profile.Extended_1.desc.nameWrongTypo, "
7780 + "RestrictedSecurity.Test-Profile.Extended_1.jce.providerWrongTypo in profile "
7881 + "RestrictedSecurity.Test-Profile.Extended_1 \\ (or a base profile\\ ) are not recognized" , 1 },
7982 // 3 - Test profile - extension profile from another extension profile misspell properties.
8083 {"Test-Profile.Extended_2" ,
81- System .getProperty ("test.src" ) + "/property-java.security" ,
84+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
8285 "The property names: RestrictedSecurity.Test-Profile.Extended_2.jce.providerWrongTypo "
8386 + "in profile RestrictedSecurity.Test-Profile.Extended_2 \\ (or a base profile\\ ) are not recognized" , 1 },
8487 // 4 - Test profile - profile not exist.
8588 {"Test-Profile-NotExist.Base" ,
86- System .getProperty ("test.src" ) + "/property-java.security" ,
89+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
8790 "Test-Profile-NotExist.Base is not present in the java.security file." , 1 },
8891 // 5 - Test profile - Multi Default profile.
8992 {"Test-Profile-MultiDefault" ,
90- System .getProperty ("test.src" ) + "/property-java.security" ,
93+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
9194 "Multiple default RestrictedSecurity profiles for Test-Profile-MultiDefault" , 1 },
9295 // 6 - Test profile - no default profile.
9396 {"Test-Profile-NoDefault" ,
94- System .getProperty ("test.src" ) + "/property-java.security" ,
97+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
9598 "No default RestrictedSecurity profile was found for Test-Profile-NoDefault" , 1 },
9699 // 7 - Test profile - base profile does not exist.
97100 {"Test-Profile.Extended_3" ,
98- System .getProperty ("test.src" ) + "/property-java.security" ,
101+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
99102 "RestrictedSecurity.Test-Profile.BaseNotExist that is supposed to extend \\ 'RestrictedSecurity.Test-Profile.Extended_3\\ ' "
100103 + "is not present in the java.security file or any appended files" , 1 },
101104 // 8 - Test profile - base profile not full profile name.
102105 {"Test-Profile.Extended_4" ,
103- System .getProperty ("test.src" ) + "/property-java.security" ,
106+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
104107 "RestrictedSecurity.BaseNotFullProfileName that is supposed to extend \\ 'RestrictedSecurity.Test-Profile.Extended_4\\ ' "
105108 + "is not a full profile name" , 1 },
106109 // 9 - Test profile - base profile without hash value.
107110 {"Test-Profile-BaseWithoutHash" ,
108- System .getProperty ("test.src" ) + "/property-java.security" ,
111+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
109112 "Test-Profile-BaseWithoutHash is a base profile, so a hash value is mandatory" , 1 },
110113 // 10 - Test profile - incorrect definition of hash value.
111114 {"Test-Profile-Hash_1" ,
112- System .getProperty ("test.src" ) + "/property-java.security" ,
115+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
113116 "Incorrect definition of hash value for RestrictedSecurity.Test-Profile-Hash_1" , 1 },
114117 // 11 - Test profile - incorrect hash value.
115118 {"Test-Profile-Hash_2" ,
116- System .getProperty ("test.src" ) + "/property-java.security" ,
119+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
117120 "Hex produced from profile is not the same is a base profile, so a hash value is mandatory" , 1 },
118121 // 12 - Test property - property not appendable.
119122 {"Test-Profile-SetProperty.Extension_1" ,
120- System .getProperty ("test.src" ) + "/property-java.security" ,
123+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
121124 "Property \\ 'jdkSecureRandomAlgorithm\\ ' is not appendable" , 1 },
122125 // 13 - Test property - property does not exist in parent profile, cannot append.
123126 {"Test-Profile-SetProperty.Extension_2" ,
124- System .getProperty ("test.src" ) + "/property-java.security" ,
127+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
125128 "Property \\ 'jdkTlsDisabledNamedCurves\\ ' does not exist in parent profile or java.security file. Cannot append" , 1 },
126129 // 14 - Test property - property value is not in existing values.
127130 {"Test-Profile-SetProperty.Extension_3" ,
128- System .getProperty ("test.src" ) + "/property-java.security" ,
131+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
129132 "Value \\ 'TestDisabledlgorithms\\ ' is not in existing values" , 1 },
130133 // 15 - Test property - policy sunset.
131134 {"Test-Profile-PolicySunset.Base" ,
132- System .getProperty ("test.src" ) + "/property-java.security" ,
135+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
133136 "Use -Dsemeru.restrictedsecurity.ignoresunsetexpiration to allow Java to start while possibly using uncertified cryptograph" , 1 },
134137 // 16 - Test property - policy sunset format.
135138 {"Test-Profile-PolicySunsetFormat.Base" ,
136- System .getProperty ("test.src" ) + "/property-java.security" ,
139+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
137140 "Restricted security policy sunset date is incorrect, the correct format is yyyy-MM-dd" , 1 },
138141 // 17 - Test property - secure random check 1.
139142 {"Test-Profile-SecureRandomCheck_1" ,
140- System .getProperty ("test.src" ) + "/property-java.security" ,
143+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
141144 "Restricted security mode secure random is missing" , 1 },
142145 // 18 - Test property - secure random check 2.
143146 {"Test-Profile-SecureRandomCheck_2" ,
144- System .getProperty ("test.src" ) + "/property-java.security" ,
147+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
145148 "Restricted security mode secure random is missing" , 1 },
146149 // 19 - Test constraint - constraint check 1.
147150 {"Test-Profile-Constraint_1" ,
148- System .getProperty ("test.src" ) + "/property-java.security" ,
151+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
149152 "Provider format is incorrect" , 1 },
150153 // 20 - Test constraint - constraint check 2.
151154 {"Test-Profile-Constraint_2" ,
152- System .getProperty ("test.src" ) + "/property-java.security" ,
155+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
153156 "Incorrect constraint definition for provider" , 1 },
154157 // 21 - Test constraint - constraint check 3.
155158 {"Test-Profile-Constraint_3" ,
156- System .getProperty ("test.src" ) + "/property-java.security" ,
159+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
157160 "Incorrect constraint definition for provider" , 1 },
158161 // 22 - Test constraint - constraint attributes check.
159162 {"Test-Profile-Constraint_Attributes" ,
160- System .getProperty ("test.src" ) + "/property-java.security" ,
163+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
161164 "Constraint attributes format is incorrect" , 1 },
162165 // 23 - Test constraint - constraint changed 1.
163166 {"Test-Profile-ConstraintChanged_1.Extension" ,
164- System .getProperty ("test.src" ) + "/property-java.security" ,
167+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
165168 "Cannot append or remove constraints since the provider (.*?) "
166169 + "wasn't in this position in the profile extended" , 1 },
167170 // 24 - Test constraint - constraint changed 2.
168171 {"Test-Profile-ConstraintChanged_2.Extension" ,
169- System .getProperty ("test.src" ) + "/property-java.security" ,
172+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
170173 "Constraint (.*?)is not part of existing constraints" , 1 },
171174 // 25 - Test constraint - constraint changed 3.
172175 {"Test-Profile-ConstraintChanged_3.Base" ,
173- System .getProperty ("test.src" ) + "/property-java.security" ,
174- "Constraints of provider not previously specified cannot be modified" , 1 }
176+ System .getProperty ("test.src" ) + "/property-java.security" , null ,
177+ "Constraints of provider not previously specified cannot be modified" , 1 },
178+
179+ // 1 - The profile in propertyListB-java.security extends the profile
180+ // in propertyListA-java.security, which in turn extends the main
181+ // java.security profile, but propertyListB-java.security file is missing.
182+ {"Test-Profile-Property-List.B" ,
183+ null , System .getProperty ("test.src" ) + "/propertyListB-java.security" ,
184+ "is not present in the java.security file or any appended files" , 1 }
185+ // 2 - The -Djava.security.propertiesList option does not support using
186+ // a leading '=' prefix.
187+ // {"Test-Profile-Property-List.A",
188+ // null, "=" + System.getProperty("test.src") + "/propertyListA-java.security",
189+ // "java.security.propertiesList does not support '=' prefix", 1}
175190 });
176191 }
177192
178193 @ Test
179194 public void shouldContainExpectedExitValue () throws Throwable {
180- OutputAnalyzer outputAnalyzer = ProcessTools .executeTestJvm (
181- "-cp" , System .getProperty ("test.classes" ),
182- "-Dsemeru.fips=true" ,
183- "-Dsemeru.customprofile=" + customprofile ,
184- "-Djava.security.properties=" + securityPropertyFile ,
185- "TestProperties" );
195+ List <String > args = new ArrayList <>();
196+
197+ args .add ("-cp" );
198+ args .add (System .getProperty ("test.classes" ));
199+ args .add ("-Dsemeru.fips=true" );
200+ args .add ("-Dsemeru.customprofile=" + customprofile );
201+ if (securityPropertyFile != null ) {
202+ args .add ("-Djava.security.properties=" + securityPropertyFile );
203+ }
204+ if (securityPropertyFileList != null ) {
205+ args .add ("-Djava.security.propertiesList=" + securityPropertyFileList );
206+ }
207+ args .add ("TestProperties" );
208+
209+ OutputAnalyzer outputAnalyzer = ProcessTools .executeTestJvm (args .toArray (new String [0 ]));
186210 outputAnalyzer .reportDiagnosticSummary ();
187211 outputAnalyzer .shouldHaveExitValue (expectedExitValue ).shouldMatch (expected );
188212 }
0 commit comments