MCPcopy Create free account
hub / github.com/cel-expr/cel-go / FuzzInterpreter

Function FuzzInterpreter

fuzzing/fuzz_interpreter_test.go:117–155  ·  view source on GitHub ↗
(f *testing.F)

Source from the content-addressed store, hash-verified

115var _ interpreter.Activation = activation{}
116
117func FuzzInterpreter(f *testing.F) {
118 f.Add([]byte{})
119 if env, err := getCELFuzzEnv(); err == nil {
120 if env, err = env.Extend(cel.Variable("x", cel.StringType)); err == nil {
121 if ast, issues := env.Compile("x + ' world'"); issues.Err() == nil {
122 if ce, err := cel.AstToCheckedExpr(ast); err == nil {
123 seed := &InterpreterFuzzable{
124 CheckedExpr: ce,
125 Activation: map[string]*exprpb.Value{
126 "x": {Kind: &exprpb.Value_StringValue{StringValue: "hello"}},
127 },
128 }
129 if b, err := proto.Marshal(seed); err == nil {
130 f.Add(b)
131 }
132 }
133 }
134 }
135 }
136 f.Fuzz(func(t *testing.T, in []byte) {
137 var p InterpreterFuzzable
138 err := proto.UnmarshalOptions{
139 AllowPartial: true,
140 DiscardUnknown: true,
141 }.Unmarshal(in, &p)
142 if err != nil {
143 return
144 }
145 env, err := getCELFuzzEnv()
146 if err != nil {
147 panic(err)
148 }
149 prog, err := env.Program(cel.CheckedExprToAst(p.GetCheckedExpr()))
150 if err != nil {
151 return
152 }
153 _, _, _ = prog.Eval(activation(p.GetActivation()))
154 })
155}

Callers

nothing calls this directly

Calls 13

GetCheckedExprMethod · 0.95
GetActivationMethod · 0.95
VariableFunction · 0.92
AstToCheckedExprFunction · 0.92
CheckedExprToAstFunction · 0.92
getCELFuzzEnvFunction · 0.85
activationTypeAlias · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
AddMethod · 0.65
CompileMethod · 0.65
EvalMethod · 0.65

Tested by

no test coverage detected