| 334 | BENCHMARK(BM_PolicyNative); |
| 335 | |
| 336 | void BM_PolicySymbolic(benchmark::State& state) { |
| 337 | google::protobuf::Arena arena; |
| 338 | ASSERT_OK_AND_ASSIGN(ParsedExpr parsed_expr, Parse(R"cel( |
| 339 | !(ip in ["10.0.1.4", "10.0.1.5", "10.0.1.6"]) && |
| 340 | ((path.startsWith("v1") && token in ["v1", "v2", "admin"]) || |
| 341 | (path.startsWith("v2") && token in ["v2", "admin"]) || |
| 342 | (path.startsWith("/admin") && token == "admin" && ip in [ |
| 343 | "10.0.1.1", "10.0.1.2", "10.0.1.3" |
| 344 | ]) |
| 345 | ))cel")); |
| 346 | |
| 347 | RuntimeOptions options = GetOptions(); |
| 348 | auto runtime = |
| 349 | StandardRuntimeOrDie(options, &arena, ConstFoldingEnabled::kYes); |
| 350 | |
| 351 | ASSERT_OK_AND_ASSIGN(auto cel_expr, ProtobufRuntimeAdapter::CreateProgram( |
| 352 | *runtime, parsed_expr)); |
| 353 | |
| 354 | Activation activation; |
| 355 | activation.InsertOrAssignValue("ip", StringValue(&arena, kIP)); |
| 356 | activation.InsertOrAssignValue("path", StringValue(&arena, kPath)); |
| 357 | activation.InsertOrAssignValue("token", StringValue(&arena, kToken)); |
| 358 | |
| 359 | for (auto _ : state) { |
| 360 | ASSERT_OK_AND_ASSIGN(cel::Value result, |
| 361 | cel_expr->Evaluate(&arena, activation)); |
| 362 | auto result_bool = As<BoolValue>(result); |
| 363 | ASSERT_TRUE(result_bool && result_bool->NativeValue()); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | BENCHMARK(BM_PolicySymbolic); |
| 368 | |
| 369 | class RequestMapImpl : public CustomMapValueInterface { |
| 370 | public: |
| 371 | size_t Size() const override { return 3; } |
| 372 | |
| 373 | absl::Status ListKeys( |
| 374 | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
| 375 | google::protobuf::MessageFactory* absl_nonnull message_factory, |
| 376 | google::protobuf::Arena* absl_nonnull arena, |
| 377 | ListValue* absl_nonnull result) const override { |
| 378 | return absl::UnimplementedError("Unsupported"); |
| 379 | } |
| 380 | |
| 381 | absl::StatusOr<absl_nonnull ValueIteratorPtr> NewIterator() const override { |
| 382 | return absl::UnimplementedError("Unsupported"); |
| 383 | } |
| 384 | |
| 385 | std::string DebugString() const override { return "RequestMapImpl"; } |
| 386 | |
| 387 | absl::Status ConvertToJsonObject( |
| 388 | const google::protobuf::DescriptorPool* absl_nonnull, |
| 389 | google::protobuf::MessageFactory* absl_nonnull, |
| 390 | google::protobuf::Message* absl_nonnull) const override { |
| 391 | return absl::UnimplementedError("Unsupported"); |
| 392 | } |
| 393 |
nothing calls this directly
no test coverage detected