Skip to content

Commit

Permalink
policy fuzzer: ignore known panics (#3993)
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Korczynski <[email protected]>
  • Loading branch information
AdamKorcz authored Jan 4, 2025
1 parent 8040fc4 commit 782e038
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/policy/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,37 @@ package policy

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

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

func catchPanics() {
if r := recover(); r != nil {
var errStr string
switch err := r.(type) {
case string:
errStr = err
case runtime.Error:
errStr = err.Error()
case error:
errStr = err.Error()
}
switch {
case errStr == "freeNode: nodeContext out of sync":
return
case errStr == "unreachable":
return
default:
panic(errStr)
}
}
}

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

0 comments on commit 782e038

Please sign in to comment.