cel_authorization_engine_test.cc
Go to the documentation of this file.
1 // Copyright 2020 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <gtest/gtest.h>
18 
19 namespace grpc_core {
20 
22  protected:
23  void SetUp() override {
28  }
32 };
33 
34 TEST_F(CelAuthorizationEngineTest, CreateEngineSuccessOnePolicy) {
35  std::vector<envoy_config_rbac_v3_RBAC*> policies{allow_policy_};
36  std::unique_ptr<CelAuthorizationEngine> engine =
38  EXPECT_NE(engine, nullptr)
39  << "Error: Failed to create CelAuthorizationEngine with one policy.";
40 }
41 
42 TEST_F(CelAuthorizationEngineTest, CreateEngineSuccessTwoPolicies) {
43  std::vector<envoy_config_rbac_v3_RBAC*> policies{deny_policy_, allow_policy_};
44  std::unique_ptr<CelAuthorizationEngine> engine =
46  EXPECT_NE(engine, nullptr)
47  << "Error: Failed to create CelAuthorizationEngine with two policies.";
48 }
49 
50 TEST_F(CelAuthorizationEngineTest, CreateEngineFailNoPolicies) {
51  std::vector<envoy_config_rbac_v3_RBAC*> policies{};
52  std::unique_ptr<CelAuthorizationEngine> engine =
54  EXPECT_EQ(engine, nullptr)
55  << "Error: Created CelAuthorizationEngine without policies.";
56 }
57 
58 TEST_F(CelAuthorizationEngineTest, CreateEngineFailTooManyPolicies) {
59  std::vector<envoy_config_rbac_v3_RBAC*> policies{deny_policy_, allow_policy_,
60  deny_policy_};
61  std::unique_ptr<CelAuthorizationEngine> engine =
63  EXPECT_EQ(engine, nullptr)
64  << "Error: Created CelAuthorizationEngine with more than two policies.";
65 }
66 
67 TEST_F(CelAuthorizationEngineTest, CreateEngineFailWrongPolicyOrder) {
68  std::vector<envoy_config_rbac_v3_RBAC*> policies{allow_policy_, deny_policy_};
69  std::unique_ptr<CelAuthorizationEngine> engine =
71  EXPECT_EQ(engine, nullptr) << "Error: Created CelAuthorizationEngine with "
72  "policies in the wrong order.";
73 }
74 
75 } // namespace grpc_core
76 
77 int main(int argc, char** argv) {
78  ::testing::InitGoogleTest(&argc, argv);
79  return RUN_ALL_TESTS();
80 }
grpc_core::CelAuthorizationEngineTest::SetUp
void SetUp() override
Definition: cel_authorization_engine_test.cc:23
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::CelAuthorizationEngineTest
Definition: cel_authorization_engine_test.cc:21
main
int main(int argc, char **argv)
Definition: cel_authorization_engine_test.cc:77
envoy_config_rbac_v3_RBAC
struct envoy_config_rbac_v3_RBAC envoy_config_rbac_v3_RBAC
Definition: config/rbac/v3/rbac.upb.h:31
testing::Test
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:402
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
envoy_config_rbac_v3_RBAC_set_action
UPB_INLINE void envoy_config_rbac_v3_RBAC_set_action(envoy_config_rbac_v3_RBAC *msg, int32_t value)
Definition: config/rbac/v3/rbac.upb.h:127
EXPECT_NE
#define EXPECT_NE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2028
grpc_core::TEST_F
TEST_F(AuthorizationMatchersTest, AlwaysAuthorizationMatcher)
Definition: authorization_matchers_test.cc:35
grpc_core::CelAuthorizationEngineTest::arena_
upb::Arena arena_
Definition: cel_authorization_engine_test.cc:29
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
cel_authorization_engine.h
grpc_core::CelAuthorizationEngineTest::allow_policy_
envoy_config_rbac_v3_RBAC * allow_policy_
Definition: cel_authorization_engine_test.cc:31
envoy_config_rbac_v3_RBAC_new
UPB_INLINE envoy_config_rbac_v3_RBAC * envoy_config_rbac_v3_RBAC_new(upb_Arena *arena)
Definition: config/rbac/v3/rbac.upb.h:76
upb::Arena::ptr
upb_Arena * ptr()
Definition: upb.hpp:76
upb::Arena
Definition: upb.hpp:68
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc_core::CelAuthorizationEngineTest::deny_policy_
envoy_config_rbac_v3_RBAC * deny_policy_
Definition: cel_authorization_engine_test.cc:30
grpc_core::CelAuthorizationEngine::CreateCelAuthorizationEngine
static std::unique_ptr< CelAuthorizationEngine > CreateCelAuthorizationEngine(const std::vector< envoy_config_rbac_v3_RBAC * > &rbac_policies)
Definition: cel_authorization_engine.cc:51


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:43