| 129 | } |
| 130 | |
| 131 | TEST_P(EvaluatorMemorySafetyTest, Basic) { |
| 132 | const auto& test_case = GetTestCase(); |
| 133 | InterpreterOptions options = GetOptions(); |
| 134 | |
| 135 | std::unique_ptr<CelExpressionBuilder> builder = |
| 136 | CreateCelExpressionBuilder(options); |
| 137 | builder->set_container("google.rpc.context"); |
| 138 | ASSERT_OK(RegisterBuiltinFunctions(builder->GetRegistry(), options)); |
| 139 | |
| 140 | absl::string_view function_name = "IsPrivate"; |
| 141 | if (test_case.reference_resolver_enabled) { |
| 142 | function_name = "net.IsPrivate"; |
| 143 | } |
| 144 | ASSERT_OK((FunctionAdapter<bool, CelValue::StringHolder>::CreateAndRegister( |
| 145 | function_name, false, &IsPrivateIpv4Impl, builder->GetRegistry()))); |
| 146 | |
| 147 | ASSERT_OK_AND_ASSIGN(ParsedExpr expr, parser::Parse(test_case.expression)); |
| 148 | |
| 149 | ASSERT_OK_AND_ASSIGN( |
| 150 | auto plan, builder->CreateExpression(&expr.expr(), &expr.source_info())); |
| 151 | |
| 152 | Activation activation; |
| 153 | for (const auto& [key, value] : test_case.activation) { |
| 154 | activation.InsertValue(key, value); |
| 155 | } |
| 156 | |
| 157 | absl::StatusOr<CelValue> got = plan->Evaluate(activation, &arena_); |
| 158 | |
| 159 | EXPECT_THAT(got, IsOkAndHolds(test_case.expected_matcher)); |
| 160 | } |
| 161 | |
| 162 | // Check no use after free errors if evaluated after AST is freed. |
| 163 | TEST_P(EvaluatorMemorySafetyTest, NoAstDependency) { |
nothing calls this directly
no test coverage detected