xds_credentials_end2end_test.cc
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2020 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 
19 #include <gmock/gmock.h>
20 #include <gtest/gtest.h>
21 
22 #include <grpc/grpc.h>
23 #include <grpcpp/server_builder.h>
24 
25 #include "test/core/util/port.h"
29 
30 namespace grpc {
31 namespace testing {
32 namespace {
33 
34 class XdsCredentialsEnd2EndFallbackTest
35  : public ::testing::TestWithParam<const char*> {
36  protected:
37  XdsCredentialsEnd2EndFallbackTest() {
39  ServerBuilder builder;
40  server_address_ = "localhost:" + std::to_string(port);
41  builder.AddListeningPort(
43  GetCredentialsProvider()->GetServerCredentials(GetParam()));
44  builder.RegisterService(&service_);
45  server_ = builder.BuildAndStart();
46  }
47 
50  std::unique_ptr<Server> server_;
51 };
52 
53 TEST_P(XdsCredentialsEnd2EndFallbackTest, NoXdsSchemeInTarget) {
54  // Target does not use 'xds:///' scheme and should result in using fallback
55  // credentials.
56  ChannelArguments args;
60  GetCredentialsProvider()->GetChannelCredentials(GetParam(), &args)),
61  args);
62  auto stub = grpc::testing::EchoTestService::NewStub(channel);
63  ClientContext ctx;
64  EchoRequest req;
65  req.set_message("Hello");
66  EchoResponse resp;
67  Status s = stub->Echo(&ctx, req, &resp);
68  EXPECT_EQ(s.ok(), true);
69  EXPECT_EQ(resp.message(), "Hello");
70 }
71 
72 class XdsServerCredentialsEnd2EndFallbackTest
73  : public ::testing::TestWithParam<const char*> {
74  protected:
75  XdsServerCredentialsEnd2EndFallbackTest() {
77  // Build a server that is not xDS enabled but uses XdsServerCredentials.
78  ServerBuilder builder;
79  server_address_ = "localhost:" + std::to_string(port);
80  builder.AddListeningPort(
83  GetCredentialsProvider()->GetServerCredentials(GetParam())));
84  builder.RegisterService(&service_);
85  server_ = builder.BuildAndStart();
86  }
87 
90  std::unique_ptr<Server> server_;
91 };
92 
93 TEST_P(XdsServerCredentialsEnd2EndFallbackTest, Basic) {
94  ChannelArguments args;
97  GetCredentialsProvider()->GetChannelCredentials(GetParam(), &args), args);
98  auto stub = grpc::testing::EchoTestService::NewStub(channel);
99  ClientContext ctx;
100  EchoRequest req;
101  req.set_message("Hello");
102  EchoResponse resp;
103  Status s = stub->Echo(&ctx, req, &resp);
104  EXPECT_EQ(s.ok(), true);
105  EXPECT_EQ(resp.message(), "Hello");
106 }
107 
108 INSTANTIATE_TEST_SUITE_P(XdsCredentialsEnd2EndFallback,
109  XdsCredentialsEnd2EndFallbackTest,
110  ::testing::ValuesIn(std::vector<const char*>(
112 
113 INSTANTIATE_TEST_SUITE_P(XdsServerCredentialsEnd2EndFallback,
114  XdsServerCredentialsEnd2EndFallbackTest,
115  ::testing::ValuesIn(std::vector<const char*>(
117 
118 } // namespace
119 } // namespace testing
120 } // namespace grpc
121 
122 int main(int argc, char** argv) {
123  ::testing::InitGoogleTest(&argc, argv);
124  grpc::testing::TestEnvironment env(&argc, argv);
125  const auto result = RUN_ALL_TESTS();
126  return result;
127 }
test_credentials_provider.h
grpc::testing::kTlsCredentialsType
const char kTlsCredentialsType[]
Definition: test_credentials_provider.h:34
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
testing
Definition: aws_request_signer_test.cc:25
port.h
ctx
Definition: benchmark-async.c:30
generate.env
env
Definition: generate.py:37
grpc
Definition: grpcpp/alarm.h:33
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
ctx
static struct test_ctx ctx
Definition: test-ipc-send-recv.c:65
absl::FormatConversionChar::s
@ s
grpc::XdsServerCredentials
std::shared_ptr< ServerCredentials > XdsServerCredentials(const std::shared_ptr< ServerCredentials > &fallback_credentials)
Builds Xds ServerCredentials given fallback credentials.
Definition: xds_server_credentials.cc:30
async_greeter_client.stub
stub
Definition: hellostreamingworld/async_greeter_client.py:26
server_address_
std::string server_address_
Definition: xds_credentials_end2end_test.cc:48
test_service_impl.h
testing::TestWithParam
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1883
main
int main(int argc, char **argv)
Definition: xds_credentials_end2end_test.cc:122
grpc::testing::kInsecureCredentialsType
const char kInsecureCredentialsType[]
Definition: test_credentials_provider.h:31
profile_analyzer.builder
builder
Definition: profile_analyzer.py:159
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
req
static uv_connect_t req
Definition: test-connection-fail.c:30
service_
TestServiceImpl service_
Definition: xds_credentials_end2end_test.cc:49
http2_server_health_check.resp
resp
Definition: http2_server_health_check.py:31
grpc.h
grpc::testing::INSTANTIATE_TEST_SUITE_P
INSTANTIATE_TEST_SUITE_P(HistogramTestCases, HistogramTest, ::testing::Range< int >(0, GRPC_STATS_HISTOGRAM_COUNT))
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
grpc_pick_unused_port_or_die
int grpc_pick_unused_port_or_die(void)
tests.unit._exit_scenarios.port
port
Definition: _exit_scenarios.py:179
test_config.h
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc::testing::GetCredentialsProvider
CredentialsProvider * GetCredentialsProvider()
Definition: test_credentials_provider.cc:169
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
grpc::CreateCustomChannel
std::shared_ptr< Channel > CreateCustomChannel(const grpc::string &target, const std::shared_ptr< ChannelCredentials > &creds, const ChannelArguments &args)
grpc::protobuf::util::Status
GRPC_CUSTOM_UTIL_STATUS Status
Definition: include/grpcpp/impl/codegen/config_protobuf.h:93
server_
std::unique_ptr< Server > server_
Definition: xds_credentials_end2end_test.cc:50
grpc::XdsCredentials
std::shared_ptr< ChannelCredentials > XdsCredentials(const std::shared_ptr< ChannelCredentials > &fallback_creds)
Builds XDS Credentials.
Definition: cpp/client/xds_credentials.cc:30
grpc::testing::EXPECT_EQ
EXPECT_EQ(options.token_exchange_service_uri, "https://foo/exchange")
grpc::testing::TEST_P
TEST_P(HistogramTest, IncHistogram)
Definition: stats_test.cc:87
testing::ValuesIn
internal::ParamGenerator< typename std::iterator_traits< ForwardIterator >::value_type > ValuesIn(ForwardIterator begin, ForwardIterator end)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-param-test.h:297
to_string
static bool to_string(zval *from)
Definition: protobuf/php/ext/google/protobuf/convert.c:333
TestServiceImpl
Definition: interop_server.cc:139
server_builder.h


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:58