aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/end2end
diff options
context:
space:
mode:
authorGravatar Hongwei Wang <hongweiw@google.com>2015-08-03 12:29:18 -0700
committerGravatar Hongwei Wang <hongweiw@google.com>2015-08-03 12:29:18 -0700
commit72538b9103cb6c7d841ecfee2aa071609b3d322b (patch)
treed45cce9ba12cabcdb7b7a4e2f861032cd24ddb25 /test/cpp/end2end
parenteace1904de2cefef8cd32ba2439a518b961a1061 (diff)
parentbee7b68b54ae379b89424fd207dfa47ec68f87a7 (diff)
Merge branch 'master' of https://github.com/grpc/grpc into zookeeper
Diffstat (limited to 'test/cpp/end2end')
-rw-r--r--test/cpp/end2end/end2end_test.cc29
1 files changed, 28 insertions, 1 deletions
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index 5b351c169e..f39c6cf82a 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -93,6 +93,15 @@ void CheckServerAuthContext(const ServerContext* context) {
EXPECT_TRUE(auth_ctx->GetPeerIdentity().empty());
}
+bool CheckIsLocalhost(const grpc::string& addr) {
+ const grpc::string kIpv6("ipv6:[::1]:");
+ const grpc::string kIpv4MappedIpv6("ipv6:[::ffff:127.0.0.1]:");
+ const grpc::string kIpv4("ipv4:127.0.0.1:");
+ return addr.substr(0, kIpv4.size()) == kIpv4 ||
+ addr.substr(0, kIpv4MappedIpv6.size()) == kIpv4MappedIpv6 ||
+ addr.substr(0, kIpv6.size()) == kIpv6;
+}
+
} // namespace
class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
@@ -148,6 +157,9 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
response->set_message(
grpc::string(request->param().response_message_length(), '\0'));
}
+ if (request->has_param() && request->param().echo_peer()) {
+ response->mutable_param()->set_peer(context->peer());
+ }
return Status::OK;
}
@@ -236,7 +248,7 @@ class End2endTest : public ::testing::Test {
void SetUp() GRPC_OVERRIDE {
int port = grpc_pick_unused_port_or_die();
- server_address_ << "localhost:" << port;
+ server_address_ << "127.0.0.1:" << port;
// Setup server
ServerBuilder builder;
SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key,
@@ -818,6 +830,21 @@ TEST_F(End2endTest, HugeResponse) {
EXPECT_TRUE(s.ok());
}
+TEST_F(End2endTest, Peer) {
+ ResetStub();
+ EchoRequest request;
+ EchoResponse response;
+ request.set_message("hello");
+ request.mutable_param()->set_echo_peer(true);
+
+ ClientContext context;
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_EQ(response.message(), request.message());
+ EXPECT_TRUE(s.ok());
+ EXPECT_TRUE(CheckIsLocalhost(response.param().peer()));
+ EXPECT_TRUE(CheckIsLocalhost(context.peer()));
+}
+
} // namespace testing
} // namespace grpc