Skip to content

Commit

Permalink
policy fuzzer: ignore known panics
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Korczynski <[email protected]>
  • Loading branch information
AdamKorcz committed Dec 26, 2024
1 parent 170ef3c commit 710ea20
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/policy/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,33 @@ package policy

import (
"context"
"runtime"
"testing"
)

var policyTypes = []string{"cue", "rego"}

func catchPanics() {

Check failure on line 26 in pkg/policy/fuzz_test.go

View workflow job for this annotation

GitHub Actions / lint

func `catchPanics` is unused (unused)
if r := recover(); r != nil {
var err string
switch r.(type) {

Check failure on line 29 in pkg/policy/fuzz_test.go

View workflow job for this annotation

GitHub Actions / lint

typeSwitchVar: 3 cases can benefit from type switch with assignment (gocritic)

Check failure on line 29 in pkg/policy/fuzz_test.go

View workflow job for this annotation

GitHub Actions / lint

S1034: assigning the result of this type assertion to a variable (switch r := r.(type)) could eliminate type assertions in switch cases (gosimple)
case string:
err = r.(string)

Check failure on line 31 in pkg/policy/fuzz_test.go

View workflow job for this annotation

GitHub Actions / lint

S1034(related information): could eliminate this type assertion (gosimple)
case runtime.Error:
err = r.(runtime.Error).Error()

Check failure on line 33 in pkg/policy/fuzz_test.go

View workflow job for this annotation

GitHub Actions / lint

S1034(related information): could eliminate this type assertion (gosimple)
case error:
err = r.(error).Error()

Check failure on line 35 in pkg/policy/fuzz_test.go

View workflow job for this annotation

GitHub Actions / lint

S1034(related information): could eliminate this type assertion (gosimple)
}
if err == "freeNode: nodeContext out of sync" {

Check failure on line 37 in pkg/policy/fuzz_test.go

View workflow job for this annotation

GitHub Actions / lint

ifElseChain: rewrite if-else to switch statement (gocritic)
return
} else if err == "unreachable" {
return
} else {

Check failure on line 41 in pkg/policy/fuzz_test.go

View workflow job for this annotation

GitHub Actions / lint

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
panic(err)
}
}
}

func FuzzEvaluatePolicyAgainstJSON(f *testing.F) {
f.Fuzz(func(_ *testing.T, name, policyBody string, jsonBytes []byte, policyType uint8) {
choosePolicyType := policyTypes[int(policyType)%len(policyTypes)]
Expand Down

0 comments on commit 710ea20

Please sign in to comment.