aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/end2end
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-05-19 22:20:57 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-05-19 22:20:57 -0700
commit037d8700a7be5576e5904d0ec7992fcde53ed364 (patch)
treed5f77fac4fb45657d90fdc0f512b83dd602bf7de /test/cpp/end2end
parent2dea0c1cc9a5f44780e4439f9f4e98646b93cd7f (diff)
parentaa253c37ec5fb6bdf24174be65519f958aba2b27 (diff)
Merge github.com:grpc/grpc into we-dont-need-no-backup
Diffstat (limited to 'test/cpp/end2end')
-rw-r--r--test/cpp/end2end/end2end_test.cc112
1 files changed, 104 insertions, 8 deletions
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index f35b16fe55..76271c3e1d 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -33,11 +33,13 @@
#include <thread>
+#include "src/core/security/credentials.h"
+#include "src/cpp/server/thread_pool.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
#include "test/cpp/util/echo_duplicate.grpc.pb.h"
#include "test/cpp/util/echo.grpc.pb.h"
-#include "src/cpp/server/thread_pool.h"
+#include "test/cpp/util/fake_credentials.h"
#include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
@@ -106,6 +108,16 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
} else {
EXPECT_FALSE(context->IsCancelled());
}
+
+ if (request->has_param() && request->param().echo_metadata()) {
+ const std::multimap<grpc::string, grpc::string>& client_metadata =
+ context->client_metadata();
+ for (std::multimap<grpc::string, grpc::string>::const_iterator iter =
+ client_metadata.begin();
+ iter != client_metadata.end(); ++iter) {
+ context->AddTrailingMetadata((*iter).first, (*iter).second);
+ }
+ }
return Status::OK;
}
@@ -180,7 +192,7 @@ class End2endTest : public ::testing::Test {
// Setup server
ServerBuilder builder;
builder.AddListeningPort(server_address_.str(),
- InsecureServerCredentials());
+ FakeTransportSecurityServerCredentials());
builder.RegisterService(&service_);
builder.SetMaxMessageSize(
kMaxMessageSize_); // For testing max message size.
@@ -192,8 +204,9 @@ class End2endTest : public ::testing::Test {
void TearDown() GRPC_OVERRIDE { server_->Shutdown(); }
void ResetStub() {
- std::shared_ptr<ChannelInterface> channel = CreateChannel(
- server_address_.str(), InsecureCredentials(), ChannelArguments());
+ std::shared_ptr<ChannelInterface> channel =
+ CreateChannel(server_address_.str(), FakeTransportSecurityCredentials(),
+ ChannelArguments());
stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel));
}
@@ -404,8 +417,9 @@ TEST_F(End2endTest, BidiStream) {
// Talk to the two services with the same name but different package names.
// The two stubs are created on the same channel.
TEST_F(End2endTest, DiffPackageServices) {
- std::shared_ptr<ChannelInterface> channel = CreateChannel(
- server_address_.str(), InsecureCredentials(), ChannelArguments());
+ std::shared_ptr<ChannelInterface> channel =
+ CreateChannel(server_address_.str(), FakeTransportSecurityCredentials(),
+ ChannelArguments());
EchoRequest request;
EchoResponse response;
@@ -429,7 +443,7 @@ TEST_F(End2endTest, DiffPackageServices) {
// rpc and stream should fail on bad credentials.
TEST_F(End2endTest, BadCredentials) {
- std::unique_ptr<Credentials> bad_creds = ServiceAccountCredentials("", "", 1);
+ std::shared_ptr<Credentials> bad_creds = ServiceAccountCredentials("", "", 1);
EXPECT_EQ(nullptr, bad_creds.get());
std::shared_ptr<ChannelInterface> channel =
CreateChannel(server_address_.str(), bad_creds, ChannelArguments());
@@ -438,7 +452,7 @@ TEST_F(End2endTest, BadCredentials) {
EchoRequest request;
EchoResponse response;
ClientContext context;
- grpc::string msg("hello");
+ request.set_message("Hello");
Status s = stub->Echo(&context, request, &response);
EXPECT_EQ("", response.message());
@@ -588,6 +602,88 @@ TEST_F(End2endTest, RpcMaxMessageSize) {
EXPECT_FALSE(s.IsOk());
}
+bool MetadataContains(const std::multimap<grpc::string, grpc::string>& metadata,
+ const grpc::string& key, const grpc::string& value) {
+ int count = 0;
+
+ for (std::multimap<grpc::string, grpc::string>::const_iterator iter =
+ metadata.begin();
+ iter != metadata.end(); ++iter) {
+ if ((*iter).first == key && (*iter).second == value) {
+ count++;
+ }
+ }
+ return count == 1;
+}
+
+TEST_F(End2endTest, SetPerCallCredentials) {
+ ResetStub();
+ EchoRequest request;
+ EchoResponse response;
+ ClientContext context;
+ std::shared_ptr<Credentials> creds =
+ IAMCredentials("fake_token", "fake_selector");
+ context.set_credentials(creds);
+ request.set_message("Hello");
+ request.mutable_param()->set_echo_metadata(true);
+
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_EQ(request.message(), response.message());
+ EXPECT_TRUE(s.IsOk());
+ EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(),
+ GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY,
+ "fake_token"));
+ EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(),
+ GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY,
+ "fake_selector"));
+}
+
+TEST_F(End2endTest, InsecurePerCallCredentials) {
+ ResetStub();
+ EchoRequest request;
+ EchoResponse response;
+ ClientContext context;
+ std::shared_ptr<Credentials> creds = InsecureCredentials();
+ context.set_credentials(creds);
+ request.set_message("Hello");
+ request.mutable_param()->set_echo_metadata(true);
+
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_EQ(StatusCode::CANCELLED, s.code());
+ EXPECT_EQ("Failed to set credentials to rpc.", s.details());
+}
+
+TEST_F(End2endTest, OverridePerCallCredentials) {
+ ResetStub();
+ EchoRequest request;
+ EchoResponse response;
+ ClientContext context;
+ std::shared_ptr<Credentials> creds1 =
+ IAMCredentials("fake_token1", "fake_selector1");
+ context.set_credentials(creds1);
+ std::shared_ptr<Credentials> creds2 =
+ IAMCredentials("fake_token2", "fake_selector2");
+ context.set_credentials(creds2);
+ request.set_message("Hello");
+ request.mutable_param()->set_echo_metadata(true);
+
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(),
+ GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY,
+ "fake_token2"));
+ EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(),
+ GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY,
+ "fake_selector2"));
+ EXPECT_FALSE(MetadataContains(context.GetServerTrailingMetadata(),
+ GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY,
+ "fake_token1"));
+ EXPECT_FALSE(MetadataContains(context.GetServerTrailingMetadata(),
+ GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY,
+ "fake_selector1"));
+ EXPECT_EQ(request.message(), response.message());
+ EXPECT_TRUE(s.IsOk());
+}
+
} // namespace testing
} // namespace grpc