Repository navigation
test(fuzz): add fuzz targets for secret transforms and data hashing #340
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
edfb180
fix(cli): reject non-ASCII TLS pins instead of panicking
BryanFRD 8762269
test(fuzz): add fuzz targets for secret transforms and data hashing
BryanFRD c0b956a
ci(fuzz): name the exact upload-artifact version in its pin
BryanFRD 29cbe9f
test(fuzz): skip the key that collides with the fixed entry
BryanFRD 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,43 @@ | ||
| name: Fuzz | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '23 3 * * *' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| fuzz: | ||
| name: Fuzz ${{ matrix.target }} | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - target: FuzzApplyTransforms | ||
| package: ./internal/controller | ||
| - target: FuzzHashSecretData | ||
| package: ./internal/controller | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7 | ||
| with: | ||
| go-version-file: go.mod | ||
|
|
||
| - name: Fuzz | ||
| run: go test -run='^$' -fuzz="^${{ matrix.target }}\$" -fuzztime=300s ${{ matrix.package }} | ||
|
|
||
| - name: Failing inputs | ||
| if: failure() | ||
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| with: | ||
| name: fuzz-testdata-${{ matrix.target }} | ||
| path: internal/controller/testdata/fuzz | ||
| if-no-files-found: ignore | ||
| retention-days: 30 |
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
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
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,102 @@ | ||
| package controller | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "errors" | ||
| "reflect" | ||
| "testing" | ||
|
|
||
| fvv1alpha1 "github.com/FerrLabs/FerrVault/api/ferrvault/v1alpha1" | ||
| ) | ||
|
|
||
| var fuzzTransformTypes = []string{ | ||
| TransformPrefix, | ||
| TransformSuffix, | ||
| TransformRename, | ||
| TransformBase64Decode, | ||
| TransformJSONExpand, | ||
| "unknown", | ||
| } | ||
|
|
||
| func FuzzApplyTransforms(f *testing.F) { | ||
| f.Add(uint8(4), "CONFIG", `{"a":{"b":1},"c":[1,2],"d":null,"e":true}`, "", "", "") | ||
| f.Add(uint8(3), "TOKEN", "c2VjcmV0", "", "", "") | ||
| f.Add(uint8(3), "TOKEN", "c2VjcmV0_-8=", "", "", "") | ||
| f.Add(uint8(0), "K", "v", "APP_", "", "") | ||
| f.Add(uint8(1), "K", "v", "_V2", "", "") | ||
| f.Add(uint8(2), "K", "v", "", "K", "K2") | ||
| f.Add(uint8(2), "K", "v", "", "K", "K") | ||
| f.Add(uint8(4), "CONFIG", `{"x":1e400}`, "", "", "") | ||
|
|
||
| f.Fuzz(func(t *testing.T, kind uint8, key, val, affix, from, to string) { | ||
| typ := fuzzTransformTypes[int(kind)%len(fuzzTransformTypes)] | ||
| if key == "OTHER" { | ||
| t.Skip() | ||
| } | ||
| input := map[string]string{key: val, "OTHER": "o"} | ||
| snapshot := map[string]string{key: val, "OTHER": "o"} | ||
| transforms := []fvv1alpha1.SecretTransform{ | ||
| {Type: typ, Value: affix, From: from, To: to, Key: key, Keys: []string{key}}, | ||
| } | ||
|
|
||
| out, err := ApplyTransforms(input, transforms) | ||
| if !reflect.DeepEqual(input, snapshot) { | ||
| t.Fatalf("input mutated: before %q after %q", snapshot, input) | ||
| } | ||
| if err != nil { | ||
| if te := (*TransformError)(nil); !errors.As(err, &te) { | ||
| t.Fatalf("error is %T, want *TransformError", err) | ||
| } | ||
| } | ||
|
|
||
| out2, err2 := ApplyTransforms(input, transforms) | ||
| if (err == nil) != (err2 == nil) || !reflect.DeepEqual(out, out2) { | ||
| t.Fatalf("not deterministic: %q/%v vs %q/%v", out, err, out2, err2) | ||
| } | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
| switch typ { | ||
| case TransformPrefix: | ||
| if got := out[affix+key]; got != val { | ||
| t.Fatalf("prefix lost value for %q: %q", key, got) | ||
| } | ||
| case TransformSuffix: | ||
| if got := out[key+affix]; got != val { | ||
| t.Fatalf("suffix lost value for %q: %q", key, got) | ||
| } | ||
| case TransformBase64Decode: | ||
| if want, ok := decodeEither(val); ok && out[key] != want { | ||
| t.Fatalf("base64Decode %q: got %q want %q", val, out[key], want) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| func decodeEither(s string) (string, bool) { | ||
| if b, err := base64.StdEncoding.DecodeString(s); err == nil { | ||
| return string(b), true | ||
| } | ||
| if b, err := base64.URLEncoding.DecodeString(s); err == nil { | ||
| return string(b), true | ||
| } | ||
| return "", false | ||
| } | ||
|
|
||
| func FuzzHashSecretData(f *testing.F) { | ||
| f.Add("a", "1", "b", "2") | ||
| f.Add("a\x00b", "c", "a", "b\x00c") | ||
| f.Add("", "", "", "") | ||
|
|
||
| f.Fuzz(func(t *testing.T, k1, v1, k2, v2 string) { | ||
| if k1 == k2 { | ||
| t.Skip() | ||
| } | ||
| a := map[string]string{k1: v1, k2: v2} | ||
| b := map[string]string{k2: v2, k1: v1} | ||
| if hashSecretData(a) != hashSecretData(b) { | ||
| t.Fatalf("hash depends on construction order for %q", a) | ||
| } | ||
| }) | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.