(t *testing.T)
| 797 | } |
| 798 | |
| 799 | func TestSyncEvalRejectedInAsyncEnv(t *testing.T) { |
| 800 | // Env-level rejection: an environment that declares any async function rejects the synchronous |
| 801 | // entry points even for an expression that does not call the async function. Callers needing |
| 802 | // synchronous evaluation should build a separate, non-async environment. |
| 803 | prg := mustProgram(t, `x + 1`, // pure, synchronous, does not use rpc |
| 804 | cel.Variable("x", cel.IntType), |
| 805 | cel.Function("rpc", |
| 806 | cel.Overload("rpc_string", []*cel.Type{cel.StringType}, cel.StringType, |
| 807 | cel.AsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val { return args[0] }))), |
| 808 | ) |
| 809 | if _, _, err := prg.Eval(map[string]any{"x": 1}); err == nil || !strings.Contains(err.Error(), "ConcurrentEval") { |
| 810 | t.Errorf("Eval() in async env = %v, want ConcurrentEval error", err) |
| 811 | } |
| 812 | |
| 813 | // A separate non-async env evaluates the same expression synchronously. |
| 814 | syncPrg := mustProgram(t, `x + 1`, cel.Variable("x", cel.IntType)) |
| 815 | out, _, err := syncPrg.Eval(map[string]any{"x": 1}) |
| 816 | if err != nil { |
| 817 | t.Fatalf("Eval() in non-async env returned error: %v", err) |
| 818 | } |
| 819 | if out.Equal(types.Int(2)) != types.True { |
| 820 | t.Errorf("Eval() = %v, want 2", out) |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | func TestBypassAsyncProtection(t *testing.T) { |
| 825 | // An environment that declares an async function allows synchronous Eval and ContextEval |
nothing calls this directly
no test coverage detected