Fixing Cpp tests.
This commit is contained in:
parent
54a902ed17
commit
e5adc0eb67
|
|
@ -46,8 +46,8 @@ class CredentialsTest : public ::testing::Test {
|
|||
};
|
||||
|
||||
TEST_F(CredentialsTest, InvalidGoogleRefreshToken) {
|
||||
std::shared_ptr<Credentials> bad1 = GoogleRefreshTokenCredentials("");
|
||||
EXPECT_EQ(static_cast<Credentials*>(nullptr), bad1.get());
|
||||
std::shared_ptr<CallCredentials> bad1 = GoogleRefreshTokenCredentials("");
|
||||
EXPECT_EQ(static_cast<CallCredentials*>(nullptr), bad1.get());
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> {
|
|||
|
||||
void ResetStub() {
|
||||
std::shared_ptr<Channel> channel =
|
||||
CreateChannel(server_address_.str(), InsecureCredentials());
|
||||
CreateChannel(server_address_.str(), InsecureChannelCredentials());
|
||||
stub_ = grpc::cpp::test::util::TestService::NewStub(channel);
|
||||
}
|
||||
|
||||
|
|
@ -749,7 +749,7 @@ TEST_P(AsyncEnd2endTest, ServerCheckDone) {
|
|||
|
||||
TEST_P(AsyncEnd2endTest, UnimplementedRpc) {
|
||||
std::shared_ptr<Channel> channel =
|
||||
CreateChannel(server_address_.str(), InsecureCredentials());
|
||||
CreateChannel(server_address_.str(), InsecureChannelCredentials());
|
||||
std::unique_ptr<grpc::cpp::test::util::UnimplementedService::Stub> stub;
|
||||
stub = grpc::cpp::test::util::UnimplementedService::NewStub(channel);
|
||||
EchoRequest send_request;
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class CrashTest : public ::testing::Test {
|
|||
}));
|
||||
GPR_ASSERT(server_);
|
||||
return grpc::cpp::test::util::TestService::NewStub(
|
||||
CreateChannel(addr, InsecureCredentials()));
|
||||
CreateChannel(addr, InsecureChannelCredentials()));
|
||||
}
|
||||
|
||||
void KillServer() { server_.reset(); }
|
||||
|
|
|
|||
|
|
@ -146,13 +146,13 @@ class TestAuthMetadataProcessor : public AuthMetadataProcessor {
|
|||
|
||||
TestAuthMetadataProcessor(bool is_blocking) : is_blocking_(is_blocking) {}
|
||||
|
||||
std::shared_ptr<Credentials> GetCompatibleClientCreds() {
|
||||
std::shared_ptr<CallCredentials> GetCompatibleClientCreds() {
|
||||
return MetadataCredentialsFromPlugin(
|
||||
std::unique_ptr<MetadataCredentialsPlugin>(
|
||||
new TestMetadataCredentialsPlugin(kGoodGuy, is_blocking_, true)));
|
||||
}
|
||||
|
||||
std::shared_ptr<Credentials> GetIncompatibleClientCreds() {
|
||||
std::shared_ptr<CallCredentials> GetIncompatibleClientCreds() {
|
||||
return MetadataCredentialsFromPlugin(
|
||||
std::unique_ptr<MetadataCredentialsPlugin>(
|
||||
new TestMetadataCredentialsPlugin("Mr Hyde", is_blocking_, true)));
|
||||
|
|
@ -407,7 +407,7 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> {
|
|||
}
|
||||
EXPECT_TRUE(is_server_started_);
|
||||
ChannelArguments args;
|
||||
auto channel_creds = InsecureCredentials();
|
||||
auto channel_creds = InsecureChannelCredentials();
|
||||
if (GetParam().use_tls) {
|
||||
SslCredentialsOptions ssl_opts = {test_root_cert, "", ""};
|
||||
args.SetSslTargetNameOverride("foo.test.google.fr");
|
||||
|
|
@ -429,7 +429,7 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> {
|
|||
builder.RegisterService(proxy_service_.get());
|
||||
proxy_server_ = builder.BuildAndStart();
|
||||
|
||||
channel_ = CreateChannel(proxyaddr.str(), InsecureCredentials());
|
||||
channel_ = CreateChannel(proxyaddr.str(), InsecureChannelCredentials());
|
||||
}
|
||||
|
||||
stub_ = grpc::cpp::test::util::TestService::NewStub(channel_);
|
||||
|
|
@ -751,7 +751,8 @@ TEST_P(End2endTest, ChannelStateTimeout) {
|
|||
std::ostringstream server_address;
|
||||
server_address << "127.0.0.1:" << port;
|
||||
// Channel to non-existing server
|
||||
auto channel = CreateChannel(server_address.str(), InsecureCredentials());
|
||||
auto channel =
|
||||
CreateChannel(server_address.str(), InsecureChannelCredentials());
|
||||
// Start IDLE
|
||||
EXPECT_EQ(GRPC_CHANNEL_IDLE, channel->GetState(true));
|
||||
|
||||
|
|
@ -971,33 +972,6 @@ TEST_P(SecureEnd2endTest, SimpleRpcWithHost) {
|
|||
EXPECT_TRUE(s.ok());
|
||||
}
|
||||
|
||||
// rpc and stream should fail on bad credentials.
|
||||
TEST_P(SecureEnd2endTest, BadCredentials) {
|
||||
std::shared_ptr<Credentials> bad_creds = GoogleRefreshTokenCredentials("");
|
||||
EXPECT_EQ(static_cast<Credentials*>(nullptr), bad_creds.get());
|
||||
std::shared_ptr<Channel> channel =
|
||||
CreateChannel(server_address_.str(), bad_creds);
|
||||
std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub(
|
||||
grpc::cpp::test::util::TestService::NewStub(channel));
|
||||
EchoRequest request;
|
||||
EchoResponse response;
|
||||
ClientContext context;
|
||||
request.set_message("Hello");
|
||||
|
||||
Status s = stub->Echo(&context, request, &response);
|
||||
EXPECT_EQ("", response.message());
|
||||
EXPECT_FALSE(s.ok());
|
||||
EXPECT_EQ(StatusCode::INVALID_ARGUMENT, s.error_code());
|
||||
EXPECT_EQ("Invalid credentials.", s.error_message());
|
||||
|
||||
ClientContext context2;
|
||||
auto stream = stub->BidiStream(&context2);
|
||||
s = stream->Finish();
|
||||
EXPECT_FALSE(s.ok());
|
||||
EXPECT_EQ(StatusCode::INVALID_ARGUMENT, s.error_code());
|
||||
EXPECT_EQ("Invalid credentials.", s.error_message());
|
||||
}
|
||||
|
||||
bool MetadataContains(
|
||||
const std::multimap<grpc::string_ref, grpc::string_ref>& metadata,
|
||||
const grpc::string& key, const grpc::string& value) {
|
||||
|
|
@ -1055,7 +1029,7 @@ TEST_P(SecureEnd2endTest, SetPerCallCredentials) {
|
|||
EchoRequest request;
|
||||
EchoResponse response;
|
||||
ClientContext context;
|
||||
std::shared_ptr<Credentials> creds =
|
||||
std::shared_ptr<CallCredentials> creds =
|
||||
GoogleIAMCredentials("fake_token", "fake_selector");
|
||||
context.set_credentials(creds);
|
||||
request.set_message("Hello");
|
||||
|
|
@ -1072,30 +1046,15 @@ TEST_P(SecureEnd2endTest, SetPerCallCredentials) {
|
|||
"fake_selector"));
|
||||
}
|
||||
|
||||
TEST_P(SecureEnd2endTest, 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.error_code());
|
||||
EXPECT_EQ("Failed to set credentials to rpc.", s.error_message());
|
||||
}
|
||||
|
||||
TEST_P(SecureEnd2endTest, OverridePerCallCredentials) {
|
||||
ResetStub();
|
||||
EchoRequest request;
|
||||
EchoResponse response;
|
||||
ClientContext context;
|
||||
std::shared_ptr<Credentials> creds1 =
|
||||
std::shared_ptr<CallCredentials> creds1 =
|
||||
GoogleIAMCredentials("fake_token1", "fake_selector1");
|
||||
context.set_credentials(creds1);
|
||||
std::shared_ptr<Credentials> creds2 =
|
||||
std::shared_ptr<CallCredentials> creds2 =
|
||||
GoogleIAMCredentials("fake_token2", "fake_selector2");
|
||||
context.set_credentials(creds2);
|
||||
request.set_message("Hello");
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ class GenericEnd2endTest : public ::testing::Test {
|
|||
|
||||
void ResetStub() {
|
||||
std::shared_ptr<Channel> channel =
|
||||
CreateChannel(server_address_.str(), InsecureCredentials());
|
||||
CreateChannel(server_address_.str(), InsecureChannelCredentials());
|
||||
generic_stub_.reset(new GenericStub(channel));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ class MockTest : public ::testing::Test {
|
|||
|
||||
void ResetStub() {
|
||||
std::shared_ptr<Channel> channel =
|
||||
CreateChannel(server_address_.str(), InsecureCredentials());
|
||||
CreateChannel(server_address_.str(), InsecureChannelCredentials());
|
||||
stub_ = grpc::cpp::test::util::TestService::NewStub(channel);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ using namespace gflags;
|
|||
int main(int argc, char** argv) {
|
||||
ParseCommandLineFlags(&argc, &argv, true);
|
||||
auto stub = grpc::cpp::test::util::TestService::NewStub(
|
||||
grpc::CreateChannel(FLAGS_address, grpc::InsecureCredentials()));
|
||||
grpc::CreateChannel(FLAGS_address, grpc::InsecureChannelCredentials()));
|
||||
|
||||
EchoRequest request;
|
||||
EchoResponse response;
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class ShutdownTest : public ::testing::Test {
|
|||
|
||||
void ResetStub() {
|
||||
string target = "dns:localhost:" + to_string(port_);
|
||||
channel_ = CreateChannel(target, InsecureCredentials());
|
||||
channel_ = CreateChannel(target, InsecureChannelCredentials());
|
||||
stub_ = grpc::cpp::test::util::TestService::NewStub(channel_);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ class End2endTest : public ::testing::Test {
|
|||
|
||||
void ResetStub() {
|
||||
std::shared_ptr<Channel> channel =
|
||||
CreateChannel(server_address_.str(), InsecureCredentials());
|
||||
CreateChannel(server_address_.str(), InsecureChannelCredentials());
|
||||
stub_ = grpc::cpp::test::util::TestService::NewStub(channel);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ class End2endTest : public ::testing::Test {
|
|||
|
||||
void ResetStub() {
|
||||
std::shared_ptr<Channel> channel =
|
||||
CreateChannel(server_address_.str(), InsecureCredentials());
|
||||
CreateChannel(server_address_.str(), InsecureChannelCredentials());
|
||||
stub_ = grpc::cpp::test::util::TestService::NewStub(channel);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,11 +76,11 @@ grpc::string GetServiceAccountJsonKey() {
|
|||
}
|
||||
|
||||
grpc::string GetOauth2AccessToken() {
|
||||
std::shared_ptr<Credentials> creds = GoogleComputeEngineCredentials();
|
||||
SecureCredentials* secure_creds =
|
||||
dynamic_cast<SecureCredentials*>(creds.get());
|
||||
std::shared_ptr<CallCredentials> creds = GoogleComputeEngineCredentials();
|
||||
SecureCallCredentials* secure_creds =
|
||||
dynamic_cast<SecureCallCredentials*>(creds.get());
|
||||
GPR_ASSERT(secure_creds != nullptr);
|
||||
grpc_credentials* c_creds = secure_creds->GetRawCreds();
|
||||
grpc_call_credentials* c_creds = secure_creds->GetRawCreds();
|
||||
char* token = grpc_test_fetch_oauth2_token_with_credentials(c_creds);
|
||||
GPR_ASSERT(token != nullptr);
|
||||
gpr_log(GPR_INFO, "Get raw oauth2 access token: %s", token);
|
||||
|
|
@ -98,13 +98,13 @@ std::shared_ptr<Channel> CreateChannelForTestCase(
|
|||
FLAGS_server_port);
|
||||
|
||||
if (test_case == "compute_engine_creds") {
|
||||
std::shared_ptr<Credentials> creds;
|
||||
std::shared_ptr<CallCredentials> creds;
|
||||
GPR_ASSERT(FLAGS_use_tls);
|
||||
creds = GoogleComputeEngineCredentials();
|
||||
return CreateTestChannel(host_port, FLAGS_server_host_override,
|
||||
FLAGS_use_tls, !FLAGS_use_test_ca, creds);
|
||||
} else if (test_case == "jwt_token_creds") {
|
||||
std::shared_ptr<Credentials> creds;
|
||||
std::shared_ptr<CallCredentials> creds;
|
||||
GPR_ASSERT(FLAGS_use_tls);
|
||||
grpc::string json_key = GetServiceAccountJsonKey();
|
||||
std::chrono::seconds token_lifetime = std::chrono::hours(1);
|
||||
|
|
@ -114,7 +114,7 @@ std::shared_ptr<Channel> CreateChannelForTestCase(
|
|||
FLAGS_use_tls, !FLAGS_use_test_ca, creds);
|
||||
} else if (test_case == "oauth2_auth_token") {
|
||||
grpc::string raw_token = GetOauth2AccessToken();
|
||||
std::shared_ptr<Credentials> creds = AccessTokenCredentials(raw_token);
|
||||
std::shared_ptr<CallCredentials> creds = AccessTokenCredentials(raw_token);
|
||||
return CreateTestChannel(host_port, FLAGS_server_host_override,
|
||||
FLAGS_use_tls, !FLAGS_use_test_ca, creds);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ void InteropClient::DoPerRpcCreds(const grpc::string& json_key) {
|
|||
|
||||
ClientContext context;
|
||||
std::chrono::seconds token_lifetime = std::chrono::hours(1);
|
||||
std::shared_ptr<Credentials> creds =
|
||||
std::shared_ptr<CallCredentials> creds =
|
||||
ServiceAccountJWTAccessCredentials(json_key, token_lifetime.count());
|
||||
|
||||
context.set_credentials(creds);
|
||||
|
|
|
|||
|
|
@ -161,8 +161,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
|
|||
// where class contained in std::vector must have a copy constructor
|
||||
auto* servers = new ServerData[num_servers];
|
||||
for (size_t i = 0; i < num_servers; i++) {
|
||||
servers[i].stub =
|
||||
Worker::NewStub(CreateChannel(workers[i], InsecureCredentials()));
|
||||
servers[i].stub = Worker::NewStub(
|
||||
CreateChannel(workers[i], InsecureChannelCredentials()));
|
||||
ServerArgs args;
|
||||
result_server_config = server_config;
|
||||
result_server_config.set_host(workers[i]);
|
||||
|
|
@ -190,7 +190,7 @@ std::unique_ptr<ScenarioResult> RunScenario(
|
|||
auto* clients = new ClientData[num_clients];
|
||||
for (size_t i = 0; i < num_clients; i++) {
|
||||
clients[i].stub = Worker::NewStub(
|
||||
CreateChannel(workers[i + num_servers], InsecureCredentials()));
|
||||
CreateChannel(workers[i + num_servers], InsecureChannelCredentials()));
|
||||
ClientArgs args;
|
||||
result_client_config = client_config;
|
||||
result_client_config.set_host(workers[i + num_servers]);
|
||||
|
|
|
|||
|
|
@ -116,8 +116,8 @@ class PerfDbReporter : public Reporter {
|
|||
test_name_(test_name),
|
||||
sys_info_(sys_info),
|
||||
tag_(tag) {
|
||||
perf_db_client_.init(
|
||||
grpc::CreateChannel(server_address, grpc::InsecureCredentials()));
|
||||
perf_db_client_.init(grpc::CreateChannel(
|
||||
server_address, grpc::InsecureChannelCredentials()));
|
||||
}
|
||||
~PerfDbReporter() GRPC_OVERRIDE { SendData(); };
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,8 @@ class CliCallTest : public ::testing::Test {
|
|||
void TearDown() GRPC_OVERRIDE { server_->Shutdown(); }
|
||||
|
||||
void ResetStub() {
|
||||
channel_ = CreateChannel(server_address_.str(), InsecureCredentials());
|
||||
channel_ =
|
||||
CreateChannel(server_address_.str(), InsecureChannelCredentials());
|
||||
stub_ = grpc::cpp::test::util::TestService::NewStub(channel_);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,13 +58,14 @@ namespace grpc {
|
|||
std::shared_ptr<Channel> CreateTestChannel(
|
||||
const grpc::string& server, const grpc::string& override_hostname,
|
||||
bool enable_ssl, bool use_prod_roots,
|
||||
const std::shared_ptr<Credentials>& creds) {
|
||||
const std::shared_ptr<CallCredentials>& creds) {
|
||||
ChannelArguments channel_args;
|
||||
if (enable_ssl) {
|
||||
const char* roots_certs = use_prod_roots ? "" : test_root_cert;
|
||||
SslCredentialsOptions ssl_opts = {roots_certs, "", ""};
|
||||
|
||||
std::shared_ptr<Credentials> channel_creds = SslCredentials(ssl_opts);
|
||||
std::shared_ptr<ChannelCredentials> channel_creds =
|
||||
SslCredentials(ssl_opts);
|
||||
|
||||
if (!server.empty() && !override_hostname.empty()) {
|
||||
channel_args.SetSslTargetNameOverride(override_hostname);
|
||||
|
|
@ -72,11 +73,11 @@ std::shared_ptr<Channel> CreateTestChannel(
|
|||
const grpc::string& connect_to =
|
||||
server.empty() ? override_hostname : server;
|
||||
if (creds.get()) {
|
||||
channel_creds = CompositeCredentials(creds, channel_creds);
|
||||
channel_creds = CompositeChannelCredentials(channel_creds, creds);
|
||||
}
|
||||
return CreateCustomChannel(connect_to, channel_creds, channel_args);
|
||||
} else {
|
||||
return CreateChannel(server, InsecureCredentials());
|
||||
return CreateChannel(server, InsecureChannelCredentials());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +85,7 @@ std::shared_ptr<Channel> CreateTestChannel(
|
|||
const grpc::string& server, const grpc::string& override_hostname,
|
||||
bool enable_ssl, bool use_prod_roots) {
|
||||
return CreateTestChannel(server, override_hostname, enable_ssl,
|
||||
use_prod_roots, std::shared_ptr<Credentials>());
|
||||
use_prod_roots, std::shared_ptr<CallCredentials>());
|
||||
}
|
||||
|
||||
// Shortcut for end2end and interop tests.
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ std::shared_ptr<Channel> CreateTestChannel(
|
|||
std::shared_ptr<Channel> CreateTestChannel(
|
||||
const grpc::string& server, const grpc::string& override_hostname,
|
||||
bool enable_ssl, bool use_prod_roots,
|
||||
const std::shared_ptr<Credentials>& creds);
|
||||
const std::shared_ptr<CallCredentials>& creds);
|
||||
|
||||
} // namespace grpc
|
||||
|
||||
|
|
|
|||
|
|
@ -148,9 +148,9 @@ int main(int argc, char** argv) {
|
|||
std::stringstream input_stream;
|
||||
input_stream << input_file.rdbuf();
|
||||
|
||||
std::shared_ptr<grpc::Credentials> creds;
|
||||
std::shared_ptr<grpc::ChannelCredentials> creds;
|
||||
if (!FLAGS_enable_ssl) {
|
||||
creds = grpc::InsecureCredentials();
|
||||
creds = grpc::InsecureChannelCredentials();
|
||||
} else {
|
||||
if (FLAGS_use_auth) {
|
||||
creds = grpc::GoogleDefaultCredentials();
|
||||
|
|
|
|||
Loading…
Reference in New Issue