aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-02-22 22:29:51 -0800
committerGravatar Craig Tiller <ctiller@google.com>2016-02-22 22:29:51 -0800
commit70ab4c5cef079518f5b5a6a7e4b45e3d0f61c6f1 (patch)
tree91b5028c4a2b6dd0f2798f13ac48515800e373d2 /test
parent023759216c4efa34440deb2e7516d1cc9e5b278f (diff)
parent914a2e7217e3376dfbd69fa37008d6d60f797689 (diff)
Merge github.com:grpc/grpc into fix-proto-docker
Diffstat (limited to 'test')
-rw-r--r--test/core/census/mlog_test.c (renamed from test/core/census/log_test.c)2
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c26
-rw-r--r--test/core/iomgr/timer_list_test.c31
-rw-r--r--test/cpp/end2end/async_end2end_test.cc44
-rw-r--r--test/cpp/end2end/end2end_test.cc69
-rw-r--r--test/cpp/interop/client.cc8
-rw-r--r--test/cpp/interop/interop_client.cc72
-rw-r--r--test/cpp/interop/interop_client.h3
-rw-r--r--test/cpp/interop/server.cc35
-rw-r--r--test/cpp/util/test_credentials_provider.cc82
-rw-r--r--test/cpp/util/test_credentials_provider.h63
11 files changed, 365 insertions, 70 deletions
diff --git a/test/core/census/log_test.c b/test/core/census/mlog_test.c
index b68ca11504..5b6c5946ab 100644
--- a/test/core/census/log_test.c
+++ b/test/core/census/mlog_test.c
@@ -31,7 +31,7 @@
*
*/
-#include "src/core/census/log.h"
+#include "src/core/census/mlog.h"
#include <grpc/support/cpu.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index 9725d8a3b6..b57478059f 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -45,6 +45,7 @@
#include "src/core/iomgr/iomgr.h"
#include "src/core/iomgr/socket_utils_posix.h"
+#include "src/core/iomgr/timer.h"
#include "test/core/util/test_config.h"
static grpc_pollset_set g_pollset_set;
@@ -125,11 +126,13 @@ void test_succeeds(void) {
gpr_now(GPR_CLOCK_MONOTONIC),
GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5));
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
}
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+
+ grpc_exec_ctx_finish(&exec_ctx);
}
void test_fails(void) {
@@ -159,14 +162,18 @@ void test_fails(void) {
/* wait for the connection callback to finish */
while (g_connections_complete == connections_complete_before) {
grpc_pollset_worker worker;
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), test_deadline());
+ gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
+ gpr_timespec polling_deadline = test_deadline();
+ if (!grpc_timer_check(&exec_ctx, now, &polling_deadline)) {
+ grpc_pollset_work(&exec_ctx, &g_pollset, &worker, now, polling_deadline);
+ }
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
}
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ grpc_exec_ctx_finish(&exec_ctx);
}
void test_times_out(void) {
@@ -243,15 +250,18 @@ void test_times_out(void) {
GPR_ASSERT(g_connections_complete ==
connections_complete_before + is_after_deadline);
}
- grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10));
+ gpr_timespec polling_deadline = GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10);
+ if (!grpc_timer_check(&exec_ctx, now, &polling_deadline)) {
+ grpc_pollset_work(&exec_ctx, &g_pollset, &worker, now, polling_deadline);
+ }
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
}
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ grpc_exec_ctx_finish(&exec_ctx);
+
close(svr_fd);
for (i = 0; i < NUM_CLIENT_CONNECTS; ++i) {
close(client_fd[i]);
diff --git a/test/core/iomgr/timer_list_test.c b/test/core/iomgr/timer_list_test.c
index 15de87c5a1..7a21fdd5c1 100644
--- a/test/core/iomgr/timer_list_test.c
+++ b/test/core/iomgr/timer_list_test.c
@@ -35,7 +35,6 @@
#include <string.h>
-#include "src/core/iomgr/timer_internal.h"
#include <grpc/support/log.h>
#include "test/core/util/test_config.h"
@@ -72,20 +71,19 @@ static void add_test(void) {
}
/* collect timers. Only the first batch should be ready. */
- GPR_ASSERT(10 == grpc_timer_check(&exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(
- 500, GPR_TIMESPAN)),
- NULL));
+ GPR_ASSERT(grpc_timer_check(
+ &exec_ctx, gpr_time_add(start, gpr_time_from_millis(500, GPR_TIMESPAN)),
+ NULL));
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 20; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 10));
GPR_ASSERT(cb_called[i][0] == 0);
}
- GPR_ASSERT(0 == grpc_timer_check(&exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(
- 600, GPR_TIMESPAN)),
- NULL));
+ GPR_ASSERT(!grpc_timer_check(
+ &exec_ctx,
+ gpr_time_add(start, gpr_time_from_millis(600, GPR_TIMESPAN)),
+ NULL));
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 10));
@@ -93,20 +91,19 @@ static void add_test(void) {
}
/* collect the rest of the timers */
- GPR_ASSERT(10 == grpc_timer_check(
- &exec_ctx, gpr_time_add(start, gpr_time_from_millis(
- 1500, GPR_TIMESPAN)),
- NULL));
+ GPR_ASSERT(grpc_timer_check(
+ &exec_ctx, gpr_time_add(start, gpr_time_from_millis(1500, GPR_TIMESPAN)),
+ NULL));
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 20));
GPR_ASSERT(cb_called[i][0] == 0);
}
- GPR_ASSERT(0 == grpc_timer_check(&exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(
- 1600, GPR_TIMESPAN)),
- NULL));
+ GPR_ASSERT(!grpc_timer_check(
+ &exec_ctx,
+ gpr_time_add(start, gpr_time_from_millis(1600, GPR_TIMESPAN)),
+ NULL));
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 20));
GPR_ASSERT(cb_called[i][0] == 0);
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index a194c615cd..9ca3bf98f8 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -43,6 +43,7 @@
#include <grpc/grpc.h>
#include <grpc/support/thd.h>
#include <grpc/support/time.h>
+#include <grpc/support/tls.h>
#include <gtest/gtest.h>
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
@@ -59,6 +60,8 @@ using grpc::testing::EchoRequest;
using grpc::testing::EchoResponse;
using std::chrono::system_clock;
+GPR_TLS_DECL(g_is_async_end2end_test);
+
namespace grpc {
namespace testing {
@@ -67,9 +70,11 @@ namespace {
void* tag(int i) { return (void*)(intptr_t)i; }
#ifdef GPR_POSIX_SOCKET
-static int assert_non_blocking_poll(struct pollfd* pfds, nfds_t nfds,
- int timeout) {
- GPR_ASSERT(timeout == 0);
+static int maybe_assert_non_blocking_poll(struct pollfd* pfds, nfds_t nfds,
+ int timeout) {
+ if (gpr_tls_get(&g_is_async_end2end_test)) {
+ GPR_ASSERT(timeout == 0);
+ }
return poll(pfds, nfds, timeout);
}
@@ -86,21 +91,21 @@ class PollOverride {
grpc_poll_function_type prev_;
};
-class PollingCheckRegion : public PollOverride {
+class PollingOverrider : public PollOverride {
public:
- explicit PollingCheckRegion(bool allow_blocking)
- : PollOverride(allow_blocking ? poll : assert_non_blocking_poll) {}
+ explicit PollingOverrider(bool allow_blocking)
+ : PollOverride(allow_blocking ? poll : maybe_assert_non_blocking_poll) {}
};
#else
-class PollingCheckRegion {
+class PollingOverrider {
public:
- explicit PollingCheckRegion(bool allow_blocking) {}
+ explicit PollingOverrider(bool allow_blocking) {}
};
#endif
-class Verifier : public PollingCheckRegion {
+class Verifier {
public:
- explicit Verifier(bool spin) : PollingCheckRegion(!spin), spin_(spin) {}
+ explicit Verifier(bool spin) : spin_(spin) {}
Verifier& Expect(int i, bool expect_ok) {
expectations_[tag(i)] = expect_ok;
return *this;
@@ -183,6 +188,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> {
AsyncEnd2endTest() {}
void SetUp() GRPC_OVERRIDE {
+ poll_overrider_.reset(new PollingOverrider(!GetParam()));
+
int port = grpc_pick_unused_port_or_die();
server_address_ << "localhost:" << port;
@@ -193,6 +200,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> {
builder.RegisterService(&service_);
cq_ = builder.AddCompletionQueue();
server_ = builder.BuildAndStart();
+
+ gpr_tls_set(&g_is_async_end2end_test, 1);
}
void TearDown() GRPC_OVERRIDE {
@@ -202,6 +211,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> {
cq_->Shutdown();
while (cq_->Next(&ignored_tag, &ignored_ok))
;
+ poll_overrider_.reset();
+ gpr_tls_set(&g_is_async_end2end_test, 0);
}
void ResetStub() {
@@ -249,6 +260,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> {
std::unique_ptr<Server> server_;
grpc::testing::EchoTestService::AsyncService service_;
std::ostringstream server_address_;
+
+ std::unique_ptr<PollingOverrider> poll_overrider_;
};
TEST_P(AsyncEnd2endTest, SimpleRpc) {
@@ -976,6 +989,10 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
if (server_try_cancel == CANCEL_AFTER_PROCESSING) {
ServerTryCancel(&srv_ctx);
+
+ // Client reads may fail bacause it is notified that the stream is
+ // cancelled.
+ ignore_cq_result = true;
}
// Client attemts to read the three messages from the server
@@ -1087,7 +1104,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
Verifier(GetParam()).Expect(7, true).Verify(cq_.get());
// This is expected to fail in all cases i.e for all values of
- // server_try_cancel. This is becasue at this point, either there are no
+ // server_try_cancel. This is because at this point, either there are no
// more msgs from the client (because client called WritesDone) or the RPC
// is cancelled on the server
srv_stream.Read(&recv_request, tag(8));
@@ -1164,6 +1181,9 @@ INSTANTIATE_TEST_CASE_P(AsyncEnd2endServerTryCancel,
int main(int argc, char** argv) {
grpc_test_init(argc, argv);
+ gpr_tls_init(&g_is_async_end2end_test);
::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
+ int ret = RUN_ALL_TESTS();
+ gpr_tls_destroy(&g_is_async_end2end_test);
+ return ret;
}
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index c8523847ab..ce8e4d2a10 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -51,11 +51,11 @@
#include "src/core/security/credentials.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
-#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
#include "test/cpp/end2end/test_service_impl.h"
#include "test/cpp/util/string_ref_helper.h"
+#include "test/cpp/util/test_credentials_provider.h"
using grpc::testing::EchoRequest;
using grpc::testing::EchoResponse;
@@ -191,12 +191,14 @@ class TestServiceImplDupPkg
class TestScenario {
public:
- TestScenario(bool proxy, bool tls) : use_proxy(proxy), use_tls(tls) {}
+ TestScenario(bool proxy, const grpc::string& creds_type)
+ : use_proxy(proxy), credentials_type(creds_type) {}
void Log() const {
- gpr_log(GPR_INFO, "Scenario: proxy %d, tls %d", use_proxy, use_tls);
+ gpr_log(GPR_INFO, "Scenario: proxy %d, credentials %s", use_proxy,
+ credentials_type.c_str());
}
bool use_proxy;
- bool use_tls;
+ const grpc::string credentials_type;
};
class End2endTest : public ::testing::TestWithParam<TestScenario> {
@@ -220,14 +222,8 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> {
server_address_ << "127.0.0.1:" << port;
// Setup server
ServerBuilder builder;
- auto server_creds = InsecureServerCredentials();
- if (GetParam().use_tls) {
- 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);
- server_creds = SslServerCredentials(ssl_opts);
+ auto server_creds = GetServerCredentials(GetParam().credentials_type);
+ if (GetParam().credentials_type != kInsecureCredentialsType) {
server_creds->SetAuthMetadataProcessor(processor);
}
builder.AddListeningPort(server_address_.str(), server_creds);
@@ -246,12 +242,8 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> {
}
EXPECT_TRUE(is_server_started_);
ChannelArguments args;
- auto channel_creds = InsecureChannelCredentials();
- if (GetParam().use_tls) {
- SslCredentialsOptions ssl_opts = {test_root_cert, "", ""};
- args.SetSslTargetNameOverride("foo.test.google.fr");
- channel_creds = SslCredentials(ssl_opts);
- }
+ auto channel_creds =
+ GetChannelCredentials(GetParam().credentials_type, &args);
if (!user_agent_prefix_.empty()) {
args.SetUserAgentPrefix(user_agent_prefix_);
}
@@ -941,7 +933,7 @@ TEST_P(End2endTest, ChannelState) {
// Takes 10s.
TEST_P(End2endTest, ChannelStateTimeout) {
- if (GetParam().use_tls) {
+ if (GetParam().credentials_type != kInsecureCredentialsType) {
return;
}
int port = grpc_pick_unused_port_or_die();
@@ -1150,7 +1142,7 @@ class SecureEnd2endTest : public End2endTest {
protected:
SecureEnd2endTest() {
GPR_ASSERT(!GetParam().use_proxy);
- GPR_ASSERT(GetParam().use_tls);
+ GPR_ASSERT(GetParam().credentials_type != kInsecureCredentialsType);
}
};
@@ -1373,21 +1365,42 @@ TEST_P(SecureEnd2endTest, ClientAuthContext) {
EXPECT_EQ("*.test.youtube.com", ToString(auth_ctx->GetPeerIdentity()[2]));
}
+std::vector<TestScenario> CreateTestScenarios(bool use_proxy,
+ bool test_insecure,
+ bool test_secure) {
+ std::vector<TestScenario> scenarios;
+ std::vector<grpc::string> credentials_types;
+ if (test_secure) {
+ credentials_types = GetSecureCredentialsTypeList();
+ }
+ if (test_insecure) {
+ credentials_types.push_back(kInsecureCredentialsType);
+ }
+ for (auto it = credentials_types.begin(); it != credentials_types.end();
+ ++it) {
+ scenarios.push_back(TestScenario(false, *it));
+ if (use_proxy) {
+ scenarios.push_back(TestScenario(true, *it));
+ }
+ }
+ return scenarios;
+}
+
INSTANTIATE_TEST_CASE_P(End2end, End2endTest,
- ::testing::Values(TestScenario(false, false),
- TestScenario(false, true)));
+ ::testing::ValuesIn(CreateTestScenarios(false, true,
+ true)));
INSTANTIATE_TEST_CASE_P(End2endServerTryCancel, End2endServerTryCancelTest,
- ::testing::Values(TestScenario(false, false)));
+ ::testing::ValuesIn(CreateTestScenarios(false, true,
+ false)));
INSTANTIATE_TEST_CASE_P(ProxyEnd2end, ProxyEnd2endTest,
- ::testing::Values(TestScenario(false, false),
- TestScenario(false, true),
- TestScenario(true, false),
- TestScenario(true, true)));
+ ::testing::ValuesIn(CreateTestScenarios(true, true,
+ true)));
INSTANTIATE_TEST_CASE_P(SecureEnd2end, SecureEnd2endTest,
- ::testing::Values(TestScenario(false, true)));
+ ::testing::ValuesIn(CreateTestScenarios(false, false,
+ true)));
} // namespace
} // namespace testing
diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc
index cb9b396beb..788adefd24 100644
--- a/test/cpp/interop/client.cc
+++ b/test/cpp/interop/client.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -74,6 +74,7 @@ DEFINE_string(test_case, "large_unary",
"oauth2_auth_token: raw oauth2 access token auth; "
"per_rpc_creds: raw oauth2 access token on a single rpc; "
"status_code_and_message: verify status code & message; "
+ "custom_metadata: server will echo custom metadata;"
"all : all of above.");
DEFINE_string(default_service_account, "",
"Email of GCE default service account");
@@ -129,6 +130,8 @@ int main(int argc, char** argv) {
client.DoPerRpcCreds(json_key);
} else if (FLAGS_test_case == "status_code_and_message") {
client.DoStatusWithMessage();
+ } else if (FLAGS_test_case == "custom_metadata") {
+ client.DoCustomMetadata();
} else if (FLAGS_test_case == "all") {
client.DoEmpty();
client.DoLargeUnary();
@@ -142,6 +145,7 @@ int main(int argc, char** argv) {
client.DoTimeoutOnSleepingServer();
client.DoEmptyStream();
client.DoStatusWithMessage();
+ client.DoCustomMetadata();
// service_account_creds and jwt_token_creds can only run with ssl.
if (FLAGS_use_tls) {
grpc::string json_key = GetServiceAccountJsonKey();
@@ -159,7 +163,7 @@ int main(int argc, char** argv) {
"server_compressed_streaming|half_duplex|ping_pong|cancel_after_begin|"
"cancel_after_first_response|timeout_on_sleeping_server|empty_stream|"
"compute_engine_creds|jwt_token_creds|oauth2_auth_token|per_rpc_creds",
- FLAGS_test_case.c_str());
+ "status_code_and_message|custom_metadata", FLAGS_test_case.c_str());
ret = 1;
}
diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc
index b06310781a..46f6fdac40 100644
--- a/test/cpp/interop/interop_client.cc
+++ b/test/cpp/interop/interop_client.cc
@@ -625,5 +625,77 @@ void InteropClient::DoStatusWithMessage() {
gpr_log(GPR_DEBUG, "Done testing Status and Message");
}
+void InteropClient::DoCustomMetadata() {
+ const grpc::string kEchoInitialMetadataKey("x-grpc-test-echo-initial");
+ const grpc::string kInitialMetadataValue("test_initial_metadata_value");
+ const grpc::string kEchoTrailingBinMetadataKey(
+ "x-grpc-test-echo-trailing-bin");
+ const grpc::string kTrailingBinValue("\x0a\x0b\x0a\x0b\x0a\x0b");
+ ;
+
+ {
+ gpr_log(GPR_DEBUG, "Sending RPC with custom metadata");
+ ClientContext context;
+ context.AddMetadata(kEchoInitialMetadataKey, kInitialMetadataValue);
+ context.AddMetadata(kEchoTrailingBinMetadataKey, kTrailingBinValue);
+ SimpleRequest request;
+ SimpleResponse response;
+ request.set_response_size(kLargeResponseSize);
+ grpc::string payload(kLargeRequestSize, '\0');
+ request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize);
+
+ Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
+ AssertOkOrPrintErrorStatus(s);
+ const auto& server_initial_metadata = context.GetServerInitialMetadata();
+ auto iter = server_initial_metadata.find(kEchoInitialMetadataKey);
+ GPR_ASSERT(iter != server_initial_metadata.end());
+ GPR_ASSERT(iter->second.data() == kInitialMetadataValue);
+ const auto& server_trailing_metadata = context.GetServerTrailingMetadata();
+ iter = server_trailing_metadata.find(kEchoTrailingBinMetadataKey);
+ GPR_ASSERT(iter != server_trailing_metadata.end());
+ GPR_ASSERT(grpc::string(iter->second.begin(), iter->second.end()) ==
+ kTrailingBinValue);
+
+ gpr_log(GPR_DEBUG, "Done testing RPC with custom metadata");
+ }
+
+ {
+ gpr_log(GPR_DEBUG, "Sending stream with custom metadata");
+ ClientContext context;
+ context.AddMetadata(kEchoInitialMetadataKey, kInitialMetadataValue);
+ context.AddMetadata(kEchoTrailingBinMetadataKey, kTrailingBinValue);
+ std::unique_ptr<ClientReaderWriter<StreamingOutputCallRequest,
+ StreamingOutputCallResponse>>
+ stream(serviceStub_.Get()->FullDuplexCall(&context));
+
+ StreamingOutputCallRequest request;
+ request.set_response_type(PayloadType::COMPRESSABLE);
+ ResponseParameters* response_parameter = request.add_response_parameters();
+ response_parameter->set_size(kLargeResponseSize);
+ grpc::string payload(kLargeRequestSize, '\0');
+ request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize);
+ StreamingOutputCallResponse response;
+ GPR_ASSERT(stream->Write(request));
+ stream->WritesDone();
+ GPR_ASSERT(stream->Read(&response));
+ GPR_ASSERT(response.payload().body() ==
+ grpc::string(kLargeResponseSize, '\0'));
+ GPR_ASSERT(!stream->Read(&response));
+ Status s = stream->Finish();
+ AssertOkOrPrintErrorStatus(s);
+ const auto& server_initial_metadata = context.GetServerInitialMetadata();
+ auto iter = server_initial_metadata.find(kEchoInitialMetadataKey);
+ GPR_ASSERT(iter != server_initial_metadata.end());
+ GPR_ASSERT(iter->second.data() == kInitialMetadataValue);
+ const auto& server_trailing_metadata = context.GetServerTrailingMetadata();
+ iter = server_trailing_metadata.find(kEchoTrailingBinMetadataKey);
+ GPR_ASSERT(iter != server_trailing_metadata.end());
+ GPR_ASSERT(grpc::string(iter->second.begin(), iter->second.end()) ==
+ kTrailingBinValue);
+
+ gpr_log(GPR_DEBUG, "Done testing stream with custom metadata");
+ }
+}
+
} // namespace testing
} // namespace grpc
diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h
index 3ecd380398..3f57f3c733 100644
--- a/test/cpp/interop/interop_client.h
+++ b/test/cpp/interop/interop_client.h
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -75,6 +75,7 @@ class InteropClient {
void DoTimeoutOnSleepingServer();
void DoEmptyStream();
void DoStatusWithMessage();
+ void DoCustomMetadata();
// Auth tests.
// username is a string containing the user email
void DoJwtTokenCreds(const grpc::string& username);
diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc
index cdca060c23..18ac35d551 100644
--- a/test/cpp/interop/server.cc
+++ b/test/cpp/interop/server.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -80,6 +80,36 @@ using grpc::Status;
static bool got_sigint = false;
static const char* kRandomFile = "test/cpp/interop/rnd.dat";
+const char kEchoInitialMetadataKey[] = "x-grpc-test-echo-initial";
+const char kEchoTrailingBinMetadataKey[] = "x-grpc-test-echo-trailing-bin";
+const char kEchoUserAgentKey[] = "x-grpc-test-echo-useragent";
+
+void MaybeEchoMetadata(ServerContext* context) {
+ const auto& client_metadata = context->client_metadata();
+ GPR_ASSERT(client_metadata.count(kEchoInitialMetadataKey) <= 1);
+ GPR_ASSERT(client_metadata.count(kEchoTrailingBinMetadataKey) <= 1);
+
+ auto iter = client_metadata.find(kEchoInitialMetadataKey);
+ if (iter != client_metadata.end()) {
+ context->AddInitialMetadata(kEchoInitialMetadataKey, iter->second.data());
+ }
+ iter = client_metadata.find(kEchoTrailingBinMetadataKey);
+ if (iter != client_metadata.end()) {
+ context->AddTrailingMetadata(
+ kEchoTrailingBinMetadataKey,
+ grpc::string(iter->second.begin(), iter->second.end()));
+ }
+ // Check if client sent a magic key in the header that makes us echo
+ // back the user-agent (for testing purpose)
+ iter = client_metadata.find(kEchoUserAgentKey);
+ if (iter != client_metadata.end()) {
+ iter = client_metadata.find("user-agent");
+ if (iter != client_metadata.end()) {
+ context->AddInitialMetadata(kEchoUserAgentKey, iter->second.data());
+ }
+ }
+}
+
bool SetPayload(PayloadType type, int size, Payload* payload) {
PayloadType response_type;
if (type == PayloadType::RANDOM) {
@@ -130,11 +160,13 @@ class TestServiceImpl : public TestService::Service {
public:
Status EmptyCall(ServerContext* context, const grpc::testing::Empty* request,
grpc::testing::Empty* response) {
+ MaybeEchoMetadata(context);
return Status::OK;
}
Status UnaryCall(ServerContext* context, const SimpleRequest* request,
SimpleResponse* response) {
+ MaybeEchoMetadata(context);
SetResponseCompression(context, *request);
if (request->response_size() > 0) {
if (!SetPayload(request->response_type(), request->response_size(),
@@ -192,6 +224,7 @@ class TestServiceImpl : public TestService::Service {
ServerContext* context,
ServerReaderWriter<StreamingOutputCallResponse,
StreamingOutputCallRequest>* stream) {
+ MaybeEchoMetadata(context);
StreamingOutputCallRequest request;
StreamingOutputCallResponse response;
bool write_success = true;
diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc
new file mode 100644
index 0000000000..1086e14258
--- /dev/null
+++ b/test/cpp/util/test_credentials_provider.cc
@@ -0,0 +1,82 @@
+
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/cpp/util/test_credentials_provider.h"
+
+#include "test/core/end2end/data/ssl_test_data.h"
+
+namespace grpc {
+namespace testing {
+
+const char kTlsCredentialsType[] = "TLS_CREDENTIALS";
+
+std::shared_ptr<ChannelCredentials> GetChannelCredentials(
+ const grpc::string& type, ChannelArguments* args) {
+ if (type == kInsecureCredentialsType) {
+ return InsecureChannelCredentials();
+ } else if (type == kTlsCredentialsType) {
+ SslCredentialsOptions ssl_opts = {test_root_cert, "", ""};
+ args->SetSslTargetNameOverride("foo.test.google.fr");
+ return SslCredentials(ssl_opts);
+ } else {
+ gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str());
+ }
+ return nullptr;
+}
+
+std::shared_ptr<ServerCredentials> GetServerCredentials(
+ const grpc::string& type) {
+ if (type == kInsecureCredentialsType) {
+ return InsecureServerCredentials();
+ } else if (type == 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);
+ return SslServerCredentials(ssl_opts);
+ } else {
+ gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str());
+ }
+ return nullptr;
+}
+
+std::vector<grpc::string> GetSecureCredentialsTypeList() {
+ std::vector<grpc::string> types;
+ types.push_back(kTlsCredentialsType);
+ return types;
+}
+
+} // namespace testing
+} // namespace grpc
diff --git a/test/cpp/util/test_credentials_provider.h b/test/cpp/util/test_credentials_provider.h
new file mode 100644
index 0000000000..f7253051a9
--- /dev/null
+++ b/test/cpp/util/test_credentials_provider.h
@@ -0,0 +1,63 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPC_TEST_CPP_UTIL_TEST_CREDENTIALS_PROVIDER_H
+#define GRPC_TEST_CPP_UTIL_TEST_CREDENTIALS_PROVIDER_H
+
+#include <memory>
+
+#include <grpc++/security/credentials.h>
+#include <grpc++/security/server_credentials.h>
+#include <grpc++/support/channel_arguments.h>
+
+namespace grpc {
+namespace testing {
+
+const char kInsecureCredentialsType[] = "INSECURE_CREDENTIALS";
+
+// Provide channel credentials according to the given type. Alter the channel
+// arguments if needed.
+std::shared_ptr<ChannelCredentials> GetChannelCredentials(
+ const grpc::string& type, ChannelArguments* args);
+
+// Provide server credentials according to the given type.
+std::shared_ptr<ServerCredentials> GetServerCredentials(
+ const grpc::string& type);
+
+// Provide a list of secure credentials type.
+std::vector<grpc::string> GetSecureCredentialsTypeList();
+
+} // namespace testing
+} // namespace grpc
+
+#endif // GRPC_TEST_CPP_UTIL_TEST_CREDENTIALS_PROVIDER_H