Skip to content
Snippets Groups Projects
Commit a7ef49bf authored by yang-g's avatar yang-g
Browse files

Support custom credential type in interop

parent 71b275bc
No related branches found
No related tags found
No related merge requests found
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "test/cpp/util/test_config.h" #include "test/cpp/util/test_config.h"
DEFINE_bool(use_tls, false, "Whether to use tls."); 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_bool(use_test_ca, false, "False to use SSL roots for google");
DEFINE_int32(server_port, 0, "Server port."); DEFINE_int32(server_port, 0, "Server port.");
DEFINE_string(server_host, "127.0.0.1", "Server host to connect to"); DEFINE_string(server_host, "127.0.0.1", "Server host to connect to");
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#include "test/cpp/util/test_credentials_provider.h" #include "test/cpp/util/test_credentials_provider.h"
DECLARE_bool(use_tls); DECLARE_bool(use_tls);
DECLARE_string(custom_credentials_type);
DECLARE_bool(use_test_ca); DECLARE_bool(use_test_ca);
DECLARE_int32(server_port); DECLARE_int32(server_port);
DECLARE_string(server_host); DECLARE_string(server_host);
...@@ -115,8 +116,12 @@ std::shared_ptr<Channel> CreateChannelForTestCase( ...@@ -115,8 +116,12 @@ std::shared_ptr<Channel> CreateChannelForTestCase(
creds = AccessTokenCredentials(raw_token); creds = AccessTokenCredentials(raw_token);
GPR_ASSERT(creds); GPR_ASSERT(creds);
} }
return CreateTestChannel(host_port, FLAGS_server_host_override, FLAGS_use_tls, if (FLAGS_custom_credentials_type.empty()) {
!FLAGS_use_test_ca, creds); 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 } // namespace testing
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "test/cpp/util/test_config.h" #include "test/cpp/util/test_config.h"
DEFINE_bool(use_tls, false, "Whether to use tls."); 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(port, 0, "Server port.");
DEFINE_int32(max_send_message_size, -1, "The maximum send message size."); DEFINE_int32(max_send_message_size, -1, "The maximum send message size.");
......
...@@ -42,12 +42,16 @@ ...@@ -42,12 +42,16 @@
#include "test/cpp/util/test_credentials_provider.h" #include "test/cpp/util/test_credentials_provider.h"
DECLARE_bool(use_tls); DECLARE_bool(use_tls);
DECLARE_string(custom_credentials_type);
namespace grpc { namespace grpc {
namespace testing { namespace testing {
std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() { 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); return GetCredentialsProvider()->GetServerCredentials(kTlsCredentialsType);
} else { } else {
return GetCredentialsProvider()->GetServerCredentials( return GetCredentialsProvider()->GetServerCredentials(
......
...@@ -147,6 +147,7 @@ DEFINE_bool(do_not_abort_on_transient_failures, true, ...@@ -147,6 +147,7 @@ DEFINE_bool(do_not_abort_on_transient_failures, true,
// Options from client.cc (for compatibility with interop test). // Options from client.cc (for compatibility with interop test).
// TODO(sreek): Consolidate overlapping options // TODO(sreek): Consolidate overlapping options
DEFINE_bool(use_tls, false, "Whether to use tls."); 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_bool(use_test_ca, false, "False to use SSL roots for google");
DEFINE_int32(server_port, 0, "Server port."); DEFINE_int32(server_port, 0, "Server port.");
DEFINE_string(server_host, "127.0.0.1", "Server host to connect to"); DEFINE_string(server_host, "127.0.0.1", "Server host to connect to");
......
...@@ -135,4 +135,18 @@ std::shared_ptr<Channel> CreateTestChannel(const grpc::string& server, ...@@ -135,4 +135,18 @@ std::shared_ptr<Channel> CreateTestChannel(const grpc::string& server,
return CreateTestChannel(server, "foo.test.google.fr", enable_ssl, false); 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 } // namespace grpc
...@@ -59,6 +59,10 @@ std::shared_ptr<Channel> CreateTestChannel( ...@@ -59,6 +59,10 @@ std::shared_ptr<Channel> CreateTestChannel(
const std::shared_ptr<CallCredentials>& creds, const std::shared_ptr<CallCredentials>& creds,
const ChannelArguments& args); 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 } // namespace grpc
#endif // GRPC_TEST_CPP_UTIL_CREATE_TEST_CHANNEL_H #endif // GRPC_TEST_CPP_UTIL_CREATE_TEST_CHANNEL_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment