From edc506849f3429c6b4a6d90ec604aeb1b7b0eb54 Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Wed, 22 May 2019 15:24:33 -0700 Subject: [PATCH 1/2] Expose interop test for others --- src/proto/grpc/testing/BUILD | 25 ++++++++----- test/cpp/interop/BUILD | 21 ++++++++++- test/cpp/util/BUILD | 1 + test/cpp/util/test_credentials_provider.cc | 43 ++++++++++++++++++++-- 4 files changed, 76 insertions(+), 14 deletions(-) diff --git a/src/proto/grpc/testing/BUILD b/src/proto/grpc/testing/BUILD index 727c99cf99c..212f0f3cca7 100644 --- a/src/proto/grpc/testing/BUILD +++ b/src/proto/grpc/testing/BUILD @@ -18,11 +18,17 @@ load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_package") load("@grpc_python_dependencies//:requirements.bzl", "requirement") load("//bazel:python_rules.bzl", "py_proto_library") -grpc_package(name = "testing", visibility = "public") +grpc_package( + name = "testing", + visibility = "public", +) exports_files([ "echo.proto", "echo_messages.proto", + "test.proto", + "empty.proto", + "messages.proto", ]) grpc_proto_library( @@ -50,9 +56,11 @@ grpc_proto_library( grpc_proto_library( name = "echo_proto", srcs = ["echo.proto"], - deps = ["echo_messages_proto", - "simple_messages_proto"], generate_mocks = True, + deps = [ + "echo_messages_proto", + "simple_messages_proto", + ], ) grpc_proto_library( @@ -102,7 +110,7 @@ grpc_proto_library( name = "benchmark_service_proto", srcs = ["benchmark_service.proto"], deps = [ - "messages_proto", + "messages_proto", ], ) @@ -110,7 +118,7 @@ grpc_proto_library( name = "report_qps_scenario_service_proto", srcs = ["report_qps_scenario_service.proto"], deps = [ - "control_proto", + "control_proto", ], ) @@ -118,7 +126,7 @@ grpc_proto_library( name = "worker_service_proto", srcs = ["worker_service.proto"], deps = [ - "control_proto", + "control_proto", ], ) @@ -134,7 +142,7 @@ grpc_proto_library( has_services = False, deps = [ "//src/proto/grpc/core:stats_proto", - ] + ], ) grpc_proto_library( @@ -190,6 +198,5 @@ py_proto_library( name = "py_test_proto", deps = [ ":test_proto_descriptor", - ] + ], ) - diff --git a/test/cpp/interop/BUILD b/test/cpp/interop/BUILD index 6cf4719c17b..802302bc8bf 100644 --- a/test/cpp/interop/BUILD +++ b/test/cpp/interop/BUILD @@ -16,7 +16,10 @@ licenses(["notice"]) # Apache v2 load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_cc_binary", "grpc_package") -grpc_package(name = "test/cpp/interop") +grpc_package( + name = "test/cpp/interop", + visibility = "public", +) grpc_cc_library( name = "server_helper_lib", @@ -103,6 +106,20 @@ grpc_cc_binary( ], ) +grpc_cc_binary( + name = "metrics_client", + srcs = ["metrics_client.cc"], + external_deps = [ + "gflags", + ], + language = "C++", + deps = [ + "//:grpc++", + "//test/cpp/util:metrics_server_lib", + "//test/cpp/util:test_config", + ], +) + grpc_cc_binary( name = "reconnect_interop_client", srcs = [ @@ -153,6 +170,7 @@ grpc_cc_test( external_deps = [ "gflags", ], + tags = ["no_windows"], deps = [ "//:gpr", "//:grpc", @@ -161,5 +179,4 @@ grpc_cc_test( "//test/cpp/util:test_config", "//test/cpp/util:test_util", ], - tags = ["no_windows"], ) diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD index bb1ca868ffb..d112611ef35 100644 --- a/test/cpp/util/BUILD +++ b/test/cpp/util/BUILD @@ -75,6 +75,7 @@ grpc_cc_library( "test_credentials_provider.h", ], external_deps = [ + "gflags", "protobuf", ], deps = [ diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc index 455f94e33d4..41779327cb9 100644 --- a/test/cpp/util/test_credentials_provider.cc +++ b/test/cpp/util/test_credentials_provider.cc @@ -19,21 +19,50 @@ #include "test/cpp/util/test_credentials_provider.h" +#include +#include +#include + #include #include +#include #include #include #include #include "test/core/end2end/data/ssl_test_data.h" +DEFINE_string(tls_cert_file, "", "The TLS cert file used when --use_tls=true"); +DEFINE_string(tls_key_file, "", "The TLS key file used when --use_tls=true"); + namespace grpc { namespace testing { namespace { +grpc::string ReadFile(const grpc::string& src_path) { + std::ifstream src; + src.open(src_path, std::ifstream::in | std::ifstream::binary); + + grpc::string contents; + src.seekg(0, std::ios::end); + contents.reserve(src.tellg()); + src.seekg(0, std::ios::beg); + contents.assign((std::istreambuf_iterator(src)), + (std::istreambuf_iterator())); + return contents; +} + class DefaultCredentialsProvider : public CredentialsProvider { public: + DefaultCredentialsProvider() { + if (!FLAGS_tls_key_file.empty()) { + custom_server_key_ = ReadFile(FLAGS_tls_key_file); + } + if (!FLAGS_tls_cert_file.empty()) { + custom_server_cert_ = ReadFile(FLAGS_tls_cert_file); + } + } ~DefaultCredentialsProvider() override {} void AddSecureType( @@ -87,11 +116,17 @@ class DefaultCredentialsProvider : public CredentialsProvider { 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}; SslServerCredentialsOptions ssl_opts; ssl_opts.pem_root_certs = ""; - ssl_opts.pem_key_cert_pairs.push_back(pkcp); + if (!custom_server_key_.empty() && !custom_server_cert_.empty()) { + SslServerCredentialsOptions::PemKeyCertPair pkcp = {custom_server_key_, + custom_server_cert_}; + ssl_opts.pem_key_cert_pairs.push_back(pkcp); + } else { + SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key, + test_server1_cert}; + ssl_opts.pem_key_cert_pairs.push_back(pkcp); + } return SslServerCredentials(ssl_opts); } else { std::unique_lock lock(mu_); @@ -121,6 +156,8 @@ class DefaultCredentialsProvider : public CredentialsProvider { std::vector added_secure_type_names_; std::vector> added_secure_type_providers_; + grpc::string custom_server_key_; + grpc::string custom_server_cert_; }; CredentialsProvider* g_provider = nullptr; From bd2756e482b90df42bc3f60105cb06841331aad9 Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Tue, 28 May 2019 15:39:53 -0700 Subject: [PATCH 2/2] Fix format --- test/cpp/util/test_credentials_provider.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc index 41779327cb9..fd796372c8c 100644 --- a/test/cpp/util/test_credentials_provider.cc +++ b/test/cpp/util/test_credentials_provider.cc @@ -119,8 +119,8 @@ class DefaultCredentialsProvider : public CredentialsProvider { SslServerCredentialsOptions ssl_opts; ssl_opts.pem_root_certs = ""; if (!custom_server_key_.empty() && !custom_server_cert_.empty()) { - SslServerCredentialsOptions::PemKeyCertPair pkcp = {custom_server_key_, - custom_server_cert_}; + SslServerCredentialsOptions::PemKeyCertPair pkcp = { + custom_server_key_, custom_server_cert_}; ssl_opts.pem_key_cert_pairs.push_back(pkcp); } else { SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key,