From b57f72dbeeffee0bdb3f39f470f048a23bdb6a08 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Sun, 17 May 2015 21:54:54 -0700 Subject: [PATCH] resolve comments --- test/cpp/end2end/end2end_test.cc | 19 ++++++++++++++----- test/cpp/util/fake_credentials.cc | 31 +++++-------------------------- test/cpp/util/fake_credentials.h | 4 ++-- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 9017641e30e..76271c3e1dd 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -191,7 +191,8 @@ class End2endTest : public ::testing::Test { server_address_ << "localhost:" << port; // Setup server ServerBuilder builder; - builder.AddListeningPort(server_address_.str(), FakeServerCredentials()); + builder.AddListeningPort(server_address_.str(), + FakeTransportSecurityServerCredentials()); builder.RegisterService(&service_); builder.SetMaxMessageSize( kMaxMessageSize_); // For testing max message size. @@ -203,8 +204,9 @@ class End2endTest : public ::testing::Test { void TearDown() GRPC_OVERRIDE { server_->Shutdown(); } void ResetStub() { - std::shared_ptr channel = CreateChannel( - server_address_.str(), FakeCredentials(), ChannelArguments()); + std::shared_ptr channel = + CreateChannel(server_address_.str(), FakeTransportSecurityCredentials(), + ChannelArguments()); stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel)); } @@ -415,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 channel = CreateChannel( - server_address_.str(), FakeCredentials(), ChannelArguments()); + std::shared_ptr channel = + CreateChannel(server_address_.str(), FakeTransportSecurityCredentials(), + ChannelArguments()); EchoRequest request; EchoResponse response; @@ -671,6 +674,12 @@ TEST_F(End2endTest, OverridePerCallCredentials) { 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()); } diff --git a/test/cpp/util/fake_credentials.cc b/test/cpp/util/fake_credentials.cc index 6b89e2fc968..f5b83b8159f 100644 --- a/test/cpp/util/fake_credentials.cc +++ b/test/cpp/util/fake_credentials.cc @@ -36,39 +36,18 @@ #include #include #include "src/cpp/client/channel.h" +#include "src/cpp/client/secure_credentials.h" #include "src/cpp/server/secure_server_credentials.h" namespace grpc { namespace testing { -namespace { -class FakeCredentialsImpl GRPC_FINAL : public Credentials { - public: - FakeCredentialsImpl() - : c_creds_(grpc_fake_transport_security_credentials_create()) {} - ~FakeCredentialsImpl() { grpc_credentials_release(c_creds_); } - SecureCredentials* AsSecureCredentials() GRPC_OVERRIDE { return nullptr; } - std::shared_ptr CreateChannel( - const grpc::string& target, const ChannelArguments& args) GRPC_OVERRIDE { - grpc_channel_args channel_args; - args.SetChannelArgs(&channel_args); - return std::shared_ptr(new Channel( - target, - grpc_secure_channel_create(c_creds_, target.c_str(), &channel_args))); - } - bool ApplyToCall(grpc_call* call) GRPC_OVERRIDE { return false; } - - private: - grpc_credentials* const c_creds_; -}; - -} // namespace - -std::shared_ptr FakeCredentials() { - return std::shared_ptr(new FakeCredentialsImpl()); +std::shared_ptr FakeTransportSecurityCredentials() { + grpc_credentials* c_creds = grpc_fake_transport_security_credentials_create(); + return std::shared_ptr(new SecureCredentials(c_creds)); } -std::shared_ptr FakeServerCredentials() { +std::shared_ptr FakeTransportSecurityServerCredentials() { grpc_server_credentials* c_creds = grpc_fake_transport_security_server_credentials_create(); return std::shared_ptr( diff --git a/test/cpp/util/fake_credentials.h b/test/cpp/util/fake_credentials.h index 7e134ceef47..e1ba7bb9e4a 100644 --- a/test/cpp/util/fake_credentials.h +++ b/test/cpp/util/fake_credentials.h @@ -42,8 +42,8 @@ class ServerCredentials; namespace testing { -std::shared_ptr FakeCredentials(); -std::shared_ptr FakeServerCredentials(); +std::shared_ptr FakeTransportSecurityCredentials(); +std::shared_ptr FakeTransportSecurityServerCredentials(); } // namespace testing } // namespace grpc