Skip to content

Commit

Permalink
Fixed issue with nil, and removed more tests of the old version
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobht committed Oct 31, 2024
1 parent e8cda72 commit e30187e
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 405 deletions.
19 changes: 10 additions & 9 deletions common/authorization/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ package authorization

import (
"context"
"encoding/json"
"fmt"
"os"
"reflect"
"strings"

clientworker "go.uber.org/cadence/worker"
Expand Down Expand Up @@ -120,20 +122,19 @@ type simpleRequestLogWrapper struct {
}

func (f *simpleRequestLogWrapper) SerializeForLogging() (string, error) {
return types.SerializeRequest(f.request)
}
if f.request == nil || reflect.ValueOf(f.request).IsNil() {
return "", nil
}

type nullRequestLogWrapper struct{}
res, err := json.Marshal(f.request)
if err != nil {
return "", err
}

func (f *nullRequestLogWrapper) SerializeForLogging() (string, error) {
return "", nil
return string(res), nil
}

func NewFilteredRequestBody(request interface{}) FilteredRequestBody {
if request == nil {
return &nullRequestLogWrapper{}
}

return &simpleRequestLogWrapper{request}
}

Expand Down
87 changes: 87 additions & 0 deletions common/authorization/authorizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/uber/cadence/common/types"

"github.com/uber/cadence/common"
)
Expand Down Expand Up @@ -95,3 +96,89 @@ func Test_validatePermission(t *testing.T) {
})
}
}

func TestSignalWithStartWorkflowExecutionRequestSerializeForLogging(t *testing.T) {
tests := map[string]struct {
input *types.SignalWithStartWorkflowExecutionRequest
expectedOutput string
expectedErrorOutput error
}{
"complete request without error": {
input: createNewSignalWithStartWorkflowExecutionRequest(),
expectedOutput: "{\"domain\":\"testDomain\",\"workflowId\":\"testWorkflowID\",\"workflowType\":{\"name\":\"testWorkflowType\"},\"taskList\":{\"name\":\"testTaskList\",\"kind\":\"STICKY\"},\"executionStartToCloseTimeoutSeconds\":1,\"taskStartToCloseTimeoutSeconds\":1,\"identity\":\"testIdentity\",\"requestId\":\"DF66E35D-A5B0-425D-8731-6AAC4A4B6368\",\"workflowIdReusePolicy\":\"AllowDuplicate\",\"signalName\":\"testRequest\",\"control\":\"dGVzdENvbnRyb2w=\",\"retryPolicy\":{\"initialIntervalInSeconds\":1,\"backoffCoefficient\":1,\"maximumIntervalInSeconds\":1,\"maximumAttempts\":1,\"nonRetriableErrorReasons\":[\"testArray\"],\"expirationIntervalInSeconds\":1},\"cronSchedule\":\"testSchedule\",\"header\":{},\"delayStartSeconds\":1,\"jitterStartSeconds\":1,\"firstRunAtTimestamp\":1}",
expectedErrorOutput: nil,
},

"empty request without error": {
input: &types.SignalWithStartWorkflowExecutionRequest{},
expectedOutput: "{}",
expectedErrorOutput: nil,
},

"nil request without error": {
input: nil,
expectedOutput: "",
expectedErrorOutput: nil,
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
assert.NotPanics(t, func() {
wrappedInput := NewFilteredRequestBody(test.input)
output, err := wrappedInput.SerializeForLogging()
assert.Equal(t, test.expectedOutput, output)
assert.Equal(t, test.expectedErrorOutput, err)
assert.NotContains(t, output, "PII")
})
})
}
}

