authorization_policy_provider_test.cc
Go to the documentation of this file.
1 // Copyright 2021 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 
15 #include <gtest/gtest.h>
16 
18 
21 
22 #define VALID_POLICY_PATH_1 \
23  "test/core/security/authorization/test_policies/valid_policy_1.json"
24 #define VALID_POLICY_PATH_2 \
25  "test/core/security/authorization/test_policies/valid_policy_2.json"
26 #define INVALID_POLICY_PATH \
27  "test/core/security/authorization/test_policies/invalid_policy.json"
28 
29 namespace grpc {
30 
31 TEST(AuthorizationPolicyProviderTest, StaticDataCreateReturnsProvider) {
35  ASSERT_NE(provider, nullptr);
36  EXPECT_NE(provider->c_provider(), nullptr);
37  EXPECT_TRUE(status.ok());
38  EXPECT_TRUE(status.error_message().empty());
39 }
40 
41 TEST(AuthorizationPolicyProviderTest, StaticDataCreateReturnsErrorStatus) {
45  ASSERT_EQ(provider, nullptr);
47  EXPECT_EQ(status.error_message(), "\"name\" field is not present.");
48 }
49 
50 TEST(AuthorizationPolicyProviderTest, FileWatcherCreateReturnsProvider) {
51  auto tmp_authz_policy = absl::make_unique<grpc_core::testing::TmpFile>(
55  tmp_authz_policy->name(), /*refresh_interval_sec=*/1, &status);
56  ASSERT_NE(provider, nullptr);
57  EXPECT_NE(provider->c_provider(), nullptr);
58  EXPECT_TRUE(status.ok());
59  EXPECT_TRUE(status.error_message().empty());
60 }
61 
62 TEST(AuthorizationPolicyProviderTest, FileWatcherCreateReturnsErrorStatus) {
63  auto tmp_authz_policy = absl::make_unique<grpc_core::testing::TmpFile>(
67  tmp_authz_policy->name(), /*refresh_interval_sec=*/1, &status);
68  ASSERT_EQ(provider, nullptr);
70  EXPECT_EQ(status.error_message(), "\"name\" field is not present.");
71 }
72 
73 } // namespace grpc
74 
75 int main(int argc, char** argv) {
76  ::testing::InitGoogleTest(&argc, argv);
78  return RUN_ALL_TESTS();
79 }
grpc::status
auto status
Definition: cpp/client/credentials_test.cc:200
tls_utils.h
generate.env
env
Definition: generate.py:37
grpc
Definition: grpcpp/alarm.h:33
grpc::ASSERT_EQ
ASSERT_EQ(sizeof(valid_json), fwrite(valid_json, 1, sizeof(valid_json), creds_file))
grpc::EXPECT_TRUE
EXPECT_TRUE(status.ok())
EXPECT_NE
#define EXPECT_NE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2028
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
grpc::ASSERT_NE
ASSERT_NE(creds_file_name, nullptr)
main
int main(int argc, char **argv)
Definition: authorization_policy_provider_test.cc:75
test_config.h
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
VALID_POLICY_PATH_1
#define VALID_POLICY_PATH_1
Definition: authorization_policy_provider_test.cc:22
grpc::TEST
TEST(CredentialsTest, StsCredentialsOptionsFromEnv)
Definition: cpp/client/credentials_test.cc:229
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
grpc::experimental::StaticDataAuthorizationPolicyProvider::Create
static std::shared_ptr< StaticDataAuthorizationPolicyProvider > Create(const std::string &authz_policy, grpc::Status *status)
Definition: authorization_policy_provider.cc:29
grpc.StatusCode.INVALID_ARGUMENT
tuple INVALID_ARGUMENT
Definition: src/python/grpcio/grpc/__init__.py:263
grpc::Status
Definition: include/grpcpp/impl/codegen/status.h:35
grpc::experimental::FileWatcherAuthorizationPolicyProvider::Create
static std::shared_ptr< FileWatcherAuthorizationPolicyProvider > Create(const std::string &authz_policy_path, unsigned int refresh_interval_sec, grpc::Status *status)
Definition: authorization_policy_provider.cc:51
grpc::EXPECT_EQ
EXPECT_EQ(grpc::StatusCode::INVALID_ARGUMENT, status.error_code())
INVALID_POLICY_PATH
#define INVALID_POLICY_PATH
Definition: authorization_policy_provider_test.cc:26
authorization_policy_provider.h
grpc_core::testing::GetFileContents
std::string GetFileContents(const char *path)
Definition: test/core/util/tls_utils.cc:68


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:45