-
Notifications
You must be signed in to change notification settings - Fork 106
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
Update fuzz tests to use go fuzz features #148
base: master
Are you sure you want to change the base?
Conversation
@@ -611,6 +611,7 @@ func testNewV7(t *testing.T) { | |||
t.Run("FaultyRand", makeTestNewV7FaultyRand()) | |||
t.Run("FaultyRandWithOptions", makeTestNewV7FaultyRandWithOptions()) | |||
t.Run("ShortRandomRead", makeTestNewV7ShortRandomRead()) | |||
t.Run("ShortRandomReadWithOptions", makeTestNewV7ShortRandomReadWithOptions()) |
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.
While I was here I noticed that one of the v7 test functions weren't being run, so I added it here.
5178ff4
to
fe908f1
Compare
} | ||
f.Fuzz(func(t *testing.T, payload string) { | ||
u, err := FromString(payload) | ||
if err != nil { |
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.
the general logic for this pair is that if the function didn't return an error, we make sure the uuid matches a regex for uuids. Otherwise, we assume the error was correct for the input. This implicitly fails the fuzz test on a panic.
name := "seed_valid_" + fst.variant | ||
if err := writeSeedFile(name, fst.input); err != nil { | ||
t.Fatal(err) | ||
f.Fuzz(func(t *testing.T, payload []byte) { |
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.
the general logic for this pair is that if the payload was not 16 bytes, we fail the fuzz if fan error was not returned (or put another way, we verify that the function returns an error when the payload is 16 bytes). Otherwise, if an error was not returned, we make sure it's not a Nil uuid, and we make sure it matched the uuid pattern
@@ -40,11 +40,6 @@ jobs: | |||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support | |||
|
|||
steps: | |||
- name: Harden Runner |
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.
Removed harden in places that I missed it.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #148 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 5 +1
Lines 513 447 -66
=========================================
- Hits 513 447 -66 ☔ View full report in Codecov by Sentry. |
codec_test.go
Outdated
@@ -403,28 +400,109 @@ func BenchmarkParseV4(b *testing.B) { | |||
} | |||
} | |||
|
|||
var seedFuzzCorpus = flag.Bool("seed_fuzz_corpus", false, "seed fuzz test corpus") | |||
const uuidPattern = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" |
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.
Should this also include capital A-F
in the match patterns since those would still be valid UUID strings?
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.
Thanks, nice catch. Should be fixed now. Also added uppered uuids to the corpus
045a083
to
007c5b0
Compare
This PR implements #147. Now, we use the fuzz test features built into
go test
.This PR also replaces the
go-fuzz
tests and their accompanying corpus.