diff options
author | Yang Gao <yangg@google.com> | 2015-05-17 21:54:54 -0700 |
---|---|---|
committer | Yang Gao <yangg@google.com> | 2015-05-17 21:54:54 -0700 |
commit | b57f72dbeeffee0bdb3f39f470f048a23bdb6a08 (patch) | |
tree | 68a24792c151d603e2f4d4703843d31e4846e019 /test/cpp | |
parent | 26a49125588108e18d12d6ed13ba65d7ef565a10 (diff) |
resolve comments
Diffstat (limited to 'test/cpp')
-rw-r--r-- | test/cpp/end2end/end2end_test.cc | 19 | ||||
-rw-r--r-- | test/cpp/util/fake_credentials.cc | 31 | ||||
-rw-r--r-- | 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 9017641e30..76271c3e1d 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<ChannelInterface> channel = CreateChannel( - server_address_.str(), FakeCredentials(), ChannelArguments()); + std::shared_ptr<ChannelInterface> 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<ChannelInterface> channel = CreateChannel( - server_address_.str(), FakeCredentials(), ChannelArguments()); + std::shared_ptr<ChannelInterface> 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 6b89e2fc96..f5b83b8159 100644 --- a/test/cpp/util/fake_credentials.cc +++ b/test/cpp/util/fake_credentials.cc @@ -36,39 +36,18 @@ #include <grpc++/credentials.h> #include <grpc++/server_credentials.h> #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<ChannelInterface> CreateChannel( - const grpc::string& target, const ChannelArguments& args) GRPC_OVERRIDE { - grpc_channel_args channel_args; - args.SetChannelArgs(&channel_args); - return std::shared_ptr<ChannelInterface>(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<Credentials> FakeCredentials() { - return std::shared_ptr<Credentials>(new FakeCredentialsImpl()); +std::shared_ptr<Credentials> FakeTransportSecurityCredentials() { + grpc_credentials* c_creds = grpc_fake_transport_security_credentials_create(); + return std::shared_ptr<Credentials>(new SecureCredentials(c_creds)); } -std::shared_ptr<ServerCredentials> FakeServerCredentials() { +std::shared_ptr<ServerCredentials> FakeTransportSecurityServerCredentials() { grpc_server_credentials* c_creds = grpc_fake_transport_security_server_credentials_create(); return std::shared_ptr<ServerCredentials>( diff --git a/test/cpp/util/fake_credentials.h b/test/cpp/util/fake_credentials.h index 7e134ceef4..e1ba7bb9e4 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<Credentials> FakeCredentials(); -std::shared_ptr<ServerCredentials> FakeServerCredentials(); +std::shared_ptr<Credentials> FakeTransportSecurityCredentials(); +std::shared_ptr<ServerCredentials> FakeTransportSecurityServerCredentials(); } // namespace testing } // namespace grpc |