Skip to content
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

fix(server): Validate null on UserTaskRun arrival for userId and userGroup #1333

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading