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

IWF-228: returning 400 for missing workflowId #469

Merged
merged 1 commit into from
Oct 28, 2024
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
34 changes: 34 additions & 0 deletions integ/signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/indeedeng/iwf/service"
"github.com/indeedeng/iwf/service/common/ptr"
"github.com/stretchr/testify/assert"
"log"
"net/http"
"strconv"
"testing"
Expand Down Expand Up @@ -39,6 +40,39 @@ func TestSignalWorkflowCadence(t *testing.T) {
}
}

func TestSignalWorkflowNoWorkflowId(t *testing.T) {
assertions := assert.New(t)
_, closeFunc2 := startIwfServiceWithClient(service.BackendTypeTemporal)
defer closeFunc2()

// start a workflow
apiClient := iwfidl.NewAPIClient(&iwfidl.Configuration{
Servers: []iwfidl.ServerConfiguration{
{
URL: "http://localhost:" + testIwfServerPort,
},
},
})
req := apiClient.DefaultApi.ApiV1WorkflowSignalPost(context.Background())
httpResp, err := req.WorkflowSignalRequest(iwfidl.WorkflowSignalRequest{
WorkflowId: "",
SignalChannelName: signal.SignalName,
}).Execute()

assertions.Equal(httpResp.StatusCode, http.StatusBadRequest)

apiErr, ok := err.(*iwfidl.GenericOpenAPIError)
if !ok {
log.Fatalf("Should fail to invoke get api %v", err)
}
errResp, ok := apiErr.Model().(iwfidl.ErrorResponse)
if !ok {
log.Fatalf("should be error response")
}
assertions.Equal(iwfidl.WORKFLOW_NOT_EXISTS_SUB_STATUS, errResp.GetSubStatus())
assertions.Equal("WorkflowId is not set on request.", errResp.GetDetail())
}

func doTestSignalWorkflow(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) {
assertions := assert.New(t)

Expand Down
4 changes: 4 additions & 0 deletions service/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,10 @@ func (s *serviceImpl) handleError(err error, apiPath string, workflowId string)
status = http.StatusBadRequest
subStatus = iwfidl.WORKFLOW_ALREADY_STARTED_SUB_STATUS
}
if workflowId == "" && status == http.StatusInternalServerError {
status = http.StatusBadRequest
subStatus = iwfidl.WORKFLOW_NOT_EXISTS_SUB_STATUS
}
if status >= 500 {
s.logger.Error("encounter server error for API",
tag.StatusCode(status), tag.Error(err),
Expand Down
Loading