test: add fuzz tests for ChaosHub GitOps helper functions#5526
Conversation
Signed-off-by: jovid <sh.jo@ecubelabs.com>
There was a problem hiding this comment.
Pull request overview
Adds Go fuzz targets to expand ChaosHub GitOps helper coverage in chaoscenter/graphql/server/pkg/chaoshub/ops, aligning with the existing AdaLogics fuzzing approach already used in the chaoshub handler package.
Changes:
- Introduces fuzz tests for
GetClonePath,GitConfigConstruct, and the unexportedgenerateAuthMethod. - Adds invariant/expectation checks to ensure deterministic helpers behave consistently under fuzzed inputs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| projectID, err := fuzzConsumer.GetString() | ||
| if err != nil { | ||
| return | ||
| } |
There was a problem hiding this comment.
Fixed — switched to projectID, _ := fuzzConsumer.GetString() so the error is ignored and short inputs aren't discarded, consistent with the existing handler fuzz tests.
| token, err := fuzzConsumer.GetString() | ||
| if err != nil { | ||
| return | ||
| } | ||
| username, err := fuzzConsumer.GetString() | ||
| if err != nil { | ||
| return | ||
| } | ||
| password, err := fuzzConsumer.GetString() | ||
| if err != nil { | ||
| return | ||
| } | ||
| sshPrivateKey, err := fuzzConsumer.GetString() | ||
| if err != nil { | ||
| return | ||
| } | ||
| idx, err := fuzzConsumer.GetInt() | ||
| if err != nil { | ||
| return | ||
| } |
There was a problem hiding this comment.
Resolved by switching to fuzzConsumer.GenerateStruct(&config), so the manual GetString() calls and their early returns are gone entirely; the one remaining GetInt() now ignores its error as suggested.
| config := ChaosHubConfig{ | ||
| AuthType: authType, | ||
| Token: &token, | ||
| UserName: &username, | ||
| Password: &password, | ||
| SSHPrivateKey: &sshPrivateKey, | ||
| } |
There was a problem hiding this comment.
Refactored this to use GenerateStruct(&config) for consistency with the rest of the suite; since go-fuzz-headers always allocates pointers (never nil), the nil case isn't reachable through that path.
Also, Reaching it would expose an unguarded nil-deref in generateAuthMethod (gitops.go:286-299), which I think is better fixed in production code via a separate PR
|
Hey @jovid18 |
Signed-off-by: jovid <sh.jo@ecubelabs.com>
|
Thanks @PriteshKiri! |
Proposed changes
Fixes #5525
Add fuzz tests for the deterministic GitOps helper functions in
chaoscenter/graphql/server/pkg/chaoshub/ops/gitops.go, following the existingconvention in
chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go(using
github.com/AdaLogics/go-fuzz-headers).New test file:
chaoscenter/graphql/server/pkg/chaoshub/ops/gitops_fuzz_test.goCovered helper functions:
FuzzGetClonePath—GetClonePathFuzzGitConfigConstruct—GitConfigConstructFuzzGenerateAuthMethod—generateAuthMethodFunctions that perform real git/network or filesystem I/O (
GitClone,GitPull,getChaosChartRepo,GitPlainOpen, etc.) are out of scope.This continues the ChaosHub fuzzing coverage started for the
handlerpackage in #4857,as part of the wider effort to add fuzzing test suites in Litmus (#4548).
Types of changes
What types of changes does your code introduce to Litmus? Put an
xin the boxes that applyChecklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Dependency
N/A
Special notes for your reviewer:
The new test file is placed inside the
chaoshubopspackage (not an external_testpackage) so that the unexportedgenerateAuthMethodhelper can be covered,matching the in-package convention used by the chaoshub
handlerfuzz tests.Each fuzz target was run locally with
go test -fuzzfor 15s with no crashes.