You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by "alberto-art3ch (via GitHub)" <gi...@apache.org> on 2024/06/11 06:10:56 UTC

[PR] FINERACT-2096: Fix Failed exception handling with Idempotency key length [fineract]

alberto-art3ch opened a new pull request, #3926:
URL: https://github.com/apache/fineract/pull/3926

   ## Description
   
   Seems when too long idempotency id was added, HTTP 403 was raised, but the name and message is weird. Check and fix it
   
   [FINERACT-2096](https://issues.apache.org/jira/browse/FINERACT-2096)
   
   
   ## Checklist
   
   Please make sure these boxes are checked before submitting your pull request - thanks!
   
   - [ ] Write the commit message as per https://github.com/apache/fineract/#pull-requests
   
   - [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
   
   - [ ] Create/update unit or integration tests for verifying the changes made.
   
   - [ ] Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.
   
   - [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
   
   - [ ] Submission is not a "code dump".  (Large changes can be made "in repository" via a branch.  Ask on the developer mailing list for guidance, if required.)
   
   FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2096: Fix Failed exception handling with Idempotency key length [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #3926:
URL: https://github.com/apache/fineract/pull/3926#discussion_r1636092674


##########
fineract-provider/src/test/java/org/apache/fineract/commands/service/SynchronousCommandProcessingServiceTest.java:
##########
@@ -185,4 +185,45 @@ public void publishHookEventHandlesInvalidJson() {
             underTest.publishHookEvent(entityName, actionName, command, Object.class);
         });
     }
+
+    @Test
+    public void testIdempotentKeyMaxLength() {
+        CommandWrapper commandWrapper = Mockito.mock(CommandWrapper.class);
+        when(commandWrapper.isDatatableResource()).thenReturn(false);
+        when(commandWrapper.isNoteResource()).thenReturn(false);
+        when(commandWrapper.isSurveyResource()).thenReturn(false);
+        when(commandWrapper.isLoanDisburseDetailResource()).thenReturn(false);
+        JsonCommand jsonCommand = Mockito.mock(JsonCommand.class);
+        Long commandId = jsonCommand.commandId();
+
+        NewCommandSourceHandler commandHandler = Mockito.mock(NewCommandSourceHandler.class);
+        CommandProcessingResult commandProcessingResult = Mockito.mock(CommandProcessingResult.class);
+        CommandSource commandSource = Mockito.mock(CommandSource.class);
+        when(commandProcessingResult.isRollbackTransaction()).thenReturn(false);
+        RuntimeException runtimeException = new RuntimeException("foo");
+        when(commandHandler.processCommand(jsonCommand)).thenThrow(runtimeException);
+        when(commandHandlerProvider.getHandler(Mockito.any(), Mockito.any())).thenReturn(commandHandler);
+
+        when(configurationDomainService.isMakerCheckerEnabledForTask(Mockito.any())).thenReturn(false);
+        final String idk = "i".repeat(60);
+        when(idempotencyKeyResolver.resolve(commandWrapper)).thenReturn(idk);
+        when(commandSourceService.findCommandSource(commandWrapper, idk)).thenReturn(null);
+        when(commandSourceService.getCommandSource(commandId)).thenReturn(commandSource);
+        when(commandSource.getIdempotencyKey()).thenReturn(idk);
+
+        AppUser appUser = Mockito.mock(AppUser.class);
+        when(context.authenticatedUser(Mockito.any(CommandWrapper.class))).thenReturn(appUser);
+        when(commandSourceService.saveInitialNewTransaction(commandWrapper, jsonCommand, appUser, idk)).thenReturn(commandSource);
+
+        CommandSource initialCommandSource = Mockito.mock(CommandSource.class);
+        when(commandSourceService.findCommandSource(commandWrapper, idk)).thenReturn(initialCommandSource);
+
+        when(commandSourceService.processCommand(commandHandler, jsonCommand, commandSource, appUser, false, false))
+                .thenThrow(runtimeException);
+
+        assertThrows(RuntimeException.class, () -> {

Review Comment:
   Please check the thrown error whether it has the right title, error code and error message



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2096: Fix Failed exception handling with Idempotency key length [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #3926:
URL: https://github.com/apache/fineract/pull/3926#discussion_r1635307544


##########
fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java:
##########
@@ -102,6 +103,11 @@ public CommandProcessingResult executeCommand(final CommandWrapper wrapper, fina
         } else {
             idempotencyKey = idempotencyKeyResolver.resolve(wrapper);
         }
+        // Idempotency key lebgth validation
+        if (!StringUtils.isEmpty(idempotencyKey) && idempotencyKey.length() > 50) {

Review Comment:
   You misunderstood me. I dont want you to check the length of the idempotency field. It will automatically throw a database error which will be translated to a domain rule exception. I would like you to debug out why wrong exception title and message was generated and fix it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2096: Fix Failed exception handling with Idempotency key length [fineract]

Posted by "alberto-art3ch (via GitHub)" <gi...@apache.org>.
alberto-art3ch commented on code in PR #3926:
URL: https://github.com/apache/fineract/pull/3926#discussion_r1635299487


##########
fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java:
##########
@@ -102,6 +103,11 @@ public CommandProcessingResult executeCommand(final CommandWrapper wrapper, fina
         } else {
             idempotencyKey = idempotencyKeyResolver.resolve(wrapper);
         }
+        // Idempotency key lebgth validation

Review Comment:
   Done!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2096: Fix Failed exception handling with Idempotency key length [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #3926:
URL: https://github.com/apache/fineract/pull/3926#discussion_r1635254306


##########
fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java:
##########
@@ -102,6 +103,11 @@ public CommandProcessingResult executeCommand(final CommandWrapper wrapper, fina
         } else {
             idempotencyKey = idempotencyKeyResolver.resolve(wrapper);
         }
+        // Idempotency key lebgth validation
+        if (!StringUtils.isEmpty(idempotencyKey) && idempotencyKey.length() > 50) {

Review Comment:
   This seems not right. If the idempotency key is too long, we should have a domain rule exception (HTTP 403) that describes the issue. The issue was when it happened the error message title and message was incorrect.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2096: Fix Failed exception handling with Idempotency key length [fineract]

Posted by "alberto-art3ch (via GitHub)" <gi...@apache.org>.
alberto-art3ch closed pull request #3926: FINERACT-2096: Fix Failed exception handling with Idempotency key length
URL: https://github.com/apache/fineract/pull/3926


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2096: Fix Failed exception handling with Idempotency key length [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #3926:
URL: https://github.com/apache/fineract/pull/3926#discussion_r1635251820


##########
fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java:
##########
@@ -102,6 +103,11 @@ public CommandProcessingResult executeCommand(final CommandWrapper wrapper, fina
         } else {
             idempotencyKey = idempotencyKeyResolver.resolve(wrapper);
         }
+        // Idempotency key lebgth validation

Review Comment:
   Please fix the typo in the comment



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2096: Fix Failed exception handling with Idempotency key length [fineract]

Posted by "alberto-art3ch (via GitHub)" <gi...@apache.org>.
alberto-art3ch commented on code in PR #3926:
URL: https://github.com/apache/fineract/pull/3926#discussion_r1635299863


##########
fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java:
##########
@@ -102,6 +103,11 @@ public CommandProcessingResult executeCommand(final CommandWrapper wrapper, fina
         } else {
             idempotencyKey = idempotencyKeyResolver.resolve(wrapper);
         }
+        // Idempotency key lebgth validation
+        if (!StringUtils.isEmpty(idempotencyKey) && idempotencyKey.length() > 50) {

Review Comment:
   Done! Exception updated to be as Domain rule exception



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org