-
Notifications
You must be signed in to change notification settings - Fork 32
[INJICERT-1277] Remove cache dependency from mdoc vc issuance #139
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: Piyush7034 <[email protected]>
WalkthroughThis PR removes internal identity/key helper methods and crypto/cache dependencies from the MDoc mock VC issuance plugin and obtains the documentNumber directly from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
mock-certify-plugin/src/main/java/io.mosip.certify.mock.integration/service/MDocMockVCIssuancePlugin.java (2)
77-83: Missing null validation for "sub" key.If
identityDetailsdoes not contain the"sub"key or if the value isnull,documentNumberwill benulland flow through tomockDataForMsoMdoc()without any error. The broadcatch (Exception e)only catchesClassCastExceptionif the value is non-String, not missing/null values.Consider validating the presence of
"sub":🛡️ Proposed fix to add validation
String documentNumber; try { + if (!identityDetails.containsKey("sub") || identityDetails.get("sub") == null) { + log.error("Missing or null 'sub' in identityDetails"); + throw new VCIExchangeException(ErrorConstants.VCI_EXCHANGE_FAILED); + } documentNumber = (String) identityDetails.get("sub"); } catch (Exception e) {
34-64: Remove unused code from cache dependency removal refactoring.This file contains significant dead code from methods that were deleted during cache dependency removal:
- Constants:
AES_CIPHER_FAILED,NO_UNIQUE_ALIAS,USERINFO_CACHE,ACCESS_TOKEN_HASH,CERTIFY_SERVICE_APP_ID- Autowired fields:
cacheManager,keyStore,dbHelper- @value fields:
cacheSecretKeyRefId,aesECBTransformation,secureIndividualId,storeIndividualId- Imports:
OIDCTransaction,KeyStore,KeymanagerConstant,KeyAlias,KeymanagerDBHelper,CacheManager,Cipher,Key,LocalDateTime,ZoneOffsetRemove these declarations and imports to complete the refactoring.
mock-certify-plugin/src/test/java/io/mosip/certify/mock/integration/service/MDocMockVCIssuancePluginTest.java (1)
57-71: Test setup doesn't match production code after refactoring.The test sets
identityDetails.put("accessTokenHash", "tokenHash")at line 62, but the production code now retrievesidentityDetails.get("sub"). Since"sub"is never set,documentNumberwill benullduring the test. The test passes only becauseanyMap()is used in the mock, hiding this mismatch.Update the test to use the correct key:
🐛 Proposed fix
Map<String, Object> identityDetails = new HashMap<>(); - identityDetails.put("accessTokenHash", "tokenHash"); + identityDetails.put("sub", "testDocumentNumber"); when(mdocGenerator.generate(anyMap(), anyString(), anyString())).thenReturn("mockedMdoc");Consider also using argument captors to verify that
mockDataForMsoMdocreceives the expected document number:ArgumentCaptor<Map<String, Object>> mapCaptor = ArgumentCaptor.forClass(Map.class); verify(mdocGenerator).generate(mapCaptor.capture(), eq("holderId"), eq("empty")); assertEquals("testDocumentNumber", mapCaptor.getValue().get("document_number"));
🧹 Nitpick comments (1)
mock-certify-plugin/src/test/java/io/mosip/certify/mock/integration/service/MDocMockVCIssuancePluginTest.java (1)
34-54: Test setup contains unused mocks and field configurations.Several mocks and
ReflectionTestUtils.setFieldcalls correspond to production fields that are now unused:
- Unused mocks:
cacheManager,keyStore,dbHelper,cache,key- Unused field setups:
cacheSecretKeyRefId,aesECBTransformation,storeIndividualId,secureIndividualIdAfter cleaning up the production code, remove these from the test as well to keep the test focused and maintainable.
Signed-off-by: Piyush7034 <[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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
mock-certify-plugin/src/main/java/io.mosip.certify.mock.integration/service/MDocMockVCIssuancePlugin.java (1)
38-43: Add null validation for "sub" key from identityDetails.The code retrieves "sub" from
identityDetailsand casts it to String, butidentityDetails.get("sub")returnsnullif the key is absent—and castingnulltoStringdoes not throw an exception. This results in anulldocumentNumber being passed tomockDataForMsoMdoc()and subsequently tomdocGenerator.generate().The try-catch block only handles ClassCastException (when the value exists but isn't a String); it does not validate the presence of the "sub" key. Other similar plugins in this codebase (MockIdaDataProviderPlugin, MockCSVDataProviderPlugin) explicitly check for null after retrieval. Either validate that "sub" is present/non-null before use, or add an explicit null check after retrieval to match the defensive coding pattern used elsewhere.
🧹 Nitpick comments (2)
mock-certify-plugin/src/test/java/io/mosip/certify/mock/integration/service/MDocMockVCIssuancePluginTest.java (1)
59-64: Make the unsupported-format test independent of identityDetails validation.
If validation of"sub"is ever moved ahead of the format check, this test could fail for the wrong reason. Consider adding"sub"here (or asserting on the error code) to ensure the exception is strictly for unsupported formats.💡 Optional test hardening
Map<String, Object> identityDetails = new HashMap<>(); identityDetails.put("accessTokenHash", "tokenHash"); +identityDetails.put("sub", "12345");mock-certify-plugin/src/main/java/io.mosip.certify.mock.integration/service/MDocMockVCIssuancePlugin.java (1)
64-64: Consider usinglog.debugfor mock data setup message.Since this is a mock plugin, the "Setting up the data for mDoc" message at INFO level may add noise in production logs. DEBUG level would be more appropriate for internal setup messages.
♻️ Suggested change
private Map<String, Object> mockDataForMsoMdoc(String documentNumber) { Map<String, Object> data = new HashMap<>(); - log.info("Setting up the data for mDoc"); + log.debug("Setting up the data for mDoc"); data.put("family_name","Agatha");
Signed-off-by: Piyush7034 <[email protected]>
* [INJICERT-1277] Remove cache dependency from mdoc vc issuance Signed-off-by: Piyush7034 <[email protected]> * [INJICERT-1277] Remove unused injected dependencies Signed-off-by: Piyush7034 <[email protected]> * [INJICERT-1277] Fix nitpick comments Signed-off-by: Piyush7034 <[email protected]> --------- Signed-off-by: Piyush7034 <[email protected]>
…140) * [INJICERT-1277] Remove cache dependency from mdoc vc issuance * [INJICERT-1277] Remove unused injected dependencies * [INJICERT-1277] Fix nitpick comments --------- Signed-off-by: Piyush7034 <[email protected]>
Summary by CodeRabbit
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.