aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.IntegrationTesting
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2017-02-06 08:45:00 -0800
committerGravatar Jan Tattermusch <jtattermusch@google.com>2017-03-02 12:07:15 +0100
commitc9b03fe9879b23f67d25938fd969765ae5fe7be8 (patch)
tree2b066213d13d41ba7c19627e6aee9808bcf743db /src/csharp/Grpc.IntegrationTesting
parentf2ac4bd4886c4f8122e7f5b10f28ed7a2cfaa0a8 (diff)
expose AuthContext in C#
Diffstat (limited to 'src/csharp/Grpc.IntegrationTesting')
-rw-r--r--src/csharp/Grpc.IntegrationTesting/SslCredentialsTest.cs38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/csharp/Grpc.IntegrationTesting/SslCredentialsTest.cs b/src/csharp/Grpc.IntegrationTesting/SslCredentialsTest.cs
index f85e272711..377dad63f4 100644
--- a/src/csharp/Grpc.IntegrationTesting/SslCredentialsTest.cs
+++ b/src/csharp/Grpc.IntegrationTesting/SslCredentialsTest.cs
@@ -37,6 +37,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using Google.Protobuf;
using Grpc.Core;
using Grpc.Core.Utils;
using Grpc.Testing;
@@ -68,7 +69,7 @@ namespace Grpc.IntegrationTesting
server = new Server
{
- Services = { TestService.BindService(new TestServiceImpl()) },
+ Services = { TestService.BindService(new SslCredentialsTestServiceImpl()) },
Ports = { { Host, ServerPort.PickUnused, serverCredentials } }
};
server.Start();
@@ -95,5 +96,40 @@ namespace Grpc.IntegrationTesting
var response = client.UnaryCall(new SimpleRequest { ResponseSize = 10 });
Assert.AreEqual(10, response.Payload.Body.Length);
}
+
+ [Test]
+ public async Task AuthContextIsPopulated()
+ {
+ var call = client.StreamingInputCall();
+ await call.RequestStream.CompleteAsync();
+ var response = await call.ResponseAsync;
+ Assert.AreEqual(12345, response.AggregatedPayloadSize);
+ }
+
+ private class SslCredentialsTestServiceImpl : TestService.TestServiceBase
+ {
+ public override async Task<SimpleResponse> UnaryCall(SimpleRequest request, ServerCallContext context)
+ {
+ return new SimpleResponse { Payload = CreateZerosPayload(request.ResponseSize) };
+ }
+
+ public override async Task<StreamingInputCallResponse> StreamingInputCall(IAsyncStreamReader<StreamingInputCallRequest> requestStream, ServerCallContext context)
+ {
+ var authContext = context.AuthContext;
+ await requestStream.ForEachAsync(async request => {});
+
+ Assert.IsTrue(authContext.IsPeerAuthenticated);
+ Assert.AreEqual("x509_subject_alternative_name", authContext.PeerIdentityPropertyName);
+ Assert.IsTrue(authContext.PeerIdentity.Count() > 0);
+ Assert.AreEqual("ssl", authContext.FindPropertiesByName("transport_security_type").First().Value);
+
+ return new StreamingInputCallResponse { AggregatedPayloadSize = 12345 };
+ }
+
+ private static Payload CreateZerosPayload(int size)
+ {
+ return new Payload { Body = ByteString.CopyFrom(new byte[size]) };
+ }
+ }
}
}