diff options
author | Yihua Zhang <yihuaz@google.com> | 2018-04-20 08:50:45 -0700 |
---|---|---|
committer | Yihua Zhang <yihuaz@google.com> | 2018-04-20 08:50:45 -0700 |
commit | 0dcbb83420e25b657249878606bbef9c53f09ea3 (patch) | |
tree | f4864ac186a6c2d2c62b1ad19d546724fcd8ec9f | |
parent | 2a6f47354391af2514310ff06d44a26354cc07fb (diff) |
add alts to interop tests
-rw-r--r-- | test/cpp/interop/client.cc | 2 | ||||
-rw-r--r-- | test/cpp/interop/client_helper.cc | 5 | ||||
-rw-r--r-- | test/cpp/interop/http2_client.cc | 2 | ||||
-rw-r--r-- | test/cpp/interop/interop_server.cc | 2 | ||||
-rw-r--r-- | test/cpp/interop/reconnect_interop_client.cc | 6 | ||||
-rw-r--r-- | test/cpp/interop/server_helper.cc | 3 | ||||
-rw-r--r-- | test/cpp/interop/stress_test.cc | 10 | ||||
-rw-r--r-- | test/cpp/util/create_test_channel.cc | 26 | ||||
-rw-r--r-- | test/cpp/util/create_test_channel.h | 16 | ||||
-rw-r--r-- | test/cpp/util/test_credentials_provider.cc | 6 | ||||
-rw-r--r-- | test/cpp/util/test_credentials_provider.h | 2 |
11 files changed, 56 insertions, 24 deletions
diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index ca8ee3de06..3eb155ef95 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -31,6 +31,8 @@ #include "test/cpp/interop/interop_client.h" #include "test/cpp/util/test_config.h" +DEFINE_bool(use_alts, false, + "Whether to use alts. Enable alts will disable 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"); diff --git a/test/cpp/interop/client_helper.cc b/test/cpp/interop/client_helper.cc index 4041f95abc..29b5a1ed6c 100644 --- a/test/cpp/interop/client_helper.cc +++ b/test/cpp/interop/client_helper.cc @@ -35,6 +35,7 @@ #include "test/cpp/util/create_test_channel.h" #include "test/cpp/util/test_credentials_provider.h" +DECLARE_bool(use_alts); DECLARE_bool(use_tls); DECLARE_string(custom_credentials_type); DECLARE_bool(use_test_ca); @@ -103,8 +104,10 @@ std::shared_ptr<Channel> CreateChannelForTestCase( GPR_ASSERT(creds); } if (FLAGS_custom_credentials_type.empty()) { + transport_security security_type = + FLAGS_use_alts ? ALTS : (FLAGS_use_tls ? TLS : INSECURE); return CreateTestChannel(host_port, FLAGS_server_host_override, - FLAGS_use_tls, !FLAGS_use_test_ca, creds); + security_type, !FLAGS_use_test_ca, creds); } else { return CreateTestChannel(host_port, FLAGS_custom_credentials_type, creds); } diff --git a/test/cpp/interop/http2_client.cc b/test/cpp/interop/http2_client.cc index 821815c6e8..543f159265 100644 --- a/test/cpp/interop/http2_client.cc +++ b/test/cpp/interop/http2_client.cc @@ -194,7 +194,7 @@ int main(int argc, char** argv) { snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), FLAGS_server_port); std::shared_ptr<grpc::Channel> channel = - grpc::CreateTestChannel(host_port, false); + grpc::CreateTestChannel(host_port, grpc::testing::INSECURE); GPR_ASSERT(channel->WaitForConnected(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(300, GPR_TIMESPAN)))); grpc::testing::Http2Client client(channel); diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 5fa1a336da..6526e0535b 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -38,6 +38,8 @@ #include "test/cpp/interop/server_helper.h" #include "test/cpp/util/test_config.h" +DEFINE_bool(use_alts, false, + "Whether to use alts. Enable alts will disable 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."); diff --git a/test/cpp/interop/reconnect_interop_client.cc b/test/cpp/interop/reconnect_interop_client.cc index 9a451fa3f2..8a071d417e 100644 --- a/test/cpp/interop/reconnect_interop_client.cc +++ b/test/cpp/interop/reconnect_interop_client.cc @@ -44,9 +44,11 @@ using grpc::ClientContext; using grpc::CreateTestChannel; using grpc::Status; using grpc::testing::Empty; +using grpc::testing::INSECURE; using grpc::testing::ReconnectInfo; using grpc::testing::ReconnectParams; using grpc::testing::ReconnectService; +using grpc::testing::TLS; int main(int argc, char** argv) { grpc::testing::InitTest(&argc, &argv, true); @@ -57,7 +59,7 @@ int main(int argc, char** argv) { server_address << FLAGS_server_host << ':' << FLAGS_server_control_port; std::unique_ptr<ReconnectService::Stub> control_stub( ReconnectService::NewStub( - CreateTestChannel(server_address.str(), false))); + CreateTestChannel(server_address.str(), INSECURE))); ClientContext start_context; ReconnectParams reconnect_params; reconnect_params.set_max_reconnect_backoff_ms(FLAGS_max_reconnect_backoff_ms); @@ -75,7 +77,7 @@ int main(int argc, char** argv) { FLAGS_max_reconnect_backoff_ms); } std::shared_ptr<Channel> retry_channel = - CreateTestChannel(server_address.str(), "foo.test.google.fr", true, false, + CreateTestChannel(server_address.str(), "foo.test.google.fr", TLS, false, std::shared_ptr<CallCredentials>(), channel_args); // About 13 retries. diff --git a/test/cpp/interop/server_helper.cc b/test/cpp/interop/server_helper.cc index 93ffd52560..2194521998 100644 --- a/test/cpp/interop/server_helper.cc +++ b/test/cpp/interop/server_helper.cc @@ -26,6 +26,7 @@ #include "src/core/lib/surface/call_test_only.h" #include "test/cpp/util/test_credentials_provider.h" +DECLARE_bool(use_alts); DECLARE_bool(use_tls); DECLARE_string(custom_credentials_type); @@ -36,6 +37,8 @@ std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() { if (!FLAGS_custom_credentials_type.empty()) { return GetCredentialsProvider()->GetServerCredentials( FLAGS_custom_credentials_type); + } else if (FLAGS_use_alts) { + return GetCredentialsProvider()->GetServerCredentials(kAltsCredentialsType); } else if (FLAGS_use_tls) { return GetCredentialsProvider()->GetServerCredentials(kTlsCredentialsType); } else { diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc index 6e8134a83b..023e0c8f0b 100644 --- a/test/cpp/interop/stress_test.cc +++ b/test/cpp/interop/stress_test.cc @@ -99,18 +99,24 @@ 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_alts, false, + "Whether to use alts. Enable alts will disable tls."); DEFINE_bool(use_tls, false, "Whether to use tls."); DEFINE_bool(use_test_ca, false, "False to use SSL roots for google"); DEFINE_string(server_host_override, "foo.test.google.fr", "Override the server host which is sent in HTTP header"); +using grpc::testing::ALTS; +using grpc::testing::INSECURE; using grpc::testing::MetricsService; using grpc::testing::MetricsServiceImpl; using grpc::testing::StressTestInteropClient; +using grpc::testing::TLS; using grpc::testing::TestCaseType; using grpc::testing::UNKNOWN_TEST; using grpc::testing::WeightedRandomTestSelector; using grpc::testing::kTestCaseList; +using grpc::testing::transport_security; static int log_level = GPR_LOG_SEVERITY_DEBUG; @@ -268,6 +274,8 @@ int main(int argc, char** argv) { int thread_idx = 0; int server_idx = -1; char buffer[256]; + transport_security security_type = + FLAGS_use_alts ? ALTS : (FLAGS_use_tls ? TLS : INSECURE); for (auto it = server_addresses.begin(); it != server_addresses.end(); it++) { ++server_idx; // Create channel(s) for each server @@ -276,7 +284,7 @@ int main(int argc, char** argv) { gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(), channel_idx); std::shared_ptr<grpc::Channel> channel = grpc::CreateTestChannel( - *it, FLAGS_server_host_override, FLAGS_use_tls, !FLAGS_use_test_ca); + *it, FLAGS_server_host_override, security_type, !FLAGS_use_test_ca); // Create stub(s) for each channel for (int stub_idx = 0; stub_idx < FLAGS_num_stubs_per_channel; diff --git a/test/cpp/util/create_test_channel.cc b/test/cpp/util/create_test_channel.cc index 1047d44627..0bcd4dbc84 100644 --- a/test/cpp/util/create_test_channel.cc +++ b/test/cpp/util/create_test_channel.cc @@ -107,37 +107,37 @@ std::shared_ptr<Channel> CreateTestChannel( std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, - bool enable_ssl, bool use_prod_roots, + testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args) { - grpc::string type; - if (enable_ssl) { - type = testing::kTlsCredentialsType; - } - + grpc::string type = + security_type == testing::ALTS + ? testing::kAltsCredentialsType + : (security_type == testing::TLS ? testing::kTlsCredentialsType + : testing::kInsecureCredentialsType); return CreateTestChannel(server, type, override_hostname, use_prod_roots, creds, args); } std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, - bool enable_ssl, bool use_prod_roots, + testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds) { - return CreateTestChannel(server, override_hostname, enable_ssl, + return CreateTestChannel(server, override_hostname, security_type, use_prod_roots, creds, ChannelArguments()); } std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, - bool enable_ssl, bool use_prod_roots) { - return CreateTestChannel(server, override_hostname, enable_ssl, + testing::transport_security security_type, bool use_prod_roots) { + return CreateTestChannel(server, override_hostname, security_type, use_prod_roots, std::shared_ptr<CallCredentials>()); } // Shortcut for end2end and interop tests. -std::shared_ptr<Channel> CreateTestChannel(const grpc::string& server, - bool enable_ssl) { - return CreateTestChannel(server, "foo.test.google.fr", enable_ssl, false); +std::shared_ptr<Channel> CreateTestChannel( + const grpc::string& server, testing::transport_security security_type) { + return CreateTestChannel(server, "foo.test.google.fr", security_type, false); } std::shared_ptr<Channel> CreateTestChannel( diff --git a/test/cpp/util/create_test_channel.h b/test/cpp/util/create_test_channel.h index ddaa99f43e..c615fb7653 100644 --- a/test/cpp/util/create_test_channel.h +++ b/test/cpp/util/create_test_channel.h @@ -26,21 +26,27 @@ namespace grpc { class Channel; -std::shared_ptr<Channel> CreateTestChannel(const grpc::string& server, - bool enable_ssl); +namespace testing { + +typedef enum { INSECURE = 0, TLS, ALTS } transport_security; + +} // namespace testing + +std::shared_ptr<Channel> CreateTestChannel( + const grpc::string& server, testing::transport_security security_type); std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, - bool enable_ssl, bool use_prod_roots); + testing::transport_security security_type, bool use_prod_roots); std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, - bool enable_ssl, bool use_prod_roots, + testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds); std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, - bool enable_ssl, bool use_prod_roots, + testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args); diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc index 76561007c4..c8b0ac73f4 100644 --- a/test/cpp/util/test_credentials_provider.cc +++ b/test/cpp/util/test_credentials_provider.cc @@ -56,6 +56,9 @@ class DefaultCredentialsProvider : public CredentialsProvider { const grpc::string& type, ChannelArguments* args) override { if (type == grpc::testing::kInsecureCredentialsType) { return InsecureChannelCredentials(); + } else if (type == grpc::testing::kAltsCredentialsType) { + grpc::experimental::AltsCredentialsOptions alts_opts; + return grpc::experimental::AltsCredentials(alts_opts); } else if (type == grpc::testing::kTlsCredentialsType) { SslCredentialsOptions ssl_opts = {test_root_cert, "", ""}; args->SetSslTargetNameOverride("foo.test.google.fr"); @@ -77,6 +80,9 @@ class DefaultCredentialsProvider : public CredentialsProvider { const grpc::string& type) override { if (type == grpc::testing::kInsecureCredentialsType) { return InsecureServerCredentials(); + } else if (type == grpc::testing::kAltsCredentialsType) { + grpc::experimental::AltsServerCredentialsOptions alts_opts; + return grpc::experimental::AltsServerCredentials(alts_opts); } else if (type == grpc::testing::kTlsCredentialsType) { SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key, test_server1_cert}; diff --git a/test/cpp/util/test_credentials_provider.h b/test/cpp/util/test_credentials_provider.h index f489a2c563..b1d69e893d 100644 --- a/test/cpp/util/test_credentials_provider.h +++ b/test/cpp/util/test_credentials_provider.h @@ -29,10 +29,10 @@ namespace grpc { namespace testing { const char kInsecureCredentialsType[] = "INSECURE_CREDENTIALS"; - // For real credentials, like tls/ssl, this name should match the AuthContext // property "transport_security_type". const char kTlsCredentialsType[] = "ssl"; +const char kAltsCredentialsType[] = "alts"; // Provide test credentials of a particular type. class CredentialTypeProvider { |