aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2015-08-02 00:54:02 -0700
committerGravatar Jan Tattermusch <jtattermusch@google.com>2015-08-12 10:06:28 -0700
commit0c140a863ed5ccc5c3c5aa2577332ccc4dbb2ef4 (patch)
tree4d1970cbea12729abf622a96954af9c2b948f562 /src/csharp/Grpc.IntegrationTesting/InteropClient.cs
parent023878c5c2f99b37d37880a1ac4a1ec5de1e029c (diff)
migrate to usable auth library
Diffstat (limited to 'src/csharp/Grpc.IntegrationTesting/InteropClient.cs')
-rw-r--r--src/csharp/Grpc.IntegrationTesting/InteropClient.cs80
1 files changed, 52 insertions, 28 deletions
diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
index c918f60127..385ca92086 100644
--- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
+++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
@@ -43,6 +43,7 @@ using Grpc.Auth;
using Grpc.Core;
using Grpc.Core.Utils;
using NUnit.Framework;
+using Google.Apis.Auth.OAuth2;
namespace Grpc.IntegrationTesting
{
@@ -97,10 +98,10 @@ namespace Grpc.IntegrationTesting
}
var interopClient = new InteropClient(options);
- interopClient.Run();
+ interopClient.Run().Wait();
}
- private void Run()
+ private async Task Run()
{
Credentials credentials = null;
if (options.useTls)
@@ -120,17 +121,7 @@ namespace Grpc.IntegrationTesting
using (Channel channel = new Channel(options.serverHost, options.serverPort.Value, credentials, channelOptions))
{
TestService.TestServiceClient client = new TestService.TestServiceClient(channel);
- if (options.testCase == "service_account_creds" || options.testCase == "compute_engine_creds")
- {
- var credential = GoogleCredential.GetApplicationDefault();
- if (credential.IsCreateScopedRequired)
- {
- credential = credential.CreateScoped(new[] { AuthScope });
- }
- client.HeaderInterceptor = OAuth2Interceptors.FromCredential(credential);
- }
-
- RunTestCaseAsync(options.testCase, client).Wait();
+ await RunTestCaseAsync(options.testCase, client);
}
GrpcEnvironment.Shutdown();
}
@@ -158,16 +149,19 @@ namespace Grpc.IntegrationTesting
await RunEmptyStreamAsync(client);
break;
case "service_account_creds":
- RunServiceAccountCreds(client);
+ await RunServiceAccountCredsAsync(client);
break;
case "compute_engine_creds":
- RunComputeEngineCreds(client);
+ await RunComputeEngineCredsAsync(client);
+ break;
+ case "jwt_token_creds":
+ await RunJwtTokenCredsAsync(client);
break;
case "oauth2_auth_token":
- RunOAuth2AuthToken(client);
+ await RunOAuth2AuthTokenAsync(client);
break;
case "per_rpc_creds":
- RunPerRpcCreds(client);
+ await RunPerRpcCredsAsync(client);
break;
case "cancel_after_begin":
await RunCancelAfterBeginAsync(client);
@@ -309,9 +303,13 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static void RunServiceAccountCreds(TestService.ITestServiceClient client)
+ public static async Task RunServiceAccountCredsAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running service_account_creds");
+ var credential = await GoogleCredential.GetApplicationDefaultAsync();
+ credential = credential.CreateScoped(new[] { AuthScope });
+ client.HeaderInterceptor = OAuth2Interceptors.FromCredential(credential);
+
var request = SimpleRequest.CreateBuilder()
.SetResponseType(PayloadType.COMPRESSABLE)
.SetResponseSize(314159)
@@ -329,9 +327,13 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static void RunComputeEngineCreds(TestService.ITestServiceClient client)
+ public static async Task RunComputeEngineCredsAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running compute_engine_creds");
+ var credential = await GoogleCredential.GetApplicationDefaultAsync();
+ Assert.IsFalse(credential.IsCreateScopedRequired);
+ client.HeaderInterceptor = OAuth2Interceptors.FromCredential(credential);
+
var request = SimpleRequest.CreateBuilder()
.SetResponseType(PayloadType.COMPRESSABLE)
.SetResponseSize(314159)
@@ -349,12 +351,35 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static void RunOAuth2AuthToken(TestService.TestServiceClient client)
+ public static async Task RunJwtTokenCredsAsync(TestService.TestServiceClient client)
+ {
+ Console.WriteLine("running jwt_token_creds");
+ var credential = await GoogleCredential.GetApplicationDefaultAsync();
+ // check this a credential with scope support, but don't add the scope.
+ Assert.IsTrue(credential.IsCreateScopedRequired);
+ client.HeaderInterceptor = OAuth2Interceptors.FromCredential(credential);
+
+ 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(ServiceAccountUser, response.Username);
+ Console.WriteLine("Passed!");
+ }
+
+ public static async Task RunOAuth2AuthTokenAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running oauth2_auth_token");
- var credential = GoogleCredential.GetApplicationDefault().CreateScoped(new[] { AuthScope });
- Assert.IsTrue(credential.RequestAccessTokenAsync(CancellationToken.None).Result);
- string oauth2Token = credential.Token.AccessToken;
+ ITokenAccess credential = (await GoogleCredential.GetApplicationDefaultAsync()).CreateScoped(new[] { AuthScope });
+ string oauth2Token = await credential.GetAccessTokenForRequestAsync();
client.HeaderInterceptor = OAuth2Interceptors.FromAccessToken(oauth2Token);
@@ -370,13 +395,12 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static void RunPerRpcCreds(TestService.TestServiceClient client)
+ public static async Task RunPerRpcCredsAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running per_rpc_creds");
- var credential = GoogleCredential.GetApplicationDefault().CreateScoped(new[] { AuthScope });
- Assert.IsTrue(credential.RequestAccessTokenAsync(CancellationToken.None).Result);
- string oauth2Token = credential.Token.AccessToken;
+ ITokenAccess credential = (await GoogleCredential.GetApplicationDefaultAsync()).CreateScoped(new[] { AuthScope });
+ string oauth2Token = await credential.GetAccessTokenForRequestAsync();
var headerInterceptor = OAuth2Interceptors.FromAccessToken(oauth2Token);
var request = SimpleRequest.CreateBuilder()
@@ -385,7 +409,7 @@ namespace Grpc.IntegrationTesting
.Build();
var headers = new Metadata();
- headerInterceptor(headers);
+ headerInterceptor("", headers);
var response = client.UnaryCall(request, headers: headers);
Assert.AreEqual(AuthScopeResponse, response.OauthScope);