aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--test/cpp/util/create_test_channel.cc29
-rw-r--r--test/cpp/util/create_test_channel.h8
2 files changed, 25 insertions, 12 deletions
diff --git a/test/cpp/util/create_test_channel.cc b/test/cpp/util/create_test_channel.cc
index 68f6244a53..0b1b628e5e 100644
--- a/test/cpp/util/create_test_channel.cc
+++ b/test/cpp/util/create_test_channel.cc
@@ -44,22 +44,26 @@ namespace grpc {
// create channel. Otherwise, connect to server and override hostname if
// override_hostname is provided.
// When ssl is not enabled, override_hostname is ignored.
-// Set use_prod_root to true to use the SSL root for production GFE. Otherwise,
-// root for test SSL cert will be used.
+// Set use_prod_root to true to use the SSL root for connecting google.
+// Otherwise, root for test SSL cert will be used.
+// creds will be used to create a channel when enable_ssl is true.
// Use examples:
-// CreateTestChannel("1.1.1.1:12345", "override.hostname.com", true, false);
-// CreateTestChannel("test.google.com:443", "", true, true);
-// CreateTestChannel("", "test.google.com:443", true, true); // same as above
+// CreateTestChannel(
+// "1.1.1.1:12345", "override.hostname.com", true, false, creds);
+// CreateTestChannel("test.google.com:443", "", true, true, creds);
+// same as above
+// CreateTestChannel("", "test.google.com:443", true, true, creds);
std::shared_ptr<ChannelInterface> CreateTestChannel(
const grpc::string& server, const grpc::string& override_hostname,
- bool enable_ssl, bool use_prod_roots) {
+ bool enable_ssl, bool use_prod_roots,
+ const std::unique_ptr<Credentials>& creds) {
ChannelArguments channel_args;
if (enable_ssl) {
const char* roots_certs =
use_prod_roots ? prod_roots_certs : test_root_cert;
SslCredentialsOptions ssl_opts = {roots_certs, "", ""};
- std::unique_ptr<Credentials> creds =
+ std::unique_ptr<Credentials> channel_creds =
CredentialsFactory::SslCredentials(ssl_opts);
if (!server.empty() && !override_hostname.empty()) {
@@ -67,12 +71,21 @@ std::shared_ptr<ChannelInterface> CreateTestChannel(
}
const grpc::string& connect_to =
server.empty() ? override_hostname : server;
- return CreateChannel(connect_to, creds, channel_args);
+ if (creds.get()) {
+ channel_creds = CredentialsFactory::ComposeCredentials(creds, channel_creds);
+ }
+ return CreateChannel(connect_to, channel_creds, channel_args);
} else {
return CreateChannel(server, channel_args);
}
}
+std::shared_ptr<ChannelInterface> CreateTestChannel(
+ const grpc::string& server, const grpc::string& override_hostname,
+ bool enable_ssl, bool use_prod_roots) {
+ return CreateTestChannel(server, override_hostname, enable_ssl, use_prod_roots, std::unique_ptr<Credentials>());
+}
+
// Shortcut for end2end and interop tests.
std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server,
bool enable_ssl) {
diff --git a/test/cpp/util/create_test_channel.h b/test/cpp/util/create_test_channel.h
index 17b519ecb0..4019820eaa 100644
--- a/test/cpp/util/create_test_channel.h
+++ b/test/cpp/util/create_test_channel.h
@@ -41,10 +41,6 @@
namespace grpc {
class ChannelInterface;
-std::shared_ptr<ChannelInterface> CreateTestChannel(
- const grpc::string& server, const grpc::string& override_hostname,
- bool enable_ssl);
-
std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server,
bool enable_ssl);
@@ -52,6 +48,10 @@ std::shared_ptr<ChannelInterface> CreateTestChannel(
const grpc::string& server, const grpc::string& override_hostname,
bool enable_ssl, bool use_prod_roots);
+std::shared_ptr<ChannelInterface> CreateTestChannel(
+ const grpc::string& server, const grpc::string& override_hostname,
+ bool enable_ssl, bool use_prod_roots, const std::unique_ptr<Credentials>& creds);
+
} // namespace grpc
#endif // __GRPCPP_TEST_UTIL_CREATE_TEST_CHANNEL_H_