Skip to content

Commit 8b658b3

Browse files
Refactor JUnit 5 Tests for BaseTestDSASignatureInterop
Replace multiple test classes extending BaseTestDSASignatureInterop with a single JUnit 5 parameterized test class Signed-off-by: Mohit Rajbhar <mohit.rajbhar@ibm.com>
1 parent 1df365e commit 8b658b3

11 files changed

Lines changed: 145 additions & 109 deletions

src/test/java/ibm/jceplus/junit/TestMultithread.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public class TestMultithread {
3535
"ibm.jceplus.junit.openjceplus.multithread.TestAliases",
3636
"ibm.jceplus.junit.openjceplus.multithread.TestDH",
3737
"ibm.jceplus.junit.openjceplus.multithread.TestDSAKey",
38-
"ibm.jceplus.junit.openjceplus.multithread.TestDSASignatureInteropSUN",
3938
"ibm.jceplus.junit.openjceplus.multithread.TestECDH",
4039
"ibm.jceplus.junit.openjceplus.multithread.TestECDHInteropSunEC",
4140
"ibm.jceplus.junit.openjceplus.multithread.TestEdDSASignature",

src/test/java/ibm/jceplus/junit/TestMultithreadFIPS.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public class TestMultithreadFIPS {
3535
"ibm.jceplus.junit.openjceplusfips.multithread.TestAliases",
3636
"ibm.jceplus.junit.openjceplusfips.multithread.TestDH",
3737
"ibm.jceplus.junit.openjceplusfips.multithread.TestDSAKey",
38-
"ibm.jceplus.junit.openjceplusfips.multithread.TestDSASignatureInteropSUN",
3938
"ibm.jceplus.junit.openjceplusfips.multithread.TestECDH",
4039
"ibm.jceplus.junit.openjceplusfips.multithread.TestECDHInteropSunEC",
4140
"ibm.jceplus.junit.openjceplusfips.multithread.TestHKDF",

src/test/java/ibm/jceplus/junit/openjceplus/TestAll.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
TestDSAKey.class,
4040
TestDSASignature.class,
4141
TestDSASignatureInteropBC.class,
42-
TestDSASignatureInteropSUN.class,
4342
TestECDH.class,
4443
TestECDHInteropBC.class,
4544
TestECDHInteropSunEC.class,

src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignatureInteropSUN.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDSASignatureInteropSUN.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSASignatureInteropSUN.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDSASignatureInteropSUN.java

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright IBM Corp. 2023, 2026
3+
*
4+
* This code is free software; you can redistribute it and/or modify it
5+
* under the terms provided by IBM in the LICENSE file that accompanied
6+
* this code, including the "Classpath" Exception described therein.
7+
*/
8+
9+
package ibm.jceplus.junit.tests;
10+
11+
public class BaseTestInterop extends BaseTest {
12+
13+
public String interopProviderName;
14+
public String interopProviderName2;
15+
16+
/**
17+
* Sets the provider name to interop with.
18+
*
19+
* @param providerName the provider name associated with this test case for use.
20+
*/
21+
public void setInteropProviderName(String providerName) {
22+
this.interopProviderName = providerName;
23+
}
24+
25+
/**
26+
* Gets the provider name that is to be used for interop.
27+
*
28+
* @return The provider name associated with the interop provider name.
29+
*/
30+
public String getInteropProviderName() {
31+
return this.interopProviderName;
32+
}
33+
34+
/**
35+
* Sets the provider name to interop with.
36+
*
37+
* @param providerName the provider name associated with this test case for use.
38+
*/
39+
public void setInteropProviderName2(String providerName) {
40+
this.interopProviderName2 = providerName;
41+
}
42+
43+
/**
44+
* Gets the provider name that is to be used for interop.
45+
*
46+
* @return The provider name associated with the interop provider name.
47+
*/
48+
public String getInteropProviderName2() {
49+
return this.interopProviderName2;
50+
}
51+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright IBM Corp. 2023, 2026
3+
*
4+
* This code is free software; you can redistribute it and/or modify it
5+
* under the terms provided by IBM in the LICENSE file that accompanied
6+
* this code, including the "Classpath" Exception described therein.
7+
*/
8+
9+
package ibm.jceplus.junit.tests;
10+
11+
import java.security.PrivateKey;
12+
import java.security.PublicKey;
13+
import java.security.Signature;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
16+
public class BaseTestSignatureInterop extends BaseTestInterop {
17+
18+
protected void doSignVerify(String sigAlgo, byte[] message, PrivateKey privateKey,
19+
PublicKey publicKey) throws Exception {
20+
doSignVerify(sigAlgo, message, privateKey, publicKey, getProviderName(), getInteropProviderName());
21+
doSignVerify(sigAlgo, message, privateKey, publicKey, getInteropProviderName(), getProviderName());
22+
}
23+
24+
25+
protected static void doSignVerify(String sigAlgo, byte[] message, PrivateKey privateKey,
26+
PublicKey publicKey, String signProvider, String verifyProvider) throws Exception {
27+
Signature signing = Signature.getInstance(sigAlgo, signProvider);
28+
signing.initSign(privateKey);
29+
signing.update(message);
30+
byte[] signedBytes = signing.sign();
31+
32+
Signature verifying = Signature.getInstance(sigAlgo, verifyProvider);
33+
verifying.initVerify(publicKey);
34+
verifying.update(message);
35+
36+
assertTrue(verifying.verify(signedBytes), "Signature verification failed");
37+
}
38+
}
39+

src/test/java/ibm/jceplus/junit/tests/TestArguments.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ public static Stream<Arguments> rsaMultithreadKeySizesAndProviders() {
4848
return keySizesAndJCEPlusProviders(rsaKeySizes);
4949
}
5050

51+
/**
52+
* Generates combinations of OpenJCEPlus* providers with the SUN provider for interoperability testing.
53+
*
54+
* @return Stream of Arguments containing (JCEProviders, SUN) pairs
55+
*/
56+
public static Stream<Arguments> getOpenJCEPlusWithSUNInteropProvider() {
57+
return getOpenJCEPlusWithInteropProviders(TestProvider.SUN);
58+
}
59+
5160
/**
5261
* Generates combinations of all key sizes and OpenJCEPlus* providers under test.
5362
*
@@ -101,5 +110,23 @@ protected static Stream<TestProvider> getEnabledProviders() {
101110
}
102111
}
103112
return enabledProviders.stream();
104-
}
113+
}
114+
115+
/**
116+
* Generates combinations of OpenJCEPlus* providers with a specified interoperability provider for testing.
117+
*
118+
* @param interopProvider The interoperability provider to combine with OpenJCEPlus* providers
119+
* @return Stream of Arguments containing (JCEProviders, interopProvider) pairs
120+
*/
121+
protected static Stream<Arguments> getOpenJCEPlusWithInteropProviders(TestProvider interopProvider) {
122+
List<TestProvider> enabledProviders = getEnabledProviders().toList();
123+
124+
List<Arguments> arguments = new ArrayList<>();
125+
for (TestProvider jceProvider : enabledProviders) {
126+
arguments.add(Arguments.of(jceProvider, interopProvider));
127+
}
128+
129+
return arguments.stream();
130+
}
131+
105132
}

0 commit comments

Comments
 (0)