Skip to content

Refactor JUnit 5 tests consolidate BaseTestRSA#1194

Open
Mohit-Rajbhar100698 wants to merge 1 commit intoIBM:mainfrom
Mohit-Rajbhar100698:mohit-rajbhar/junit5-BaseTestRSA-consolidation
Open

Refactor JUnit 5 tests consolidate BaseTestRSA#1194
Mohit-Rajbhar100698 wants to merge 1 commit intoIBM:mainfrom
Mohit-Rajbhar100698:mohit-rajbhar/junit5-BaseTestRSA-consolidation

Conversation

@Mohit-Rajbhar100698
Copy link
Collaborator

This change consolidates various tests associated with the former BaseTestRSA into a single parameterized test.

Signed-off-by: Mohit Rajbhar mohit.rajbhar@ibm.com

@jasonkatonica
Copy link
Member

We did talk about this update some and found the runtimes for the test buckets increased by ~4x. Some additional work here to only run 2048 base keys for multi-thread is being tried.

@Mohit-Rajbhar100698 Mohit-Rajbhar100698 force-pushed the mohit-rajbhar/junit5-BaseTestRSA-consolidation branch from ea991d6 to 22b8ad7 Compare February 24, 2026 05:45
This change consolidates various tests associated with the former BaseTestRSA into a single parameterized test.

Fixes: https://github.ibm.com/runtimes/jit-crypto/issues/1063

Signed-off-by: Mohit Rajbhar <mohit.rajbhar@ibm.com>
@Mohit-Rajbhar100698 Mohit-Rajbhar100698 force-pushed the mohit-rajbhar/junit5-BaseTestRSA-consolidation branch from 22b8ad7 to 87c6137 Compare February 24, 2026 11:00
@Mohit-Rajbhar100698
Copy link
Collaborator Author

Since a @MethodSource cannot be overridden using inheritance, we cannot simply extend TestRSA and change the method source to run only the 2048 key size. I created two separate test classes. One class runs all RSA key sizes except 2048, and the other class runs only the 2048 key size for multithread testing. Both classes extend the same base test class (TestRSA), which contains all the common setup and tests.

import static org.junit.jupiter.api.Assumptions.assumeTrue;

public class BaseTestRSA extends BaseTestCipher {
public abstract class TestRSA extends BaseTestCipher {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an abstract class and we expect other classes to extend it can we keep the naming convention of BaseTestRSA for this class?

Comment on lines +17 to +24
@Tag(Tags.OPENJCEPLUS_NAME)
@Tag(Tags.OPENJCEPLUS_FIPS_NAME)
@Tag(Tags.OPENJCEPLUS_MULTITHREAD_NAME)
@Tag(Tags.OPENJCEPLUS_FIPS_MULTITHREAD_NAME)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ParameterizedClass
@MethodSource("ibm.jceplus.junit.tests.TestArguments#rsaKeySize2048AndJCEPlusProviders")
public class TestRSA_2048 extends TestRSA {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is intended to only run multhreaded given that it only ( for now to match past behavior ) runs 2048 sized keys. I believe we want to remove these tags from the test so it is not run for our regular openjceplus and openjceplusfips test suites:

@Tag(Tags.OPENJCEPLUS_NAME)
@Tag(Tags.OPENJCEPLUS_FIPS_NAME)

And also rename the test to something like TestRSAMultiThread since this is a multithreaded specific test. I dont think we need to put the keysize in the test name given we may want to in the future add more key sizes to the parameters of this test.

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ParameterizedClass
@MethodSource("ibm.jceplus.junit.tests.TestArguments#rsaKeySizesAndJCEPlusProviders")
public class TestRSA_Non2048 extends TestRSA {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests tags seem correct. We do however want to run all the available key sizes for RSA in the test so it runs as part of the openjceplus or openjceplusfips test suites. The class can also be simply named TestRSA.

Comment on lines +82 to +94
if (keySize == 512) {
specifiedKeySize = 512;
} else if (keySize == 1024) {
specifiedKeySize = 1024;
} else if (keySize == 2048) {
specifiedKeySize = 2048;
} else if (keySize == 3072) {
specifiedKeySize = 3072;
} else if (keySize == 4096) {
specifiedKeySize = 4096;
} else {
throw new Exception("Illegal key size in BaseTestRSA.");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we eliminate the specifiedKeySize variable here and just make use of keySize in the test?

Comment on lines +53 to +55
protected abstract int getInputKeySize();

protected abstract TestProvider getInputProvider();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these abstract methods required? Can we simply just use the keySize and provider that is set by the parameterized classes that extend this abstract class?


fail("RSA " + keySize + " worked unexpectedly in FIPS mode");
} catch (InvalidParameterException e) {
assertEquals("RSA keys must be at least 2048 bits long", e.getMessage());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ensure that we get this error message only on RSA key sizes that are expected to fail.

if (keySize < 2048) {
assertEquals("RSA keys must be at least 2048 bits long", e.getMessage());
} else {
throw e;
}

assertEquals("RSA keys must be at least 2048 bits long", e.getMessage());
}

assumeTrue(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we already handle the expected behavior above in the try catch block ? Above we are asserting expected behavior and not sure why we turn around here and skip the test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants