-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(workflow/fetcher): validates response before use (#15921)
* fix(workflow/fetcher): validates response before use * feat(capabilities): add Validate method on Response * feat(workflows/syncer): use Validate in Fetch and test * refactor(workflows/syncer): simplifies getWorkflowArtifacts * refactor(workflow/fetcher): lint fixes and clean up
- Loading branch information
Showing
6 changed files
with
214 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"chainlink": patch | ||
--- | ||
|
||
validates response from gateway in workflow/fetcher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
core/services/gateway/handlers/capabilities/webapi_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package capabilities | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestResponseValidate(t *testing.T) { | ||
tt := []struct { | ||
name string | ||
response Response | ||
expectError string | ||
}{ | ||
{ | ||
name: "valid Response with ExecutionError", | ||
response: Response{ExecutionError: true, ErrorMessage: "Some error"}, | ||
}, | ||
{ | ||
name: "invalid Response with ExecutionError but no ErrorMessage", | ||
response: Response{ExecutionError: true}, | ||
expectError: "executionError is true but errorMessage is empty", | ||
}, | ||
{ | ||
name: "valid HTTP Response", | ||
response: Response{StatusCode: 200}, | ||
}, | ||
{ | ||
name: "invalid status code", | ||
response: Response{ | ||
Body: []byte("body"), | ||
}, | ||
expectError: "statusCode must be set when executionError is false", | ||
}, | ||
{ | ||
name: "invalid HTTP Response with bad StatusCode", | ||
response: Response{StatusCode: 700}, | ||
expectError: "statusCode must be a valid HTTP status code (100-599)", | ||
}, | ||
} | ||
|
||
for _, tc := range tt { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := tc.response.Validate() | ||
|
||
if tc.expectError != "" { | ||
require.Error(t, err) | ||
return | ||
} | ||
|
||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters