Merge pull request #15127 from yihuazhang/kokoro_alts_test

Add ALTS to interop tests
pull/15150/head
yihuaz 7 years ago committed by GitHub
commit d100b5cfba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      test/cpp/interop/client.cc
  2. 5
      test/cpp/interop/client_helper.cc
  3. 2
      test/cpp/interop/http2_client.cc
  4. 2
      test/cpp/interop/interop_server.cc
  5. 6
      test/cpp/interop/reconnect_interop_client.cc
  6. 3
      test/cpp/interop/server_helper.cc
  7. 10
      test/cpp/interop/stress_test.cc
  8. 26
      test/cpp/util/create_test_channel.cc
  9. 16
      test/cpp/util/create_test_channel.h
  10. 6
      test/cpp/util/test_credentials_provider.cc
  11. 2
      test/cpp/util/test_credentials_provider.h

@ -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");

@ -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);
}

@ -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);

@ -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.");

@ -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.

@ -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 {

@ -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;

@ -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(

@ -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);

@ -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};

@ -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 {

Loading…
Cancel
Save