aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs')
-rw-r--r--src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs b/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs
index eb3bb8a28b..d55e658d94 100644
--- a/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs
+++ b/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs
@@ -103,6 +103,34 @@ namespace Grpc.IntegrationTesting
client.UnaryCall(new SimpleRequest { }, new CallOptions(credentials: callCredentials));
}
+ [Test]
+ public void MetadataCredentials_InterceptorLeavesMetadataEmpty()
+ {
+ var channelCredentials = ChannelCredentials.Create(TestCredentials.CreateSslCredentials(),
+ CallCredentials.FromInterceptor(new AsyncAuthInterceptor((context, metadata) => TaskUtils.CompletedTask)));
+ channel = new Channel(Host, server.Ports.Single().BoundPort, channelCredentials, options);
+ client = new TestService.TestServiceClient(channel);
+
+ var ex = Assert.Throws<RpcException>(() => client.UnaryCall(new SimpleRequest { }));
+ // StatusCode.Unknown as the server-side handler throws an exception after not receiving the authorization header.
+ Assert.AreEqual(StatusCode.Unknown, ex.Status.StatusCode);
+ }
+
+ [Test]
+ public void MetadataCredentials_InterceptorThrows()
+ {
+ var callCredentials = CallCredentials.FromInterceptor(new AsyncAuthInterceptor((context, metadata) =>
+ {
+ throw new Exception("Auth interceptor throws");
+ }));
+ var channelCredentials = ChannelCredentials.Create(TestCredentials.CreateSslCredentials(), callCredentials);
+ channel = new Channel(Host, server.Ports.Single().BoundPort, channelCredentials, options);
+ client = new TestService.TestServiceClient(channel);
+
+ var ex = Assert.Throws<RpcException>(() => client.UnaryCall(new SimpleRequest { }));
+ Assert.AreEqual(StatusCode.Unauthenticated, ex.Status.StatusCode);
+ }
+
private class FakeTestService : TestService.TestServiceBase
{
public override Task<SimpleResponse> UnaryCall(SimpleRequest request, ServerCallContext context)