Skip to content

Commit

Permalink
Verify requestid in StartWorkflowExecutionRequest (cadence-workflow#1719
Browse files Browse the repository at this point in the history
)

* verify request id exists

* add unit tests

* add unit tests

* add unit tests
  • Loading branch information
lihannan99 authored Apr 18, 2019
1 parent 22eac4d commit c319f27
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions service/history/historyEngine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,9 @@ func validateStartChildExecutionAttributes(parentInfo *persistence.WorkflowExecu
}

func validateStartWorkflowExecutionRequest(request *workflow.StartWorkflowExecutionRequest, maxIDLengthLimit int) error {
if len(request.GetRequestId()) == 0 {
return &workflow.BadRequestError{Message: "Missing request ID."}
}
if request.ExecutionStartToCloseTimeoutSeconds == nil || request.GetExecutionStartToCloseTimeoutSeconds() <= 0 {
return &workflow.BadRequestError{Message: "Missing or invalid ExecutionStartToCloseTimeoutSeconds."}
}
Expand Down
9 changes: 8 additions & 1 deletion service/history/historyEngine2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os"
"testing"

"github.com/pborman/uuid"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -1033,7 +1034,7 @@ func (s *engine2Suite) TestStartWorkflowExecution_BrandNew() {
},
nil,
)

requestID := uuid.New()
resp, err := s.historyEngine.StartWorkflowExecution(context.Background(), &h.StartWorkflowExecutionRequest{
DomainUUID: common.StringPtr(domainID),
StartRequest: &workflow.StartWorkflowExecutionRequest{
Expand All @@ -1044,6 +1045,7 @@ func (s *engine2Suite) TestStartWorkflowExecution_BrandNew() {
ExecutionStartToCloseTimeoutSeconds: common.Int32Ptr(1),
TaskStartToCloseTimeoutSeconds: common.Int32Ptr(2),
Identity: common.StringPtr(identity),
RequestId: common.StringPtr(requestID),
},
})
s.Nil(err)
Expand Down Expand Up @@ -1404,6 +1406,8 @@ func (s *engine2Suite) TestSignalWithStartWorkflowExecution_WorkflowNotExist() {
identity := "testIdentity"
signalName := "my signal name"
input := []byte("test input")
requestID := uuid.New()

sRequest = &h.SignalWithStartWorkflowExecutionRequest{
DomainUUID: common.StringPtr(domainID),
SignalWithStartRequest: &workflow.SignalWithStartWorkflowExecutionRequest{
Expand All @@ -1416,6 +1420,7 @@ func (s *engine2Suite) TestSignalWithStartWorkflowExecution_WorkflowNotExist() {
Identity: common.StringPtr(identity),
SignalName: common.StringPtr(signalName),
Input: input,
RequestId: common.StringPtr(requestID),
},
}

Expand Down Expand Up @@ -1457,6 +1462,7 @@ func (s *engine2Suite) TestSignalWithStartWorkflowExecution_WorkflowNotRunning()
identity := "testIdentity"
signalName := "my signal name"
input := []byte("test input")
requestID := uuid.New()
sRequest = &h.SignalWithStartWorkflowExecutionRequest{
DomainUUID: common.StringPtr(domainID),
SignalWithStartRequest: &workflow.SignalWithStartWorkflowExecutionRequest{
Expand All @@ -1469,6 +1475,7 @@ func (s *engine2Suite) TestSignalWithStartWorkflowExecution_WorkflowNotRunning()
Identity: common.StringPtr(identity),
SignalName: common.StringPtr(signalName),
Input: input,
RequestId: common.StringPtr(requestID),
},
}

Expand Down
6 changes: 5 additions & 1 deletion service/history/historyEngine3_eventsv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package history

import (
"context"
"github.com/pborman/uuid"
"os"
"testing"

Expand Down Expand Up @@ -280,7 +281,7 @@ func (s *engine3Suite) TestStartWorkflowExecution_BrandNew() {
},
nil,
)

requestID := uuid.New()
resp, err := s.historyEngine.StartWorkflowExecution(context.Background(), &h.StartWorkflowExecutionRequest{
DomainUUID: common.StringPtr(domainID),
StartRequest: &workflow.StartWorkflowExecutionRequest{
Expand All @@ -291,6 +292,7 @@ func (s *engine3Suite) TestStartWorkflowExecution_BrandNew() {
ExecutionStartToCloseTimeoutSeconds: common.Int32Ptr(1),
TaskStartToCloseTimeoutSeconds: common.Int32Ptr(2),
Identity: common.StringPtr(identity),
RequestId: common.StringPtr(requestID),
},
})
s.Nil(err)
Expand Down Expand Up @@ -369,6 +371,7 @@ func (s *engine3Suite) TestSignalWithStartWorkflowExecution_WorkflowNotExist() {
identity := "testIdentity"
signalName := "my signal name"
input := []byte("test input")
requestID := uuid.New()
sRequest = &h.SignalWithStartWorkflowExecutionRequest{
DomainUUID: common.StringPtr(domainID),
SignalWithStartRequest: &workflow.SignalWithStartWorkflowExecutionRequest{
Expand All @@ -381,6 +384,7 @@ func (s *engine3Suite) TestSignalWithStartWorkflowExecution_WorkflowNotExist() {
Identity: common.StringPtr(identity),
SignalName: common.StringPtr(signalName),
Input: input,
RequestId: common.StringPtr(requestID),
},
}

Expand Down
16 changes: 16 additions & 0 deletions service/history/historyEngine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,22 @@ func (s *engineSuite) TestRespondDecisionTaskCompletedConflictOnUpdate() {
s.Equal(int32(100), di.DecisionTimeout)
}

func (s *engineSuite) TestValidateSignalRequest() {
workflowType := "testType"
input := []byte("input")
startRequest := &workflow.StartWorkflowExecutionRequest{
WorkflowId: common.StringPtr("ID"),
WorkflowType: &workflow.WorkflowType{Name: &workflowType},
TaskList: &workflow.TaskList{Name: common.StringPtr("taskptr")},
Input: input,
ExecutionStartToCloseTimeoutSeconds: common.Int32Ptr(10),
TaskStartToCloseTimeoutSeconds: common.Int32Ptr(10),
Identity: common.StringPtr("identity"),
}
err := validateStartWorkflowExecutionRequest(startRequest, 999)
s.Error(err, "startRequest doesn't have request id, it should error out")
}

func (s *engineSuite) TestRespondDecisionTaskCompletedMaxAttemptsExceeded() {
domainID := validDomainID
we := workflow.WorkflowExecution{
Expand Down

0 comments on commit c319f27

Please sign in to comment.