add jwt token creds test_case

pull/1011/head
Yang Gao 10 years ago
parent 5c5992554b
commit 25770b02d6
  1. 30
      test/cpp/interop/client.cc

@ -73,6 +73,7 @@ DEFINE_string(test_case, "large_unary",
"ping_pong : full-duplex streaming; " "ping_pong : full-duplex streaming; "
"service_account_creds : large_unary with service_account auth; " "service_account_creds : large_unary with service_account auth; "
"compute_engine_creds: large_unary with compute engine auth; " "compute_engine_creds: large_unary with compute engine auth; "
"jwt_token_creds: large_unary with JWT token auth; "
"all : all of above."); "all : all of above.");
DEFINE_string(default_service_account, "", DEFINE_string(default_service_account, "",
"Email of GCE default service account"); "Email of GCE default service account");
@ -145,6 +146,13 @@ std::shared_ptr<ChannelInterface> CreateChannelForTestCase(
creds = CredentialsFactory::ComputeEngineCredentials(); creds = CredentialsFactory::ComputeEngineCredentials();
return CreateTestChannel(host_port, FLAGS_server_host_override, return CreateTestChannel(host_port, FLAGS_server_host_override,
FLAGS_enable_ssl, FLAGS_use_prod_roots, creds); FLAGS_enable_ssl, FLAGS_use_prod_roots, creds);
} else if (test_case == "jwt_token_creds") {
std::unique_ptr<Credentials> creds;
GPR_ASSERT(FLAGS_enable_ssl);
grpc::string json_key = GetServiceAccountJsonKey();
creds = CredentialsFactory::JWTCredentials(json_key, std::chrono::hours(1));
return CreateTestChannel(host_port, FLAGS_server_host_override,
FLAGS_enable_ssl, FLAGS_use_prod_roots, creds);
} else { } else {
return CreateTestChannel(host_port, FLAGS_server_host_override, return CreateTestChannel(host_port, FLAGS_server_host_override,
FLAGS_enable_ssl, FLAGS_use_prod_roots); FLAGS_enable_ssl, FLAGS_use_prod_roots);
@ -226,6 +234,21 @@ void DoServiceAccountCreds() {
gpr_log(GPR_INFO, "Large unary with service account creds done."); gpr_log(GPR_INFO, "Large unary with service account creds done.");
} }
void DoJwtTokenCreds() {
gpr_log(GPR_INFO,
"Sending a large unary rpc with JWT token credentials ...");
std::shared_ptr<ChannelInterface> channel =
CreateChannelForTestCase("jwt_token_creds");
SimpleRequest request;
SimpleResponse response;
request.set_fill_username(true);
PerformLargeUnary(channel, &request, &response);
GPR_ASSERT(!response.username().empty());
grpc::string json_key = GetServiceAccountJsonKey();
GPR_ASSERT(json_key.find(response.username()) != grpc::string::npos);
gpr_log(GPR_INFO, "Large unary with JWT token creds done.");
}
void DoLargeUnary() { void DoLargeUnary() {
gpr_log(GPR_INFO, "Sending a large unary rpc..."); gpr_log(GPR_INFO, "Sending a large unary rpc...");
std::shared_ptr<ChannelInterface> channel = std::shared_ptr<ChannelInterface> channel =
@ -414,6 +437,8 @@ int main(int argc, char** argv) {
DoServiceAccountCreds(); DoServiceAccountCreds();
} else if (FLAGS_test_case == "compute_engine_creds") { } else if (FLAGS_test_case == "compute_engine_creds") {
DoComputeEngineCreds(); DoComputeEngineCreds();
} else if (FLAGS_test_case == "jwt_token_creds") {
DoJwtTokenCreds();
} else if (FLAGS_test_case == "all") { } else if (FLAGS_test_case == "all") {
DoEmpty(); DoEmpty();
DoLargeUnary(); DoLargeUnary();
@ -421,9 +446,10 @@ int main(int argc, char** argv) {
DoResponseStreaming(); DoResponseStreaming();
DoHalfDuplex(); DoHalfDuplex();
DoPingPong(); DoPingPong();
// service_account_creds can only run with ssl. // service_account_creds and jwt_token_creds can only run with ssl.
if (FLAGS_enable_ssl) { if (FLAGS_enable_ssl) {
DoServiceAccountCreds(); DoServiceAccountCreds();
DoJwtTokenCreds();
} }
// compute_engine_creds only runs in GCE. // compute_engine_creds only runs in GCE.
} else { } else {
@ -431,7 +457,7 @@ int main(int argc, char** argv) {
GPR_ERROR, GPR_ERROR,
"Unsupported test case %s. Valid options are all|empty_unary|" "Unsupported test case %s. Valid options are all|empty_unary|"
"large_unary|client_streaming|server_streaming|half_duplex|ping_pong|" "large_unary|client_streaming|server_streaming|half_duplex|ping_pong|"
"service_account_creds|compute_engine_creds", "service_account_creds|compute_engine_creds|jwt_token_creds",
FLAGS_test_case.c_str()); FLAGS_test_case.c_str());
} }

Loading…
Cancel
Save