diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index c58910abc3fb5a3e5827be04ee90b435ae02ea9c..3265554444b9af68986713abeb5287f0dc9744f5 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -49,6 +49,7 @@ #include "test/cpp/util/test_config.h" DEFINE_bool(use_tls, false, "Whether to use tls."); +DEFINE_string(custom_credentials_type, "", "User provided credentials type."); DEFINE_bool(use_test_ca, false, "False to use SSL roots for google"); DEFINE_int32(server_port, 0, "Server port."); DEFINE_string(server_host, "127.0.0.1", "Server host to connect to"); diff --git a/test/cpp/interop/client_helper.cc b/test/cpp/interop/client_helper.cc index 6380c10800b4e113eb51a67d9e7914606ed27f2a..91564e5dcefbb71c1f50a9d6f6deb97715f5ff5a 100644 --- a/test/cpp/interop/client_helper.cc +++ b/test/cpp/interop/client_helper.cc @@ -53,6 +53,7 @@ #include "test/cpp/util/test_credentials_provider.h" DECLARE_bool(use_tls); +DECLARE_string(custom_credentials_type); DECLARE_bool(use_test_ca); DECLARE_int32(server_port); DECLARE_string(server_host); @@ -115,8 +116,12 @@ std::shared_ptr<Channel> CreateChannelForTestCase( creds = AccessTokenCredentials(raw_token); GPR_ASSERT(creds); } - return CreateTestChannel(host_port, FLAGS_server_host_override, FLAGS_use_tls, - !FLAGS_use_test_ca, creds); + if (FLAGS_custom_credentials_type.empty()) { + return CreateTestChannel(host_port, FLAGS_server_host_override, + FLAGS_use_tls, !FLAGS_use_test_ca, creds); + } else { + return CreateTestChannel(host_port, FLAGS_custom_credentials_type, creds); + } } } // namespace testing diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 8b50ae8c05a67da4c436d9baa79bbed09384a6ee..bc6dc0745418d78e2039ee42e2f7bd7fddb79a1f 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -56,6 +56,7 @@ #include "test/cpp/util/test_config.h" DEFINE_bool(use_tls, false, "Whether to use tls."); +DEFINE_string(custom_credentials_type, "", "User provided credentials type."); DEFINE_int32(port, 0, "Server port."); DEFINE_int32(max_send_message_size, -1, "The maximum send message size."); diff --git a/test/cpp/interop/server_helper.cc b/test/cpp/interop/server_helper.cc index af3171bf13cd98effe6452aaf4a16e5455e5c06a..8c359628f777230001b12bd671f35a5c5c665e36 100644 --- a/test/cpp/interop/server_helper.cc +++ b/test/cpp/interop/server_helper.cc @@ -42,12 +42,16 @@ #include "test/cpp/util/test_credentials_provider.h" DECLARE_bool(use_tls); +DECLARE_string(custom_credentials_type); namespace grpc { namespace testing { std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() { - if (FLAGS_use_tls) { + if (FLAGS_custom_credentials_type.empty()) { + return GetCredentialsProvider()->GetServerCredentials( + FLAGS_custom_credentials_type); + } else if (FLAGS_use_tls) { return GetCredentialsProvider()->GetServerCredentials(kTlsCredentialsType); } else { return GetCredentialsProvider()->GetServerCredentials( diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc index fc35db5233ab0b07296df15f3433e372bad5e5d2..af707d319053d0b9e74081db698a9985aa233d8e 100644 --- a/test/cpp/interop/stress_test.cc +++ b/test/cpp/interop/stress_test.cc @@ -147,6 +147,7 @@ DEFINE_bool(do_not_abort_on_transient_failures, true, // Options from client.cc (for compatibility with interop test). // TODO(sreek): Consolidate overlapping options DEFINE_bool(use_tls, false, "Whether to use tls."); +DEFINE_string(custom_credentials_type, "", "User provided credentials type."); DEFINE_bool(use_test_ca, false, "False to use SSL roots for google"); DEFINE_int32(server_port, 0, "Server port."); DEFINE_string(server_host, "127.0.0.1", "Server host to connect to"); diff --git a/test/cpp/util/create_test_channel.cc b/test/cpp/util/create_test_channel.cc index 4512193fddfd4f3299fab68b00ce78ee8d1e46fa..ad62e03490e359501e2fa1a1dab1662ba34f5391 100644 --- a/test/cpp/util/create_test_channel.cc +++ b/test/cpp/util/create_test_channel.cc @@ -135,4 +135,18 @@ std::shared_ptr<Channel> CreateTestChannel(const grpc::string& server, return CreateTestChannel(server, "foo.test.google.fr", enable_ssl, false); } +std::shared_ptr<Channel> CreateTestChannel( + const grpc::string& server, const grpc::string& credential_type, + const std::shared_ptr<CallCredentials>& creds) { + ChannelArguments channel_args; + std::shared_ptr<ChannelCredentials> channel_creds = + testing::GetCredentialsProvider()->GetChannelCredentials(credential_type, + &channel_args); + GPR_ASSERT(channel_creds != nullptr); + if (creds.get()) { + channel_creds = CompositeChannelCredentials(channel_creds, creds); + } + return CreateCustomChannel(server, channel_creds, channel_args); +} + } // namespace grpc diff --git a/test/cpp/util/create_test_channel.h b/test/cpp/util/create_test_channel.h index 4ff666dc1bc43b48cf6eb75ca55e7684d86a0319..ce71a97edbbf6b08d3bd5beb024a5dd20230b132 100644 --- a/test/cpp/util/create_test_channel.h +++ b/test/cpp/util/create_test_channel.h @@ -59,6 +59,10 @@ std::shared_ptr<Channel> CreateTestChannel( const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args); +std::shared_ptr<Channel> CreateTestChannel( + const grpc::string& server, const grpc::string& credential_type, + const std::shared_ptr<CallCredentials>& creds); + } // namespace grpc #endif // GRPC_TEST_CPP_UTIL_CREATE_TEST_CHANNEL_H