diff options
author | yang-g <yangg@google.com> | 2016-11-23 10:55:03 -0800 |
---|---|---|
committer | yang-g <yangg@google.com> | 2016-11-23 10:55:03 -0800 |
commit | a7ef49bf6a4392afaf0d4db9922ae703092b6e55 (patch) | |
tree | 2f2528d04ab660b31a3a2859a8a8b21c141be894 /test | |
parent | 71b275bc10558107cd41448a8c8ce96d1d1dd79c (diff) |
Support custom credential type in interop
Diffstat (limited to 'test')
-rw-r--r-- | test/cpp/interop/client.cc | 1 | ||||
-rw-r--r-- | test/cpp/interop/client_helper.cc | 9 | ||||
-rw-r--r-- | test/cpp/interop/interop_server.cc | 1 | ||||
-rw-r--r-- | test/cpp/interop/server_helper.cc | 6 | ||||
-rw-r--r-- | test/cpp/interop/stress_test.cc | 1 | ||||
-rw-r--r-- | test/cpp/util/create_test_channel.cc | 14 | ||||
-rw-r--r-- | test/cpp/util/create_test_channel.h | 4 |
7 files changed, 33 insertions, 3 deletions
diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index c58910abc3..3265554444 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 6380c10800..91564e5dce 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 8b50ae8c05..bc6dc07454 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 af3171bf13..8c359628f7 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 fc35db5233..af707d3190 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 4512193fdd..ad62e03490 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 4ff666dc1b..ce71a97edb 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 |