channel_creds_registry_test.cc
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2022 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
20 
21 #include <gmock/gmock.h>
22 #include <gtest/gtest.h>
23 
24 #include <grpc/grpc.h>
25 
30 
31 namespace grpc_core {
32 namespace testing {
33 namespace {
34 
35 class TestChannelCredsFactory : public ChannelCredsFactory<> {
36  public:
37  absl::string_view creds_type() const override { return "test"; }
38  bool IsValidConfig(const Json& /*config*/) const override { return true; }
39  RefCountedPtr<grpc_channel_credentials> CreateChannelCreds(
40  const Json& /*config*/) const override {
41  return RefCountedPtr<grpc_channel_credentials>(
43  }
44 };
45 
46 class ChannelCredsRegistryTest : public ::testing::Test {
47  protected:
48  void SetUp() override {
50  grpc_init();
51  }
52 };
53 
54 TEST_F(ChannelCredsRegistryTest, DefaultCreds) {
55  // Default creds.
56  EXPECT_TRUE(CoreConfiguration::Get().channel_creds_registry().IsSupported(
57  "google_default"));
58  EXPECT_TRUE(CoreConfiguration::Get().channel_creds_registry().IsSupported(
59  "insecure"));
61  CoreConfiguration::Get().channel_creds_registry().IsSupported("fake"));
62 
63  // Non-default creds.
64  EXPECT_EQ(
65  CoreConfiguration::Get().channel_creds_registry().CreateChannelCreds(
66  "test", Json()),
67  nullptr);
68  EXPECT_EQ(
69  CoreConfiguration::Get().channel_creds_registry().CreateChannelCreds(
70  "", Json()),
71  nullptr);
72 }
73 
74 TEST_F(ChannelCredsRegistryTest, Register) {
75  // Before registration.
77  CoreConfiguration::Get().channel_creds_registry().IsSupported("test"));
78  EXPECT_EQ(
79  CoreConfiguration::Get().channel_creds_registry().CreateChannelCreds(
80  "test", Json()),
81  nullptr);
82 
83  // Registration.
87  builder->channel_creds_registry()->RegisterChannelCredsFactory(
88  absl::make_unique<TestChannelCredsFactory>());
89  });
90 
91  RefCountedPtr<grpc_channel_credentials> test_cred(
92  CoreConfiguration::Get().channel_creds_registry().CreateChannelCreds(
93  "test", Json()));
95  CoreConfiguration::Get().channel_creds_registry().IsSupported("test"));
96  EXPECT_NE(test_cred.get(), nullptr);
97 }
98 
99 } // namespace
100 } // namespace testing
101 } // namespace grpc_core
102 
103 int main(int argc, char** argv) {
104  ::testing::InitGoogleTest(&argc, argv);
105  grpc::testing::TestEnvironment env(&argc, argv);
106  grpc_init();
107  auto result = RUN_ALL_TESTS();
108  return result;
109 }
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1970
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
testing
Definition: aws_request_signer_test.cc:25
cleanup.Json
Json
Definition: cleanup.py:49
fake_credentials.h
core_configuration.h
generate.env
env
Definition: generate.py:37
grpc_core
Definition: call_metric_recorder.h:31
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
grpc_core::testing::TEST_F
TEST_F(ServiceConfigTest, ErrorCheck1)
Definition: service_config_test.cc:192
channel_creds_registry.h
testing::Test
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:402
main
int main(int argc, char **argv)
Definition: channel_creds_registry_test.cc:103
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
grpc_core::CoreConfiguration::BuildSpecialConfiguration
static void BuildSpecialConfiguration(BuildFunc build)
Definition: core_configuration.h:100
profile_analyzer.builder
builder
Definition: profile_analyzer.py:159
grpc_core::CoreConfiguration::Get
static const CoreConfiguration & Get()
Definition: core_configuration.h:82
Json
JSON (JavaScript Object Notation).
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:227
EXPECT_NE
#define EXPECT_NE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2028
grpc.h
grpc_fake_transport_security_credentials_create
grpc_channel_credentials * grpc_fake_transport_security_credentials_create()
Definition: fake_credentials.cc:79
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
test_config.h
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc_core::BuildCoreConfiguration
void BuildCoreConfiguration(CoreConfiguration::Builder *builder)
Definition: grpc_plugin_registry.cc:109
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
grpc_core::CoreConfiguration::Reset
static void Reset()
Definition: core_configuration.cc:96
Builder
struct Builder Builder
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:68
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1967
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146


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