Skip to content

Commit

Permalink
Validate null on UserTaskRun arrival for userId and userGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
eduwercamacaro committed Feb 24, 2025
1 parent a0484cf commit 5495500
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ public void onArrival(Date time) throws NodeFailureException {
? null
: thread.assignVariable(node.getUserGroup()).asStr().getStrVal();

if (newUserId == null && newUserGroup == null) {
throw new NodeFailureException(new FailureModel("Invalid user task assignment", LHConstants.VAR_ERROR));
}

// Set owners and schedule all on-assignment hooks
this.assignTo(newUserId, newUserGroup, true);

Expand Down
30 changes: 30 additions & 0 deletions server/src/test/java/e2e/UserTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.littlehorse.common.util.LHUtil;
import io.littlehorse.sdk.common.LHLibUtil;
import io.littlehorse.sdk.common.proto.CompleteUserTaskRunRequest;
import io.littlehorse.sdk.common.proto.Failure;
import io.littlehorse.sdk.common.proto.ListUserTaskRunRequest;
import io.littlehorse.sdk.common.proto.LittleHorseGrpc.LittleHorseBlockingStub;
import io.littlehorse.sdk.common.proto.NodeRun.NodeTypeCase;
Expand Down Expand Up @@ -40,6 +41,7 @@
import io.littlehorse.test.internal.TestExecutionContext;
import io.littlehorse.test.internal.step.SearchResultCaptor;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import org.assertj.core.api.Assertions;
Expand Down Expand Up @@ -71,6 +73,9 @@ public class UserTaskTest {
@LHWorkflow("worker-context-receives-user-details")
private Workflow workerContextReceivesUserDetails;

@LHWorkflow("user-task-assignment")
private Workflow userTaskAssignment;

@LHUserTaskForm(USER_TASK_DEF_NAME)
private MyForm myForm = new MyForm();

Expand Down Expand Up @@ -323,6 +328,22 @@ void shouldScheduleAndExecuteReminderTask() {
.start();
}

@Test
void shouldValidateUserIdOrUserGroup() {
workflowVerifier
.prepareRun(userTaskAssignment)
.waitForStatus(ERROR)
.waitForNodeRunStatus(0, 1, ERROR)
.thenVerifyNodeRun(0, 1, nodeRun -> {
List<Failure> failures = nodeRun.getFailuresList();
Assertions.assertThat(failures).hasSize(1);
Failure nodeFailure = failures.get(0);
Assertions.assertThat(nodeFailure.getFailureName()).isEqualTo("VAR_ERROR");
Assertions.assertThat(nodeFailure.getMessage()).isEqualTo("Invalid user task assignment");
})
.start();
}

@Test
void verifyWorkerContextHasUserIdOrUserGroup() {
workflowVerifier
Expand Down Expand Up @@ -424,6 +445,15 @@ public Workflow buildCancelUserTaskOnReassignmentWorkflow() {
});
}

@LHWorkflow("user-task-assignment")
public Workflow buildUserTaskAssignmentWorkflow() {
return new WorkflowImpl("user-task-assignment", wf -> {
WfRunVariable userId = wf.declareStr("userId");
WfRunVariable userGroup = wf.declareStr("userGroup");
wf.assignUserTask(USER_TASK_DEF_NAME, userId, userGroup);
});
}

@LHTaskMethod("my-custom-task")
public String obiwan(MyForm formData) {
return "String was " + formData.myStr + " and int was " + formData.myInt;
Expand Down

0 comments on commit 5495500

Please sign in to comment.