Skip to content

Commit

Permalink
fix: generate ID based on the secretsURL
Browse files Browse the repository at this point in the history
  • Loading branch information
agparadiso committed Nov 26, 2024
1 parent 968a8a1 commit 2a26934
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 46 deletions.
20 changes: 2 additions & 18 deletions core/services/workflows/syncer/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"strings"

"github.com/smartcontractkit/chainlink/v2/core/capabilities/validation"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/webapi"
"github.com/smartcontractkit/chainlink/v2/core/logger"
ghcapabilities "github.com/smartcontractkit/chainlink/v2/core/services/gateway/handlers/capabilities"
Expand All @@ -16,24 +15,8 @@ import (
func NewFetcherFunc(
ctx context.Context,
lggr logger.Logger,
och *webapi.OutgoingConnectorHandler,
workflowID, workflowExecutionID string,
idGenerator func() string) FetcherFunc {
och *webapi.OutgoingConnectorHandler) FetcherFunc {
return func(ctx context.Context, url string) ([]byte, error) {
if err := validation.ValidateWorkflowOrExecutionID(workflowID); err != nil {
return nil, fmt.Errorf("workflow ID %q is invalid: %w", workflowID, err)
}
if err := validation.ValidateWorkflowOrExecutionID(workflowExecutionID); err != nil {
return nil, fmt.Errorf("workflow execution ID %q is invalid: %w", workflowExecutionID, err)
}

messageID := strings.Join([]string{
workflowID,
workflowExecutionID,
ghcapabilities.MethodWorkflowSyncer,
idGenerator(),
}, "/")

payloadBytes, err := json.Marshal(ghcapabilities.Request{
URL: url,
Method: http.MethodGet,
Expand All @@ -42,6 +25,7 @@ func NewFetcherFunc(
return nil, fmt.Errorf("failed to marshal fetch request: %w", err)
}

messageID := strings.Join([]string{ghcapabilities.MethodWorkflowSyncer, url}, "/")
resp, err := och.HandleSingleNodeRequest(ctx, messageID, payloadBytes)
if err != nil {
return nil, err
Expand Down
30 changes: 2 additions & 28 deletions core/services/workflows/syncer/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,9 @@ func TestNewFetcherFunc(t *testing.T) {
och, err := webapi.NewOutgoingConnectorHandler(connector, config, ghcapabilities.MethodComputeAction, lggr)
require.NoError(t, err)

workflowID := "15c631d295ef5e32deb99a10ee6804bc4af13855687559d7ff6552ac6dbb2ce0"
workflowExecutionID := "25c631d295ef5e32deb99a10ee6804bc4af13855687559d7ff6552ac6dbb2ce1"
idGenerator := func() string { return "uniqueID" }
url := "http://example.com"

msgID := strings.Join([]string{
workflowID,
workflowExecutionID,
ghcapabilities.MethodWorkflowSyncer,
idGenerator(),
}, "/")
msgID := strings.Join([]string{ghcapabilities.MethodWorkflowSyncer, url}, "/")

t.Run("OK-valid_request", func(t *testing.T) {
gatewayResp := gatewayResponse(t, msgID)
Expand All @@ -54,32 +46,14 @@ func TestNewFetcherFunc(t *testing.T) {
connector.EXPECT().DonID().Return("don-id")
connector.EXPECT().GatewayIDs().Return([]string{"gateway1", "gateway2"})

fetcher := NewFetcherFunc(ctx, lggr, och, workflowID, workflowExecutionID, idGenerator)
fetcher := NewFetcherFunc(ctx, lggr, och)

payload, err := fetcher(ctx, url)
require.NoError(t, err)

expectedPayload := []byte("response body")
require.Equal(t, expectedPayload, payload)
})

t.Run("NOK-invalid_workflow_id", func(t *testing.T) {
invalidWorkflowID := "invalidWorkflowID"
fetcher := NewFetcherFunc(ctx, lggr, och, invalidWorkflowID, workflowExecutionID, idGenerator)

_, err := fetcher(ctx, url)
require.Error(t, err)
require.Contains(t, err.Error(), "workflow ID")
})

t.Run("NOK-invalid_workflow_execution_id", func(t *testing.T) {
invalidWorkflowExecutionID := "invalidWorkflowExecutionID"
fetcher := NewFetcherFunc(ctx, lggr, och, workflowID, invalidWorkflowExecutionID, idGenerator)

_, err := fetcher(ctx, url)
require.Error(t, err)
require.Contains(t, err.Error(), "workflow execution ID")
})
}

func gatewayResponse(t *testing.T, msgID string) *api.Message {
Expand Down

0 comments on commit 2a26934

Please sign in to comment.