-
Notifications
You must be signed in to change notification settings - Fork 80
MOSIP-30573: test case for pkcs11 file #475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: nagendra0721 <[email protected]>
Signed-off-by: nagendra0721 <[email protected]>
WalkthroughAdded a test-only dependency and three new comprehensive test classes (PKCS11KeyStoreImplTest, OLKeyStoreImplTest, PartnerCertManagerControllerTest update) exercising keystore providers, key/certificate operations, error paths, and provider stubbing; plus a small test-data change in PartnerCertManagerControllerTest. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (4)
kernel/kernel-keymanager-service/src/test/java/io/mosip/kernel/keymanager/hsm/test/PKCS11KeyStoreImplTest.java (3)
87-107: Consider thread-safety implications of Security provider manipulation.The test modifies the global Security provider registry (lines 89-90, 104), which could cause issues if tests run in parallel. While the tearDown method properly cleans up, any test failure that prevents tearDown execution could affect subsequent tests.
Consider documenting that these tests should run serially, or explore using JUnit 5's
@Execution(ExecutionMode.SAME_THREAD)annotation if upgrading from JUnit 4.
550-862: Reduce visibility of nested test helper classes.All nested helper classes (TestProvider, NoSecureRandomProvider, FaultyProvider, TestKeyStoreSpi, TestRSAKeyPairGeneratorSpi, TestECKeyPairGeneratorSpi, TestAesKeyGeneratorSpi, TestSecureRandomSpi) are declared as
public static. Since these classes are only used within this test file, they should use package-private (default) visibility to avoid unnecessary exposure.Apply this pattern to all nested classes:
- public static class TestProvider extends Provider { + static class TestProvider extends Provider {
234-241: Heavy reflection usage creates brittle tests.The tests extensively use
ReflectionTestUtilsto access and manipulate private fields and methods of PKCS11KeyStoreImpl. While this provides thorough coverage of internal behavior, it tightly couples tests to implementation details, making them fragile during refactoring.Consider balancing coverage with maintainability:
- Focus on testing public API behavior where possible
- Reserve reflection-based tests for critical internal logic that must be verified
- Document why reflection is necessary in complex test cases
Also applies to: 248-253, 267-268, 276-278, 286-288, 296-297, 313-314, 331-332, 348-349, 365-366, 374-375, 380-388, 393-402, 407-425, 430-439, 444-461, 470-471, 480-481, 489-490
kernel/kernel-keymanager-service/pom.xml (1)
149-154: Consider upgrading to Mockito 5.x to simplify dependencies.Mockito 5.20.0 (latest stable, Sep 2025) includes inline mocking by default out of the box, making the separate mockito-inline artifact unnecessary. The project currently uses Mockito 3.4.3 from 2020, so upgrading would eliminate the redundant dependency and modernize the codebase. However, this is a major version bump and requires verification of breaking changes and compatibility with existing tests before proceeding.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
kernel/kernel-keymanager-service/pom.xml(1 hunks)kernel/kernel-keymanager-service/src/test/java/io/mosip/kernel/keymanager/hsm/test/PKCS11KeyStoreImplTest.java(1 hunks)kernel/kernel-keymanager-service/src/test/java/io/mosip/kernel/partnercertservice/test/controller/PartnerCertManagerControllerTest.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
kernel/kernel-keymanager-service/src/test/java/io/mosip/kernel/keymanager/hsm/test/PKCS11KeyStoreImplTest.java (2)
kernel/kernel-keymanager-service/src/main/java/io/mosip/kernel/keymanager/hsm/impl/pkcs/PKCS11KeyStoreImpl.java (1)
PKCS11KeyStoreImpl(62-656)kernel/kernel-keymanager-service/src/main/java/io/mosip/kernel/keymanager/hsm/util/CertificateUtility.java (1)
CertificateUtility(46-289)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build-kernel / maven-build
🔇 Additional comments (3)
kernel/kernel-keymanager-service/src/test/java/io/mosip/kernel/partnercertservice/test/controller/PartnerCertManagerControllerTest.java (1)
531-531: LGTM! Test data now consistent with certificate content.The organizationName change from "IITB" to "Mosip" aligns with the certificate's organization field and matches the usage pattern in other tests (e.g., Line 259).
kernel/kernel-keymanager-service/src/test/java/io/mosip/kernel/keymanager/hsm/test/PKCS11KeyStoreImplTest.java (2)
549-550: Deprecated Provider constructor usage is acceptable for test purposes.The nested provider classes use the deprecated
Provider(String, double, String)constructor (lines 554, 578, 600), which is suppressed via@SuppressWarnings("deprecation"). This is acceptable for test scaffolding where the deprecated API provides the simplest way to create custom providers.Also applies to: 573-575, 595-597
117-491: Excellent test coverage and structure.The test suite provides comprehensive coverage of PKCS11KeyStoreImpl functionality, including:
- Key generation and storage (RSA, EC, symmetric)
- Key retrieval and caching
- Certificate handling
- Provider reload logic
- Error scenarios and exception handling
- Edge cases (blank passwords, missing providers, etc.)
The test naming convention ("should...") and use of helper methods enhance readability and maintainability.
...anager-service/src/test/java/io/mosip/kernel/keymanager/hsm/test/PKCS11KeyStoreImplTest.java
Show resolved
Hide resolved
Signed-off-by: nagendra0721 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
kernel/kernel-keymanager-service/src/test/java/io/mosip/kernel/keymanager/hsm/test/OLKeyStoreImplTest.java (2)
37-56: SpringRunner + plain@Mockfields add complexity without clear benefitYou’re using
@RunWith(SpringRunner.class)and@Mockfields, but there’s no Spring test config (@SpringBootTest,@ContextConfiguration,@MockBean, etc.) and no Mockito initialization (MockitoJUnitRunner,MockitoRule,MockitoAnnotations.initMocks(this)). In this setup the@Mockfields are likely justnull, and OLKeyStoreImpl ignores them anyway (it always throws), so the annotations and custom runner don’t buy much.Consider simplifying by either:
- Dropping SpringRunner and initializing Mockito properly, or
- Dropping the
@Mockannotations (passingnullis enough here since args are unused), and using the default JUnit runner.This will make the tests’ intent and dependencies clearer.
58-71: Constructor tests currently use tautological assertions
assertThat(instance, is(instance));will always pass and doesn’t verify anything beyond “constructor did not throw” (which JUnit already guarantees if the test completes). If you want a stronger check, you could assert something meaningful (e.g., non-null instance or a specific property), or simply omit the assertion and rely on the absence of exceptions.This is purely a readability/clarity tweak; behavior is correct as-is.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
kernel/kernel-keymanager-service/src/test/java/io/mosip/kernel/keymanager/hsm/test/OLKeyStoreImplTest.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
kernel/kernel-keymanager-service/src/test/java/io/mosip/kernel/keymanager/hsm/test/OLKeyStoreImplTest.java (1)
kernel/kernel-keymanager-service/src/main/java/io/mosip/kernel/keymanager/hsm/impl/offline/OLKeyStoreImpl.java (1)
OLKeyStoreImpl(28-176)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build-kernel / maven-build
🔇 Additional comments (1)
kernel/kernel-keymanager-service/src/test/java/io/mosip/kernel/keymanager/hsm/test/OLKeyStoreImplTest.java (1)
73-299: Offline keystore exception behavior is well covered and matches OLKeyStoreImplAll the operation tests (
getAllAlias,getKey,getAsymmetricKey,getPrivateKey,getPublicKey,getCertificate,getSymmetricKey,deleteKey,generateAndStoreAsymmetricKey(both overloads),generateAndStoreSymmetricKey,storeCertificate) correctly expectKeystoreProcessingExceptionand, in the detail tests, asserterrorCodeanderrorTextagainstKeymanagerErrorCode.OFFLINE_KEYSTORE_ACCESS_ERROR. This aligns with the production implementation inOLKeyStoreImpl(kernel-keymanager-service/src/main/java/io/mosip/kernel/keymanager/hsm/impl/offline/OLKeyStoreImpl.java, lines 27–175), which always throws that error for these methods and returnsKEYSTORE_TYPE_OFFLINEfor the provider name.The coverage across normal and parameter edge cases (null aliases/params, EC curve overload) looks consistent and should guard against regressions in the offline keystore behavior.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.