-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add fuzz tests and daily fuzz workflow (#832)
* chore: add fuzz tests and daily fuzz workflow * i promise we'll write ok tests linter, please leave me alone * try more-right syntax * the cake (linter_settings) was a lie * there's more to say about testing, but i don't know what it is yet * fix chron syntax
- Loading branch information
1 parent
4c54274
commit 377ed80
Showing
11 changed files
with
176 additions
and
6 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,25 @@ | ||
name: Fuzz Testing | ||
|
||
permissions: | ||
contents: read | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
||
- name: Setup golang | ||
uses: ./.github/actions/golang | ||
|
||
- name: Display Go version | ||
run: go version | ||
|
||
- name: Fuzz Tests | ||
run: | | ||
make test-fuzz |
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
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,20 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
fuzzTime=${1:-10s} | ||
|
||
files=$(grep -r --include='**_test.go' --files-with-matches 'func Fuzz' .) | ||
|
||
for file in ${files} | ||
do | ||
funcs=$(grep -o 'func Fuzz\w*' $file | sed 's/func //') | ||
for func in ${funcs} | ||
do | ||
echo "Fuzzing $func in $file" | ||
parentDir=$(dirname $file) | ||
# Add $ to the end of the func name, since go fuzzing gets stressed out by ambiguiity | ||
# ie "testing: will not fuzz, -fuzz matches more than one fuzz test: [FuzzCompareControls FuzzCompareControlsInt]" | ||
go test $parentDir -run=$func -fuzz=$func\$ -fuzztime=${fuzzTime} | ||
done | ||
done |
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,36 @@ | ||
package dev | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func FuzzRunSingleValidation(f *testing.F) { | ||
// including a fully populated valid-component.yaml to exercise a fuzzy version of passing valid-but-wrong-for-this-command oscal data. | ||
for _, tc := range []string{"../../test/unit/common/oscal/valid-component.yaml", "../../test/unit/common/validation/multi.validation.yaml"} { | ||
bytes, err := os.ReadFile(tc) | ||
require.NoError(f, err) | ||
|
||
f.Add(bytes) | ||
} | ||
|
||
f.Fuzz(func(t *testing.T, a []byte) { | ||
RunSingleValidation(context.Background(), a) | ||
}) | ||
} | ||
|
||
func FuzzDevValidate(f *testing.F) { | ||
bytes, err := os.ReadFile("../../test/unit/common/validation/multi.validation.yaml") | ||
require.NoError(f, err) | ||
|
||
drs, err := os.ReadFile("../../test/unit/common/resources/valid-resources.json") | ||
require.NoError(f, err) | ||
f.Add(bytes, drs) | ||
|
||
f.Fuzz(func(t *testing.T, a []byte, b []byte) { | ||
DevValidate(context.Background(), a, b, false, nil) | ||
}) | ||
} |
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
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