Skip to content
Snippets Groups Projects
Commit 0bbfa382 authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

attempt to support compute_engine_creds interop test

parent 1f18e80a
No related branches found
No related tags found
No related merge requests found
...@@ -78,8 +78,14 @@ namespace Grpc.Auth ...@@ -78,8 +78,14 @@ namespace Grpc.Auth
public GoogleCredential CreateScoped(IEnumerable<string> scopes) public GoogleCredential CreateScoped(IEnumerable<string> scopes)
{ {
// TODO(jtattermusch): also support compute credential.
var credsPath = Environment.GetEnvironmentVariable(GoogleApplicationCredentialsEnvName); var credsPath = Environment.GetEnvironmentVariable(GoogleApplicationCredentialsEnvName);
if (credsPath == null)
{
// Default to ComputeCredentials if path to JSON key is not set.
// ComputeCredential is not scoped actually, but for our use case it's
// fine to treat is as such.
return new GoogleCredential(new ComputeCredential(new ComputeCredential.Initializer()));
}
JObject o1 = JObject.Parse(File.ReadAllText(credsPath)); JObject o1 = JObject.Parse(File.ReadAllText(credsPath));
string clientEmail = o1.GetValue(ClientEmailFieldName).Value<string>(); string clientEmail = o1.GetValue(ClientEmailFieldName).Value<string>();
......
...@@ -74,7 +74,5 @@ namespace Grpc.Core ...@@ -74,7 +74,5 @@ namespace Grpc.Core
{ {
return string.Format("Status(StatusCode={0}, Detail=\"{1}\")", statusCode, detail); return string.Format("Status(StatusCode={0}, Detail=\"{1}\")", statusCode, detail);
} }
} }
} }
...@@ -120,7 +120,7 @@ namespace Grpc.IntegrationTesting ...@@ -120,7 +120,7 @@ namespace Grpc.IntegrationTesting
using (Channel channel = new Channel(addr, credentials, channelArgs)) using (Channel channel = new Channel(addr, credentials, channelArgs))
{ {
var stubConfig = StubConfiguration.Default; var stubConfig = StubConfiguration.Default;
if (options.testCase == "service_account_creds") if (options.testCase == "service_account_creds" || options.testCase == "compute_engine_creds")
{ {
var credential = GoogleCredential.GetApplicationDefault(); var credential = GoogleCredential.GetApplicationDefault();
if (credential.IsCreateScopedRequired) if (credential.IsCreateScopedRequired)
...@@ -162,6 +162,9 @@ namespace Grpc.IntegrationTesting ...@@ -162,6 +162,9 @@ namespace Grpc.IntegrationTesting
case "service_account_creds": case "service_account_creds":
RunServiceAccountCreds(client); RunServiceAccountCreds(client);
break; break;
case "compute_engine_creds":
RunComputeEngineCreds(client);
break;
case "benchmark_empty_unary": case "benchmark_empty_unary":
RunBenchmarkEmptyUnary(client); RunBenchmarkEmptyUnary(client);
break; break;
...@@ -325,6 +328,26 @@ namespace Grpc.IntegrationTesting ...@@ -325,6 +328,26 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!"); Console.WriteLine("Passed!");
} }
public static void RunComputeEngineCreds(TestServiceGrpc.ITestServiceClient client)
{
Console.WriteLine("running compute_engine_creds");
var request = SimpleRequest.CreateBuilder()
.SetResponseType(PayloadType.COMPRESSABLE)
.SetResponseSize(314159)
.SetPayload(CreateZerosPayload(271828))
.SetFillUsername(true)
.SetFillOauthScope(true)
.Build();
var response = client.UnaryCall(request);
Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type);
Assert.AreEqual(314159, response.Payload.Body.Length);
Assert.AreEqual(AuthScopeResponse, response.OauthScope);
Assert.AreEqual(ServiceAccountUser, response.Username);
Console.WriteLine("Passed!");
}
// This is not an official interop test, but it's useful. // This is not an official interop test, but it's useful.
public static void RunBenchmarkEmptyUnary(TestServiceGrpc.ITestServiceClient client) public static void RunBenchmarkEmptyUnary(TestServiceGrpc.ITestServiceClient client)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment