Skip to content

Commit 18503e2

Browse files
committed
Add the test cases for Restricted Security Mode
Add the test cases for Restricted Security Mode, to cover the restricted security mode providers and properties related scenarios. Signed-off-by: Tao Liu <[email protected]>
1 parent 9999ba0 commit 18503e2

File tree

5 files changed

+1106
-0
lines changed

5 files changed

+1106
-0
lines changed

closed/test/jdk/TEST.ROOT

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ===========================================================================
2+
# (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
3+
# ===========================================================================
4+
# This code is free software; you can redistribute it and/or modify it
5+
# under the terms of the GNU General Public License version 2 only, as
6+
# published by the Free Software Foundation.
7+
#
8+
# IBM designates this particular file as subject to the "Classpath" exception
9+
# as provided by IBM in the LICENSE file that accompanied this code.
10+
#
11+
# This code is distributed in the hope that it will be useful, but WITHOUT
12+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
# version 2 for more details (a copy is included in the LICENSE file that
15+
# accompanied this code).
16+
#
17+
# You should have received a copy of the GNU General Public License version
18+
# 2 along with this work; if not, see <http://www.gnu.org/licenses/>.
19+
# ===========================================================================
20+
21+
# Path to libraries in the topmost test directory. This is needed so @library
22+
# does not need ../../../ notation to reach them.
23+
external.lib.roots = ../../../
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*
2+
* ===========================================================================
3+
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
4+
* ===========================================================================
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* IBM designates this particular file as subject to the "Classpath" exception
11+
* as provided by IBM in the LICENSE file that accompanied this code.
12+
*
13+
* This code is distributed in the hope that it will be useful, but WITHOUT
14+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16+
* version 2 for more details (a copy is included in the LICENSE file that
17+
* accompanied this code).
18+
*
19+
* You should have received a copy of the GNU General Public License version
20+
* 2 along with this work; if not, see <http://www.gnu.org/licenses/>.
21+
*
22+
* ===========================================================================
23+
*/
24+
25+
/*
26+
* @test
27+
* @summary Test Restricted Security Mode Properties
28+
* @library /test/lib
29+
* @run junit TestProperties
30+
*/
31+
32+
import org.junit.jupiter.params.ParameterizedTest;
33+
import org.junit.jupiter.params.provider.Arguments;
34+
import org.junit.jupiter.params.provider.MethodSource;
35+
36+
import java.security.Provider;
37+
import java.security.Security;
38+
39+
import java.util.stream.Stream;
40+
41+
import jdk.test.lib.process.OutputAnalyzer;
42+
import jdk.test.lib.process.ProcessTools;
43+
44+
public class TestProperties {
45+
46+
private static Stream<Arguments> patternMatches_expectedExitValue1() {
47+
return Stream.of(
48+
// 1 - Test profile - base profile misspell properties.
49+
Arguments.of("Test-Profile.Base",
50+
System.getProperty("test.src") + "/property-java.security",
51+
"The property names: RestrictedSecurity.Test-Profile.Base.tls.disabledAlgorithmsWrongTypo "
52+
+ "in profile RestrictedSecurity.Test-Profile.Base \\(or a base profile\\) are not recognized"),
53+
// 2 - Test profile - extenstion profile misspell properties.
54+
Arguments.of("Test-Profile.Extended_1",
55+
System.getProperty("test.src") + "/property-java.security",
56+
"The property names: RestrictedSecurity.Test-Profile.Extended_1.desc.nameWrongTypo, "
57+
+ "RestrictedSecurity.Test-Profile.Extended_1.jce.providerWrongTypo in profile "
58+
+ "RestrictedSecurity.Test-Profile.Extended_1 \\(or a base profile\\) are not recognized"),
59+
// 3 - Test profile - extension profile from another extension profile misspell properties.
60+
Arguments.of("Test-Profile.Extended_2",
61+
System.getProperty("test.src") + "/property-java.security",
62+
"The property names: RestrictedSecurity.Test-Profile.Extended_2.jce.providerWrongTypo "
63+
+ "in profile RestrictedSecurity.Test-Profile.Extended_2 \\(or a base profile\\) are not recognized"),
64+
// 4 - Test profile - profile not exist.
65+
Arguments.of("Test-Profile-NotExist.Base",
66+
System.getProperty("test.src") + "/property-java.security",
67+
"Test-Profile-NotExist.Base is not present in the java.security file."),
68+
// 5 - Test profile - Multi Default profile.
69+
Arguments.of("Test-Profile-MultiDefault",
70+
System.getProperty("test.src") + "/property-java.security",
71+
"Multiple default RestrictedSecurity profiles for Test-Profile-MultiDefault"),
72+
// 6 - Test profile - no default profile.
73+
Arguments.of("Test-Profile-NoDefault",
74+
System.getProperty("test.src") + "/property-java.security",
75+
"No default RestrictedSecurity profile was found for Test-Profile-NoDefault"),
76+
// 7 - Test profile - base profile does not exist.
77+
Arguments.of("Test-Profile.Extended_3",
78+
System.getProperty("test.src") + "/property-java.security",
79+
"RestrictedSecurity.Test-Profile.BaseNotExist that is supposed to extend \\'RestrictedSecurity.Test-Profile.Extended_3\\' "
80+
+ "is not present in the java.security file or any appended files"),
81+
// 8 - Test profile - base profile not full profile name.
82+
Arguments.of("Test-Profile.Extended_4",
83+
System.getProperty("test.src") + "/property-java.security",
84+
"RestrictedSecurity.BaseNotFullProfileName that is supposed to extend \\'RestrictedSecurity.Test-Profile.Extended_4\\' "
85+
+ "is not a full profile name"),
86+
// 9 - Test profile - base profile without hash value.
87+
Arguments.of("Test-Profile-BaseWithoutHash",
88+
System.getProperty("test.src") + "/property-java.security",
89+
"Test-Profile-BaseWithoutHash is a base profile, so a hash value is mandatory"),
90+
// 10 - Test profile - incorrect definition of hash value.
91+
Arguments.of("Test-Profile-Hash_1",
92+
System.getProperty("test.src") + "/property-java.security",
93+
"Incorrect definition of hash value for RestrictedSecurity.Test-Profile-Hash_1"),
94+
// 11 - Test profile - incorrect hash value.
95+
Arguments.of("Test-Profile-Hash_2",
96+
System.getProperty("test.src") + "/property-java.security",
97+
"Hex produced from profile is not the same is a base profile, so a hash value is mandatory"),
98+
// 12 - Test property - property not appendable.
99+
Arguments.of("Test-Profile-SetProperty.Extension_1",
100+
System.getProperty("test.src") + "/property-java.security",
101+
"Property \\'jdkSecureRandomProvider\\' is not appendable"),
102+
// 13 - Test property - property does not exist in parent profile, cannot append.
103+
Arguments.of("Test-Profile-SetProperty.Extension_2",
104+
System.getProperty("test.src") + "/property-java.security",
105+
"Property \\'jdkTlsDisabledNamedCurves\\' does not exist in parent profile or java.security file. Cannot append"),
106+
// 14 - Test property - property value is not in existing values.
107+
Arguments.of("Test-Profile-SetProperty.Extension_3",
108+
System.getProperty("test.src") + "/property-java.security",
109+
"Value \\'TestDisabledlgorithms\\' is not in existing values"),
110+
// 15 - Test property - policy sunset.
111+
Arguments.of("Test-Profile-PolicySunset.Base",
112+
System.getProperty("test.src") + "/property-java.security",
113+
"Restricted security policy expired"),
114+
// 16 - Test property - policy sunset format.
115+
Arguments.of("Test-Profile-PolicySunsetFormat.Base",
116+
System.getProperty("test.src") + "/property-java.security",
117+
"Restricted security policy sunset date is incorrect, the correct format is yyyy-MM-dd"),
118+
// 17 - Test property - secure random check 1.
119+
Arguments.of("Test-Profile-SecureRandomCheck_1",
120+
System.getProperty("test.src") + "/property-java.security",
121+
"Restricted security mode secure random is missing"),
122+
// 18 - Test property - secure random check 2.
123+
Arguments.of("Test-Profile-SecureRandomCheck_2",
124+
System.getProperty("test.src") + "/property-java.security",
125+
"Restricted security mode secure random is missing"),
126+
// 19 - Test constraint - constraint check 1.
127+
Arguments.of("Test-Profile-Constraint_1",
128+
System.getProperty("test.src") + "/property-java.security",
129+
"Provider format is incorrect"),
130+
// 20 - Test constraint - constraint check 2.
131+
Arguments.of("Test-Profile-Constraint_2",
132+
System.getProperty("test.src") + "/property-java.security",
133+
"Incorrect constraint definition for provider"),
134+
// 21 - Test constraint - constraint check 3.
135+
Arguments.of("Test-Profile-Constraint_3",
136+
System.getProperty("test.src") + "/property-java.security",
137+
"Incorrect constraint definition for provider"),
138+
// 22 - Test constraint - constraint attributes check.
139+
Arguments.of("Test-Profile-Constraint_Attributes",
140+
System.getProperty("test.src") + "/property-java.security",
141+
"Constraint attributes format is incorrect"),
142+
// 23 - Test constraint - constraint changed 1.
143+
Arguments.of("Test-Profile-ConstraintChanged_1.Extension",
144+
System.getProperty("test.src") + "/property-java.security",
145+
"Cannot append or remove constraints since the provider (.*?) "
146+
+ "wasn't in this position in the profile extended"),
147+
// 24 - Test constraint - constraint changed 2.
148+
Arguments.of("Test-Profile-ConstraintChanged_2.Extension",
149+
System.getProperty("test.src") + "/property-java.security",
150+
"Constraint (.*?)is not part of existing constraints"),
151+
// 25 - Test constraint - constraint changed 3.
152+
Arguments.of("Test-Profile-ConstraintChanged_3.Base",
153+
System.getProperty("test.src") + "/property-java.security",
154+
"You cannot add or remove to provider (.*?). This is the base profile.")
155+
);
156+
}
157+
158+
@ParameterizedTest
159+
@MethodSource("patternMatches_expectedExitValue1")
160+
public void shouldContain_expectedExitValue1(String customprofile, String securityPropertyFile, String expected) throws Exception {
161+
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJava(
162+
"-Dsemeru.fips=true",
163+
"-Dsemeru.customprofile=" + customprofile,
164+
"-Djava.security.properties=" + securityPropertyFile,
165+
"TestProperties"
166+
);
167+
outputAnalyzer.reportDiagnosticSummary();
168+
outputAnalyzer.shouldHaveExitValue(1).shouldMatch(expected);
169+
}
170+
171+
public static void main(String[] args) {
172+
// Something to trigger "properties" debug output.
173+
try {
174+
for (Provider provider : Security.getProviders()) {
175+
System.out.println("Provider Name: " + provider.getName());
176+
System.out.println("Provider Version: " + provider.getVersionStr());
177+
}
178+
} catch (Exception e) {
179+
System.out.println(e);
180+
}
181+
}
182+
}

0 commit comments

Comments
 (0)