aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2015-07-06 23:26:58 -0700
committerGravatar yang-g <yangg@google.com>2015-07-06 23:26:58 -0700
commitc4eef2eae89b5eaca5eb60b73811a9cc1f348c80 (patch)
tree9e1a5fcb540d9d2d7942230bb930f9240c780326 /test
parent8068f869747529fe800586bd2a7cb34b0573dcae (diff)
add a test case in end2end_test
Diffstat (limited to 'test')
-rw-r--r--test/cpp/end2end/end2end_test.cc29
-rw-r--r--test/cpp/util/messages.proto1
2 files changed, 30 insertions, 0 deletions
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index 5e850ea30a..d626fc0c94 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -83,6 +83,17 @@ void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request,
}
}
+template <typename T>
+void CheckAuthContext(T* context) {
+ std::unique_ptr<const AuthContext> auth_ctx = context->auth_context();
+ std::vector<grpc::string> fake =
+ auth_ctx->FindPropertyValues("transport_security_type");
+ EXPECT_EQ(1, fake.size());
+ EXPECT_EQ("fake", fake[0]);
+ EXPECT_TRUE(auth_ctx->GetPeerIdentityPropertyName().empty());
+ EXPECT_TRUE(auth_ctx->GetPeerIdentity().empty());
+}
+
} // namespace
class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
@@ -123,6 +134,9 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
context->AddTrailingMetadata((*iter).first, (*iter).second);
}
}
+ if (request->has_param() && request->param().check_auth_context()) {
+ CheckAuthContext(context);
+ }
return Status::OK;
}
@@ -726,6 +740,21 @@ TEST_F(End2endTest, RequestStreamServerEarlyCancelTest) {
EXPECT_EQ(s.error_code(), StatusCode::CANCELLED);
}
+TEST_F(End2endTest, ClientAuthContext) {
+ ResetStub();
+ EchoRequest request;
+ EchoResponse response;
+ request.set_message("Hello");
+ request.mutable_param()->set_check_auth_context(true);
+
+ ClientContext context;
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_EQ(response.message(), request.message());
+ EXPECT_TRUE(s.ok());
+
+ CheckAuthContext(&context);
+}
+
} // namespace testing
} // namespace grpc
diff --git a/test/cpp/util/messages.proto b/test/cpp/util/messages.proto
index 062f66c091..3940e70c9f 100644
--- a/test/cpp/util/messages.proto
+++ b/test/cpp/util/messages.proto
@@ -37,6 +37,7 @@ message RequestParams {
optional int32 client_cancel_after_us = 2;
optional int32 server_cancel_after_us = 3;
optional bool echo_metadata = 4;
+ optional bool check_auth_context = 5;
}
message EchoRequest {