-
Notifications
You must be signed in to change notification settings - Fork 176
test(fuzz): add comprehensive Go fuzz tests #19686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sthadka
wants to merge
20
commits into
master
Choose a base branch
from
feat/fuzz
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
aab7a53
test(search): add fuzz tests for query parser
sthadka 26f4d25
test(x509utils): add fuzz tests for PEM/DER certificate processing
sthadka 2d23a06
test(servicecerttoken): add fuzz test for ParseToken
sthadka f208a4e
test(saml): add fuzz test for entity descriptor XML unmarshaling
sthadka 3228c08
test(idputil): add fuzz tests for OAuth state parsing
sthadka 315121d
test(netutil): add fuzz test for ParseEndpoint
sthadka eeb439d
test(net): add fuzz tests for IP address and port parsing
sthadka 1f679d5
test(cvss): add fuzz test for ParseCVSSV3
sthadka f9d3513
test(booleanpolicy): add fuzz tests for all validation regex patterns
sthadka 6dce922
test(pgconfig): add fuzz test for ParseSource
sthadka 4f50ff9
test(binenc): add fuzz tests for binary encoding with roundtrip
sthadka 56621d4
test(uuid): add fuzz tests for UUID parsing
sthadka fee46e1
test(protocompat): add fuzz test for RFC3339 timestamp parsing
sthadka 9b5b031
test(k8sobjects): add fuzz test and unit tests for ParseRef
sthadka 16cf0ee
test(mitre): add fuzz tests for MITRE ATT&CK bundle parsing
sthadka 1c2e50c
test(download): add fuzz test for Content-Disposition header parsing
sthadka 398b8e6
test(endpoints): add fuzz test for legacy endpoint spec parsing
sthadka 7499bcb
test(search/parser): add fuzz test for URL query parsing
sthadka 943d543
fix(fuzz): address PR review feedback
sthadka f8c2863
fix(fuzz): replace test passwords flagged by GitGuardian
sthadka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,62 @@ | ||
| package endpoints | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| // FuzzParseLegacySpec tests ParseLegacySpec with arbitrary input strings to ensure it never panics. | ||
| // The parser should handle any malformed input gracefully. | ||
| func FuzzParseLegacySpec(f *testing.F) { | ||
| // Seed with valid examples from existing tests | ||
| f.Add("") | ||
| f.Add("8080") | ||
| f.Add(":8080") | ||
| f.Add("grpc@:8443") | ||
| f.Add("http@:8080") | ||
| f.Add("grpc@:8443,http@:8080") | ||
| f.Add(":8080, http@127.0.0.1:8081") | ||
| f.Add("grpc@localhost:8443") | ||
| f.Add("http @ http, grpc @ 127.0.0.1:https, grpc@:8082, localhost:8080, http@127.0.0.1:10080") | ||
|
|
||
| // Seed with edge cases | ||
| f.Add("@") | ||
| f.Add("@@") | ||
| f.Add("@:8080") | ||
| f.Add("grpc@") | ||
| f.Add(",,,") | ||
| f.Add(" ") | ||
| f.Add("grpc @ @ :8080") | ||
| f.Add("grpc@:8443,") | ||
| f.Add(",grpc@:8443") | ||
| f.Add("grpc@:8443,,http@:8080") | ||
|
|
||
| // Seed with potentially problematic inputs | ||
| f.Add("grpc@localhost:8443@extra") | ||
| f.Add("http@:8080@http@:8081") | ||
| f.Add("very-long-protocol-name@:8080") | ||
| f.Add("grpc@very-long-hostname-that-might-cause-issues.example.com:8443") | ||
| f.Add("🚀@:8080") // Unicode | ||
| f.Add("grpc\n@:8080") // Newline | ||
| f.Add("grpc\t@:8080") // Tab | ||
|
|
||
| f.Fuzz(func(t *testing.T, input string) { | ||
| // The parser should never panic on any input | ||
| // We don't assert specific output because the function is lenient by design | ||
| // It should handle malformed input gracefully | ||
| result := ParseLegacySpec(input, nil) | ||
|
|
||
| // Basic sanity checks: result should never be nil if we got here without panic | ||
| // Each config should have a Listen address (even if empty after trimming) | ||
| for _, cfg := range result { | ||
| // Ensure Protocols is either nil or has strings | ||
| // This validates the internal structure is consistent | ||
| if cfg.Protocols != nil && len(cfg.Protocols) > 0 { | ||
| for _, proto := range cfg.Protocols { | ||
| _ = proto // Ensure we can read each protocol string | ||
| } | ||
| } | ||
| // Ensure Listen is a valid string (can be empty) | ||
| _ = cfg.Listen | ||
| } | ||
| }) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: stackrox/stackrox
Length of output: 1405
🏁 Script executed:
Repository: stackrox/stackrox
Length of output: 76
🏁 Script executed:
Repository: stackrox/stackrox
Length of output: 1224
🏁 Script executed:
# Read the golangci configuration cat .golangci.ymlRepository: stackrox/stackrox
Length of output: 6155
🏁 Script executed:
Repository: stackrox/stackrox
Length of output: 88
🏁 Script executed:
Repository: stackrox/stackrox
Length of output: 445
🏁 Script executed:
Repository: stackrox/stackrox
Length of output: 2680
🏁 Script executed:
Repository: stackrox/stackrox
Length of output: 442
🏁 Script executed:
Repository: stackrox/stackrox
Length of output: 2375
Remove the redundant nil guard.
In Go,
len(nilSlice)safely returns0, socfg.Protocols != nilis logically unnecessary before thelen()check. While the pattern is defensible as defensive programming, it can be simplified.Suggested change
🧰 Tools
🪛 GitHub Actions: Style
[error] 53-53: golangci-lint (staticcheck) S1009: should omit nil check; len() for nil slices is defined as zero
🪛 GitHub Check: golangci-lint
[failure] 53-53:
S1009: should omit nil check; len() for nil slices is defined as zero (staticcheck)
🤖 Prompt for AI Agents