func createNewSignalWithStartWorkflowExecutionRequest() *types.SignalWithStartWorkflowExecutionRequest {
testTasklistKind := types.TaskListKind(1)
testExecutionStartToCloseTimeoutSeconds := int32(1)
testTaskStartToCloseTimeoutSeconds := int32(1)
testWorkflowIDReusePolicy := types.WorkflowIDReusePolicy(1)
testDelayStartSeconds := int32(1)
testJitterStartSeconds := int32(1)
testFirstRunAtTimestamp := int64(1)
piiTestArray := []byte("testInputPII")
piiTestMap := make(map[string][]byte)
piiTestMap["PII"] = piiTestArray

testReq := &types.SignalWithStartWorkflowExecutionRequest{
Domain: "testDomain",
WorkflowID: "testWorkflowID",
WorkflowType: &types.WorkflowType{Name: "testWorkflowType"},
TaskList: &types.TaskList{
Name: "testTaskList",
Kind: &testTasklistKind,
},
Input: piiTestArray,
ExecutionStartToCloseTimeoutSeconds: &testExecutionStartToCloseTimeoutSeconds,
TaskStartToCloseTimeoutSeconds: &testTaskStartToCloseTimeoutSeconds,
Identity: "testIdentity",
RequestID: "DF66E35D-A5B0-425D-8731-6AAC4A4B6368",
WorkflowIDReusePolicy: &testWorkflowIDReusePolicy,
SignalName: "testRequest",
SignalInput: piiTestArray,
Control: []byte("testControl"),
RetryPolicy: &types.RetryPolicy{
InitialIntervalInSeconds: 1,
BackoffCoefficient: 1,
MaximumIntervalInSeconds: 1,
MaximumAttempts: 1,
NonRetriableErrorReasons: []string{"testArray"},
ExpirationIntervalInSeconds: 1,
},
CronSchedule: "testSchedule",
Memo: &types.Memo{Fields: piiTestMap},
SearchAttributes: &types.SearchAttributes{IndexedFields: piiTestMap},
Header: &types.Header{Fields: map[string][]byte{}},
DelayStartSeconds: &testDelayStartSeconds,
JitterStartSeconds: &testJitterStartSeconds,
FirstRunAtTimestamp: &testFirstRunAtTimestamp,
}
return testReq
}
49 changes: 0 additions & 49 deletions common/types/replicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,6 @@ type GetDLQReplicationMessagesRequest struct {
TaskInfos []*ReplicationTaskInfo `json:"taskInfos,omitempty"`
}

func (v *GetDLQReplicationMessagesRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

// GetTaskInfos is an internal getter (TBD...)
func (v *GetDLQReplicationMessagesRequest) GetTaskInfos() (o []*ReplicationTaskInfo) {
if v != nil && v.TaskInfos != nil {
Expand All @@ -256,13 +249,6 @@ type GetDomainReplicationMessagesRequest struct {
ClusterName string `json:"clusterName,omitempty"`
}

func (v *GetDomainReplicationMessagesRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

// GetLastRetrievedMessageID is an internal getter (TBD...)
func (v *GetDomainReplicationMessagesRequest) GetLastRetrievedMessageID() (o int64) {
if v != nil && v.LastRetrievedMessageID != nil {
Expand Down Expand Up @@ -298,13 +284,6 @@ type GetReplicationMessagesRequest struct {
ClusterName string `json:"clusterName,omitempty"`
}

func (v *GetReplicationMessagesRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

// GetClusterName is an internal getter (TBD...)
func (v *GetReplicationMessagesRequest) GetClusterName() (o string) {
if v != nil {
Expand Down Expand Up @@ -390,13 +369,6 @@ type CountDLQMessagesRequest struct {
ForceFetch bool
}

func (v *CountDLQMessagesRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

type CountDLQMessagesResponse struct {
History map[HistoryDLQCountKey]int64
Domain int64
Expand All @@ -421,13 +393,6 @@ type MergeDLQMessagesRequest struct {
NextPageToken []byte `json:"nextPageToken,omitempty"`
}

func (v *MergeDLQMessagesRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

// GetType is an internal getter (TBD...)
func (v *MergeDLQMessagesRequest) GetType() (o DLQType) {
if v != nil && v.Type != nil {
Expand Down Expand Up @@ -489,13 +454,6 @@ type PurgeDLQMessagesRequest struct {
InclusiveEndMessageID *int64 `json:"inclusiveEndMessageID,omitempty"`
}

func (v *PurgeDLQMessagesRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

// GetType is an internal getter (TBD...)
func (v *PurgeDLQMessagesRequest) GetType() (o DLQType) {
if v != nil && v.Type != nil {
Expand Down Expand Up @@ -538,13 +496,6 @@ type ReadDLQMessagesRequest struct {
NextPageToken []byte `json:"nextPageToken,omitempty"`
}

func (v *ReadDLQMessagesRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

// GetType is an internal getter (TBD...)
func (v *ReadDLQMessagesRequest) GetType() (o DLQType) {
if v != nil && v.Type != nil {
Expand Down
Loading

0 comments on commit e30187e

Please sign in to comment.