aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.IntegrationTesting
diff options
context:
space:
mode:
Diffstat (limited to 'src/csharp/Grpc.IntegrationTesting')
-rw-r--r--src/csharp/Grpc.IntegrationTesting/InteropClient.cs52
-rw-r--r--src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs7
2 files changed, 31 insertions, 28 deletions
diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
index 504d798b89..d3b7fe87f3 100644
--- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
+++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
@@ -33,11 +33,13 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using CommandLine;
+using CommandLine.Text;
using Google.Apis.Auth.OAuth2;
using Google.Protobuf;
using Grpc.Auth;
@@ -45,8 +47,6 @@ using Grpc.Core;
using Grpc.Core.Utils;
using Grpc.Testing;
using NUnit.Framework;
-using CommandLine.Text;
-using System.IO;
namespace Grpc.IntegrationTesting
{
@@ -117,6 +117,20 @@ namespace Grpc.IntegrationTesting
private async Task Run()
{
var credentials = options.UseTls ? TestCredentials.CreateTestClientCredentials(options.UseTestCa) : Credentials.Insecure;
+
+ if (options.TestCase == "jwt_token_creds")
+ {
+ var googleCredential = await GoogleCredential.GetApplicationDefaultAsync();
+ Assert.IsTrue(googleCredential.IsCreateScopedRequired);
+ credentials = CompositeCredentials.Create(googleCredential.ToGrpcCredentials(), credentials);
+ }
+
+ if (options.TestCase == "compute_engine_creds")
+ {
+ var googleCredential = await GoogleCredential.GetApplicationDefaultAsync();
+ Assert.IsFalse(googleCredential.IsCreateScopedRequired);
+ credentials = CompositeCredentials.Create(googleCredential.ToGrpcCredentials(), credentials);
+ }
List<ChannelOption> channelOptions = null;
if (!string.IsNullOrEmpty(options.ServerHostOverride))
@@ -155,10 +169,10 @@ namespace Grpc.IntegrationTesting
await RunEmptyStreamAsync(client);
break;
case "compute_engine_creds":
- await RunComputeEngineCredsAsync(client, options.DefaultServiceAccount, options.OAuthScope);
+ RunComputeEngineCreds(client, options.DefaultServiceAccount, options.OAuthScope);
break;
case "jwt_token_creds":
- await RunJwtTokenCredsAsync(client, options.DefaultServiceAccount);
+ RunJwtTokenCreds(client, options.DefaultServiceAccount);
break;
case "oauth2_auth_token":
await RunOAuth2AuthTokenAsync(client, options.DefaultServiceAccount, options.OAuthScope);
@@ -318,13 +332,10 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static async Task RunComputeEngineCredsAsync(TestService.TestServiceClient client, string defaultServiceAccount, string oauthScope)
+ public static void RunComputeEngineCreds(TestService.TestServiceClient client, string defaultServiceAccount, string oauthScope)
{
Console.WriteLine("running compute_engine_creds");
- var credential = await GoogleCredential.GetApplicationDefaultAsync();
- Assert.IsFalse(credential.IsCreateScopedRequired);
- client.HeaderInterceptor = AuthInterceptors.FromCredential(credential);
-
+
var request = new SimpleRequest
{
ResponseType = PayloadType.COMPRESSABLE,
@@ -334,6 +345,7 @@ namespace Grpc.IntegrationTesting
FillOauthScope = true
};
+ // not setting credentials here because they were set on channel already
var response = client.UnaryCall(request);
Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type);
@@ -344,13 +356,10 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static async Task RunJwtTokenCredsAsync(TestService.TestServiceClient client, string defaultServiceAccount)
+ public static void RunJwtTokenCreds(TestService.TestServiceClient client, string defaultServiceAccount)
{
Console.WriteLine("running jwt_token_creds");
- var credential = await GoogleCredential.GetApplicationDefaultAsync();
- Assert.IsTrue(credential.IsCreateScopedRequired);
- client.HeaderInterceptor = AuthInterceptors.FromCredential(credential);
-
+
var request = new SimpleRequest
{
ResponseType = PayloadType.COMPRESSABLE,
@@ -359,6 +368,7 @@ namespace Grpc.IntegrationTesting
FillUsername = true,
};
+ // not setting credentials here because they were set on channel already
var response = client.UnaryCall(request);
Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type);
@@ -373,15 +383,14 @@ namespace Grpc.IntegrationTesting
ITokenAccess credential = (await GoogleCredential.GetApplicationDefaultAsync()).CreateScoped(new[] { oauthScope });
string oauth2Token = await credential.GetAccessTokenForRequestAsync();
- client.HeaderInterceptor = AuthInterceptors.FromAccessToken(oauth2Token);
-
+ var credentials = GrpcCredentials.FromAccessToken(oauth2Token);
var request = new SimpleRequest
{
FillUsername = true,
FillOauthScope = true
};
- var response = client.UnaryCall(request);
+ var response = client.UnaryCall(request, new CallOptions(credentials: credentials));
Assert.False(string.IsNullOrEmpty(response.OauthScope));
Assert.True(oauthScope.Contains(response.OauthScope));
@@ -392,18 +401,15 @@ namespace Grpc.IntegrationTesting
public static async Task RunPerRpcCredsAsync(TestService.TestServiceClient client, string defaultServiceAccount, string oauthScope)
{
Console.WriteLine("running per_rpc_creds");
- ITokenAccess credential = (await GoogleCredential.GetApplicationDefaultAsync()).CreateScoped(new[] { oauthScope });
- string accessToken = await credential.GetAccessTokenForRequestAsync();
- var headerInterceptor = AuthInterceptors.FromAccessToken(accessToken);
+ ITokenAccess googleCredential = (await GoogleCredential.GetApplicationDefaultAsync()).CreateScoped(new[] { oauthScope });
+ var credentials = GrpcCredentials.Create(googleCredential);
var request = new SimpleRequest
{
FillUsername = true,
};
- var headers = new Metadata();
- headerInterceptor(null, "", headers);
- var response = client.UnaryCall(request, headers: headers);
+ var response = client.UnaryCall(request, new CallOptions(credentials: credentials));
Assert.AreEqual(defaultServiceAccount, response.Username);
Console.WriteLine("Passed!");
diff --git a/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs b/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs
index 76991dfc20..790bade89d 100644
--- a/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs
+++ b/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs
@@ -54,9 +54,7 @@ namespace Grpc.IntegrationTesting
[TestFixtureSetUp]
public void Init()
{
- var serverCredentials = new SslServerCredentials(new[] { new KeyCertificatePair(
- File.ReadAllText(TestCredentials.ServerCertChainPath),
- File.ReadAllText(TestCredentials.ServerPrivateKeyPath)) });
+ var serverCredentials = new SslServerCredentials(new[] { new KeyCertificatePair(File.ReadAllText(TestCredentials.ServerCertChainPath), File.ReadAllText(TestCredentials.ServerPrivateKeyPath)) });
server = new Server
{
Services = { TestService.BindService(new TestServiceImpl()) },
@@ -77,8 +75,7 @@ namespace Grpc.IntegrationTesting
var clientCredentials = CompositeCredentials.Create(
new SslCredentials(File.ReadAllText(TestCredentials.ClientCertAuthorityPath)),
- new MetadataCredentials(asyncAuthInterceptor)
- );
+ new MetadataCredentials(asyncAuthInterceptor));
channel = new Channel(Host, server.Ports.Single().BoundPort, clientCredentials, options);
client = TestService.NewClient(channel);
}