Skip to content
Snippets Groups Projects
Commit b57f72db authored by Yang Gao's avatar Yang Gao
Browse files

resolve comments

parent 26a49125
No related branches found
No related tags found
No related merge requests found
...@@ -191,7 +191,8 @@ class End2endTest : public ::testing::Test { ...@@ -191,7 +191,8 @@ class End2endTest : public ::testing::Test {
server_address_ << "localhost:" << port; server_address_ << "localhost:" << port;
// Setup server // Setup server
ServerBuilder builder; ServerBuilder builder;
builder.AddListeningPort(server_address_.str(), FakeServerCredentials()); builder.AddListeningPort(server_address_.str(),
FakeTransportSecurityServerCredentials());
builder.RegisterService(&service_); builder.RegisterService(&service_);
builder.SetMaxMessageSize( builder.SetMaxMessageSize(
kMaxMessageSize_); // For testing max message size. kMaxMessageSize_); // For testing max message size.
...@@ -203,8 +204,9 @@ class End2endTest : public ::testing::Test { ...@@ -203,8 +204,9 @@ class End2endTest : public ::testing::Test {
void TearDown() GRPC_OVERRIDE { server_->Shutdown(); } void TearDown() GRPC_OVERRIDE { server_->Shutdown(); }
void ResetStub() { void ResetStub() {
std::shared_ptr<ChannelInterface> channel = CreateChannel( std::shared_ptr<ChannelInterface> channel =
server_address_.str(), FakeCredentials(), ChannelArguments()); CreateChannel(server_address_.str(), FakeTransportSecurityCredentials(),
ChannelArguments());
stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel)); stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel));
} }
...@@ -415,8 +417,9 @@ TEST_F(End2endTest, BidiStream) { ...@@ -415,8 +417,9 @@ TEST_F(End2endTest, BidiStream) {
// Talk to the two services with the same name but different package names. // Talk to the two services with the same name but different package names.
// The two stubs are created on the same channel. // The two stubs are created on the same channel.
TEST_F(End2endTest, DiffPackageServices) { TEST_F(End2endTest, DiffPackageServices) {
std::shared_ptr<ChannelInterface> channel = CreateChannel( std::shared_ptr<ChannelInterface> channel =
server_address_.str(), FakeCredentials(), ChannelArguments()); CreateChannel(server_address_.str(), FakeTransportSecurityCredentials(),
ChannelArguments());
EchoRequest request; EchoRequest request;
EchoResponse response; EchoResponse response;
...@@ -671,6 +674,12 @@ TEST_F(End2endTest, OverridePerCallCredentials) { ...@@ -671,6 +674,12 @@ TEST_F(End2endTest, OverridePerCallCredentials) {
EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(), EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(),
GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY,
"fake_selector2")); "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_EQ(request.message(), response.message());
EXPECT_TRUE(s.IsOk()); EXPECT_TRUE(s.IsOk());
} }
......
...@@ -36,39 +36,18 @@ ...@@ -36,39 +36,18 @@
#include <grpc++/credentials.h> #include <grpc++/credentials.h>
#include <grpc++/server_credentials.h> #include <grpc++/server_credentials.h>
#include "src/cpp/client/channel.h" #include "src/cpp/client/channel.h"
#include "src/cpp/client/secure_credentials.h"
#include "src/cpp/server/secure_server_credentials.h" #include "src/cpp/server/secure_server_credentials.h"
namespace grpc { namespace grpc {
namespace testing { namespace testing {
namespace { std::shared_ptr<Credentials> FakeTransportSecurityCredentials() {
class FakeCredentialsImpl GRPC_FINAL : public Credentials { grpc_credentials* c_creds = grpc_fake_transport_security_credentials_create();
public: return std::shared_ptr<Credentials>(new SecureCredentials(c_creds));
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<ServerCredentials> FakeServerCredentials() { std::shared_ptr<ServerCredentials> FakeTransportSecurityServerCredentials() {
grpc_server_credentials* c_creds = grpc_server_credentials* c_creds =
grpc_fake_transport_security_server_credentials_create(); grpc_fake_transport_security_server_credentials_create();
return std::shared_ptr<ServerCredentials>( return std::shared_ptr<ServerCredentials>(
......
...@@ -42,8 +42,8 @@ class ServerCredentials; ...@@ -42,8 +42,8 @@ class ServerCredentials;
namespace testing { namespace testing {
std::shared_ptr<Credentials> FakeCredentials(); std::shared_ptr<Credentials> FakeTransportSecurityCredentials();
std::shared_ptr<ServerCredentials> FakeServerCredentials(); std::shared_ptr<ServerCredentials> FakeTransportSecurityServerCredentials();
} // namespace testing } // namespace testing
} // namespace grpc } // namespace grpc
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment