Skip to content

Commit

Permalink
fix validation in chain write capability
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhoonbang committed Nov 11, 2024
1 parent a455950 commit 98d221e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions core/capabilities/targets/write_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/hex"
"fmt"
"math/big"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
Expand Down Expand Up @@ -181,12 +182,18 @@ func evaluate(rawRequest capabilities.CapabilityRequest) (r Request, err error)
return r, fmt.Errorf("WorkflowExecutionID in the report does not match WorkflowExecutionID in the request metadata. Report WorkflowExecutionID: %+v, request WorkflowExecutionID: %+v", reportMetadata.WorkflowExecutionID, rawRequest.Metadata.WorkflowExecutionID)
}

if hex.EncodeToString(reportMetadata.WorkflowOwner[:]) != rawRequest.Metadata.WorkflowOwner {
if !strings.EqualFold(hex.EncodeToString(reportMetadata.WorkflowOwner[:]), rawRequest.Metadata.WorkflowOwner) {
return r, fmt.Errorf("WorkflowOwner in the report does not match WorkflowOwner in the request metadata. Report WorkflowOwner: %+v, request WorkflowOwner: %+v", reportMetadata.WorkflowOwner, rawRequest.Metadata.WorkflowOwner)
}

if hex.EncodeToString(reportMetadata.WorkflowName[:]) != rawRequest.Metadata.WorkflowName {
return r, fmt.Errorf("WorkflowName in the report does not match WorkflowName in the request metadata. Report WorkflowName: %+v, request WorkflowName: %+v", reportMetadata.WorkflowName, rawRequest.Metadata.WorkflowName)
decodedName, err := hex.DecodeString(rawRequest.Metadata.WorkflowName)
if err != nil {
return r, err
}
var workflowName [10]byte
copy(workflowName[:], decodedName)
if !bytes.Equal(reportMetadata.WorkflowName[:], workflowName[:]) {
return r, fmt.Errorf("WorkflowName in the report does not match WorkflowName in the request metadata. Report WorkflowName: %+v, request WorkflowName: %+v", hex.EncodeToString(reportMetadata.WorkflowName[:]), hex.EncodeToString(workflowName[:]))
}

if hex.EncodeToString(reportMetadata.WorkflowCID[:]) != rawRequest.Metadata.WorkflowID {
Expand Down

0 comments on commit 98d221e

Please sign in to comment.