Skip to content

test: add fuzz tests for ChaosHub GitOps helper functions#5526

Open
jovid18 wants to merge 4 commits into
litmuschaos:masterfrom
jovid18:test/add-fuzz-test-chaoshub-gitops
Open

test: add fuzz tests for ChaosHub GitOps helper functions#5526
jovid18 wants to merge 4 commits into
litmuschaos:masterfrom
jovid18:test/add-fuzz-test-chaoshub-gitops

Conversation

@jovid18

@jovid18 jovid18 commented May 30, 2026

Copy link
Copy Markdown

Proposed changes

Fixes #5525

Add fuzz tests for the deterministic GitOps helper functions in
chaoscenter/graphql/server/pkg/chaoshub/ops/gitops.go, following the existing
convention 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.go

Covered helper functions:

  • FuzzGetClonePathGetClonePath
  • FuzzGitConfigConstructGitConfigConstruct
  • FuzzGenerateAuthMethodgenerateAuthMethod

Functions 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 handler package 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 x in the boxes that apply

  • New feature (non-breaking change which adds functionality)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices applies)

Checklist

Put an x in 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.

  • I have read the CONTRIBUTING doc
  • I have signed the commit for DCO to be passed.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

Dependency

  • Please add the links to the dependent PR need to be merged before this (if any).

N/A

Special notes for your reviewer:

The new test file is placed inside the chaoshubops package (not an external
_test package) so that the unexported generateAuthMethod helper can be covered,
matching the in-package convention used by the chaoshub handler fuzz tests.

Each fuzz target was run locally with go test -fuzz for 15s with no crashes.

Signed-off-by: jovid <sh.jo@ecubelabs.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 unexported generateAuthMethod.
  • 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.

Comment on lines +44 to +47
projectID, err := fuzzConsumer.GetString()
if err != nil {
return
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — switched to projectID, _ := fuzzConsumer.GetString() so the error is ignored and short inputs aren't discarded, consistent with the existing handler fuzz tests.

Comment on lines +90 to +109
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
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +112 to +118
config := ChaosHubConfig{
AuthType: authType,
Token: &token,
UserName: &username,
Password: &password,
SSHPrivateKey: &sshPrivateKey,
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@PriteshKiri

Copy link
Copy Markdown
Contributor

Hey @jovid18
Could you please check the review comments from Co-Pilot?

Signed-off-by: jovid <sh.jo@ecubelabs.com>
@jovid18

jovid18 commented Jun 10, 2026

Copy link
Copy Markdown
Author

Thanks @PriteshKiri!
Checked all three Copilot comments and pushed the changes.
The two GetString()/GetInt() early-return points are fixed, and FuzzGenerateAuthMethod now uses GenerateStruct(&config) to align with the rest of the suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add fuzz test on chaoshub gitops

5 participants