Skip to content
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

policy fuzzer: ignore known panics #3993

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading