make CreateTestChannel support additional credentials besides ssl

pull/209/head
Yang Gao 10 years ago
parent 94e97ef2c5
commit 02ce729ce2
  1. 29
      test/cpp/util/create_test_channel.cc
  2. 8
      test/cpp/util/create_test_channel.h

@ -44,22 +44,26 @@ namespace grpc {
// create channel. Otherwise, connect to server and override hostname if // create channel. Otherwise, connect to server and override hostname if
// override_hostname is provided. // override_hostname is provided.
// When ssl is not enabled, override_hostname is ignored. // When ssl is not enabled, override_hostname is ignored.
// Set use_prod_root to true to use the SSL root for production GFE. Otherwise, // Set use_prod_root to true to use the SSL root for connecting google.
// root for test SSL cert will be used. // Otherwise, root for test SSL cert will be used.
// creds will be used to create a channel when enable_ssl is true.
// Use examples: // Use examples:
// CreateTestChannel("1.1.1.1:12345", "override.hostname.com", true, false); // CreateTestChannel(
// CreateTestChannel("test.google.com:443", "", true, true); // "1.1.1.1:12345", "override.hostname.com", true, false, creds);
// CreateTestChannel("", "test.google.com:443", true, true); // same as above // CreateTestChannel("test.google.com:443", "", true, true, creds);
// same as above
// CreateTestChannel("", "test.google.com:443", true, true, creds);
std::shared_ptr<ChannelInterface> CreateTestChannel( std::shared_ptr<ChannelInterface> CreateTestChannel(
const grpc::string& server, const grpc::string& override_hostname, 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; ChannelArguments channel_args;
if (enable_ssl) { if (enable_ssl) {
const char* roots_certs = const char* roots_certs =
use_prod_roots ? prod_roots_certs : test_root_cert; use_prod_roots ? prod_roots_certs : test_root_cert;
SslCredentialsOptions ssl_opts = {roots_certs, "", ""}; SslCredentialsOptions ssl_opts = {roots_certs, "", ""};
std::unique_ptr<Credentials> creds = std::unique_ptr<Credentials> channel_creds =
CredentialsFactory::SslCredentials(ssl_opts); CredentialsFactory::SslCredentials(ssl_opts);
if (!server.empty() && !override_hostname.empty()) { if (!server.empty() && !override_hostname.empty()) {
@ -67,12 +71,21 @@ std::shared_ptr<ChannelInterface> CreateTestChannel(
} }
const grpc::string& connect_to = const grpc::string& connect_to =
server.empty() ? override_hostname : server; 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 { } else {
return CreateChannel(server, channel_args); 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. // Shortcut for end2end and interop tests.
std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server, std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server,
bool enable_ssl) { bool enable_ssl) {

@ -41,10 +41,6 @@
namespace grpc { namespace grpc {
class ChannelInterface; 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, std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server,
bool enable_ssl); bool enable_ssl);
@ -52,6 +48,10 @@ std::shared_ptr<ChannelInterface> CreateTestChannel(
const grpc::string& server, const grpc::string& override_hostname, const grpc::string& server, const grpc::string& override_hostname,
bool enable_ssl, bool use_prod_roots); 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 } // namespace grpc
#endif // __GRPCPP_TEST_UTIL_CREATE_TEST_CHANNEL_H_ #endif // __GRPCPP_TEST_UTIL_CREATE_TEST_CHANNEL_H_

Loading…
Cancel
Save