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): Reject invalid wf_run_id in RunWfRequest #1321

Merged
merged 17 commits into from
Feb 25, 2025
Merged
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
@@ -1,5 +1,6 @@
package io.littlehorse.common.model.corecommand.subcommand;

import com.google.common.base.Strings;
import com.google.protobuf.Message;
import io.grpc.Status;
import io.littlehorse.common.LHSerializable;
Expand Down Expand Up @@ -91,8 +92,20 @@ public boolean hasResponse() {
return true;
}

private boolean isIdValid() {
return (!id.equals("") && LHUtil.isValidLHName(id));
}

@Override
public WfRun process(ProcessorExecutionContext processorContext, LHServerConfig config) {
if (Strings.isNullOrEmpty(wfSpecName)) {
throw new LHApiException(Status.INVALID_ARGUMENT, "Missing required argument 'wf_spec_name'");
}

if (id != null && !this.isIdValid()) {
throw new LHApiException(Status.INVALID_ARGUMENT, "Optional argument 'id' must be a valid hostname");
}

GetableManager getableManager = processorContext.getableManager();
WfSpecModel spec = processorContext.service().getWfSpec(wfSpecName, majorVersion, revision);
if (spec == null) {
Expand Down
11 changes: 11 additions & 0 deletions server/src/main/java/io/littlehorse/server/LHServerListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.littlehorse.server;

import com.google.common.base.Strings;
import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;
import com.google.protobuf.Message;
Expand Down Expand Up @@ -591,6 +592,16 @@ public void searchScheduledWfRun(SearchScheduledWfRunRequest req, StreamObserver
@Override
@Authorize(resources = ACLResource.ACL_WORKFLOW, actions = ACLAction.RUN)
public void runWf(RunWfRequest req, StreamObserver<WfRun> ctx) {
if (Strings.isNullOrEmpty(req.getWfSpecName())) {
throw new LHApiException(Status.INVALID_ARGUMENT, "Missing required argument 'wf_spec_name'");
}

if (req.hasId()) {
if (req.getId().equals("") || !LHUtil.isValidLHName(req.getId())) {
throw new LHApiException(Status.INVALID_ARGUMENT, "Optional argument 'id' must be a valid hostname");
}
}

RunWfRequestModel reqModel = LHSerializable.fromProto(req, RunWfRequestModel.class, requestContext());
processCommand(new CommandModel(reqModel), ctx, WfRun.class, true);
}
Expand Down
20 changes: 17 additions & 3 deletions server/src/test/java/e2e/BasicTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package e2e;

import io.littlehorse.sdk.common.config.LHConfig;
import static org.junit.jupiter.api.Assertions.assertThrows;

import io.grpc.Status.Code;
import io.grpc.StatusRuntimeException;
import io.littlehorse.sdk.common.proto.LHStatus;
import io.littlehorse.sdk.common.proto.WfRunId;
import io.littlehorse.sdk.wfsdk.Workflow;
import io.littlehorse.sdk.wfsdk.internal.WorkflowImpl;
import io.littlehorse.sdk.worker.LHTaskMethod;
import io.littlehorse.test.LHTest;
import io.littlehorse.test.LHWorkflow;
import io.littlehorse.test.WithWorkers;
import io.littlehorse.test.WorkflowVerifier;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

@LHTest
Expand All @@ -19,8 +24,6 @@ public class BasicTest {
@LHWorkflow("test-basic")
private Workflow basicWf;

private LHConfig config;

private WorkflowVerifier verifier;

@Test
Expand All @@ -40,6 +43,17 @@ public Workflow getBasic() {
});
}

@Test
public void runWfShouldFailWithInvalidId() {
StatusRuntimeException caught = assertThrows(StatusRuntimeException.class, () -> {
verifier.prepareRun(basicWf)
.waitForStatus(LHStatus.COMPLETED)
.start(WfRunId.newBuilder().setId("my_workflow").build());
});

Assertions.assertThat(caught.getStatus().getCode()).isEqualTo(Code.INVALID_ARGUMENT);
}

public Object basicWorker() {
return new BasicWorker();
}
Expand Down
Loading