Skip to content

Commit

Permalink
Update the test case for Restricted Security Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
taoliult committed Sep 26, 2024
1 parent 764b725 commit b5b5274
Show file tree
Hide file tree
Showing 2 changed files with 1,732 additions and 0 deletions.
86 changes: 86 additions & 0 deletions test/jdk/openj9/internal/security/TestProviderOrder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* ===========================================================================
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
* ===========================================================================
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* IBM designates this particular file as subject to the "Classpath" exception
* as provided by IBM in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, see <http://www.gnu.org/licenses/>.
*
* ===========================================================================
*/

/*
* @test
* @summary Test Provider Order
* @library /test/lib
* @run junit TestProviderOrder
*/

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.security.Provider;
import java.security.Security;

import java.util.stream.Stream;

import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

public class TestProviderOrder {

private static Stream<Arguments> patternMatches() {
return Stream.of(
// Test case 1
Arguments.of("Test-Profile-1",
System.getProperty("test.src") + "/java.security",
"Provider"),
// Test case 2
Arguments.of("OpenJCEPlusFIPS.FIPS140-3-Weakly-Enforced",
System.getProperty("test.src") + "/java.security",
"Provider")
// Test case 3 ...
);
}

@ParameterizedTest
@MethodSource("patternMatches")
public void shouldContain(String customprofile, String securityPropertyFile, String expected) throws Exception {
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJava(
"-Dsemeru.fips=true",
"-Dsemeru.customprofile=" + customprofile,
"-Djava.security.properties=" + securityPropertyFile,
"-Djava.security.debug=semerufips",
"TestProviderOrder"
);
outputAnalyzer.reportDiagnosticSummary();
//outputAnalyzer.shouldHaveExitValue(0).shouldContain(expected);
}

public static void main(String[] args) throws Exception {
// Something to trigger restrictedSecurity mode initialization
try {
Provider p[] = Security.getProviders();
for (int i = 0; i < p.length; i++) {
System.out.println("Provider Name: " + p[i].getName());
System.out.println("Provider Version: " + p[i].getVersion());
}
} catch (Exception e) {
System.out.println(e);
}
}
}
Loading

0 comments on commit b5b5274

Please sign in to comment.