コード例 #1
0
ファイル: SslCredentialsTest.cs プロジェクト: rwightman/grpc
        public void Init()
        {
            var rootCert = File.ReadAllText(TestCredentials.ClientCertAuthorityPath);
            var keyCertPair = new KeyCertificatePair(
                File.ReadAllText(TestCredentials.ServerCertChainPath),
                File.ReadAllText(TestCredentials.ServerPrivateKeyPath));

            var serverCredentials = new SslServerCredentials(new[] { keyCertPair }, rootCert, true);
            var clientCredentials = new SslCredentials(rootCert, keyCertPair);

            server = new Server
            {
                Services = { TestService.BindService(new TestServiceImpl()) },
                Ports = { { Host, ServerPort.PickUnused, serverCredentials } }
            };
            server.Start();

            var options = new List<ChannelOption>
            {
                new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
            };

            channel = new Channel(Host, server.Ports.Single().BoundPort, clientCredentials, options);
            client = TestService.NewClient(channel);
        }
コード例 #2
0
 public void Init()
 {
     server = new Server
     {
         Services = { TestService.BindService(new UnimplementedTestServiceImpl()) },
         Ports = { { Host, ServerPort.PickUnused, SslServerCredentials.Insecure } }
     };
     server.Start();
     channel = new Channel(Host, server.Ports.Single().BoundPort, ChannelCredentials.Insecure);
     client = new TestService.TestServiceClient(channel);
 }
コード例 #3
0
        public void Init()
        {
            server = new Server
            {
                Services = { TestService.BindService(new TestServiceImpl()) },
                Ports = { { Host, ServerPort.PickUnused, TestCredentials.CreateSslServerCredentials() } }
            };
            server.Start();

            var options = new List<ChannelOption>
            {
                new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
            };
            int port = server.Ports.Single().BoundPort;
            channel = new Channel(Host, port, TestCredentials.CreateSslCredentials(), options);
            client = TestService.NewClient(channel);
        }
コード例 #4
0
ファイル: InteropClient.cs プロジェクト: wuyunhao/grpc
 private async Task RunTestCaseAsync(Channel channel, ClientOptions options)
 {
     var client = new TestService.TestServiceClient(channel);
     switch (options.TestCase)
     {
         case "empty_unary":
             RunEmptyUnary(client);
             break;
         case "large_unary":
             RunLargeUnary(client);
             break;
         case "client_streaming":
             await RunClientStreamingAsync(client);
             break;
         case "server_streaming":
             await RunServerStreamingAsync(client);
             break;
         case "ping_pong":
             await RunPingPongAsync(client);
             break;
         case "empty_stream":
             await RunEmptyStreamAsync(client);
             break;
         case "compute_engine_creds":
             RunComputeEngineCreds(client, options.DefaultServiceAccount, options.OAuthScope);
             break;
         case "jwt_token_creds":
             RunJwtTokenCreds(client);
             break;
         case "oauth2_auth_token":
             await RunOAuth2AuthTokenAsync(client, options.OAuthScope);
             break;
         case "per_rpc_creds":
             await RunPerRpcCredsAsync(client, options.OAuthScope);
             break;
         case "cancel_after_begin":
             await RunCancelAfterBeginAsync(client);
             break;
         case "cancel_after_first_response":
             await RunCancelAfterFirstResponseAsync(client);
             break;
         case "timeout_on_sleeping_server":
             await RunTimeoutOnSleepingServerAsync(client);
             break;
         case "custom_metadata":
             await RunCustomMetadataAsync(client);
             break;
         case "status_code_and_message":
             await RunStatusCodeAndMessageAsync(client);
             break;
         case "unimplemented_method":
             RunUnimplementedMethod(new UnimplementedService.UnimplementedServiceClient(channel));
             break;
         case "client_compressed_unary":
             RunClientCompressedUnary(client);
             break;
         case "client_compressed_streaming":
             await RunClientCompressedStreamingAsync(client);
             break;
         default:
             throw new ArgumentException("Unknown test case " + options.TestCase);
     }
 }
コード例 #5
0
ファイル: InteropClient.cs プロジェクト: nkibler/grpc
 private async Task Run()
 {
     var credentials = await CreateCredentialsAsync();
     
     List<ChannelOption> channelOptions = null;
     if (!string.IsNullOrEmpty(options.ServerHostOverride))
     {
         channelOptions = new List<ChannelOption>
         {
             new ChannelOption(ChannelOptions.SslTargetNameOverride, options.ServerHostOverride)
         };
     }
     var channel = new Channel(options.ServerHost, options.ServerPort, credentials, channelOptions);
     TestService.TestServiceClient client = new TestService.TestServiceClient(channel);
     await RunTestCaseAsync(client, options);
     await channel.ShutdownAsync();
 }
コード例 #6
0
        public void MetadataCredentials_PerCall()
        {
            channel = new Channel(Host, server.Ports.Single().BoundPort, TestCredentials.CreateSslCredentials(), options);
            client = new TestService.TestServiceClient(channel);

            var callCredentials = CallCredentials.FromInterceptor(asyncAuthInterceptor);
            client.UnaryCall(new SimpleRequest { }, new CallOptions(credentials: callCredentials));
        }
コード例 #7
0
        public void MetadataCredentials()
        {
            var channelCredentials = ChannelCredentials.Create(TestCredentials.CreateSslCredentials(),
                CallCredentials.FromInterceptor(asyncAuthInterceptor));
            channel = new Channel(Host, server.Ports.Single().BoundPort, channelCredentials, options);
            client = new TestService.TestServiceClient(channel);

            client.UnaryCall(new SimpleRequest { });
        }
コード例 #8
0
ファイル: InteropClient.cs プロジェクト: JoeWoo/grpc
 private async Task Run()
 {
     var credentials = options.UseTls ? TestCredentials.CreateTestClientCredentials(options.UseTestCa) : Credentials.Insecure;
     
     List<ChannelOption> channelOptions = null;
     if (!string.IsNullOrEmpty(options.ServerHostOverride))
     {
         channelOptions = new List<ChannelOption>
         {
             new ChannelOption(ChannelOptions.SslTargetNameOverride, options.ServerHostOverride)
         };
     }
     Console.WriteLine(options.ServerHost);
     Console.WriteLine(options.ServerPort);
     var channel = new Channel(options.ServerHost, options.ServerPort, credentials, channelOptions);
     TestService.TestServiceClient client = new TestService.TestServiceClient(channel);
     await RunTestCaseAsync(client, options);
     channel.ShutdownAsync().Wait();
 }
コード例 #9
0
ファイル: StressTestClient.cs プロジェクト: nerdrew/grpc
        async Task Run()
        {
            var metricsServer = new Server()
            {
                Services = { MetricsService.BindService(new MetricsServiceImpl(histogram)) },
                Ports = { { "[::]", options.MetricsPort, ServerCredentials.Insecure } }
            };
            metricsServer.Start();

            if (options.TestDurationSecs >= 0)
            {
                finishedTokenSource.CancelAfter(TimeSpan.FromSeconds(options.TestDurationSecs));
            }

            var tasks = new List<Task>();
            var channels = new List<Channel>();
            foreach (var serverAddress in serverAddresses)
            {
                for (int i = 0; i < options.NumChannelsPerServer; i++)
                {
                    var channel = new Channel(serverAddress, ChannelCredentials.Insecure);
                    channels.Add(channel);
                    for (int j = 0; j < options.NumStubsPerChannel; j++)
                    {
                        var client = new TestService.TestServiceClient(channel);
                        var task = Task.Factory.StartNew(() => RunBodyAsync(client).GetAwaiter().GetResult(),
                            TaskCreationOptions.LongRunning);
                        tasks.Add(task);  
                    }
                }
            }
            await Task.WhenAll(tasks);

            foreach (var channel in channels)
            {
                await channel.ShutdownAsync();
            }

            await metricsServer.ShutdownAsync();
        }
コード例 #10
0
ファイル: MetadataCredentialsTest.cs プロジェクト: grpc/grpc
        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);
        }
コード例 #11
0
ファイル: MetadataCredentialsTest.cs プロジェクト: grpc/grpc
        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);
        }
コード例 #12
0
ファイル: InteropClient.cs プロジェクト: larsonmpdx/grpc
        private async Task Run()
        {
            Credentials credentials = null;
            if (options.useTls)
            {
                credentials = TestCredentials.CreateTestClientCredentials(options.useTestCa);
            }

            List<ChannelOption> channelOptions = null;
            if (!string.IsNullOrEmpty(options.serverHostOverride))
            {
                channelOptions = new List<ChannelOption>
                {
                    new ChannelOption(ChannelOptions.SslTargetNameOverride, options.serverHostOverride)
                };
            }

            var channel = new Channel(options.serverHost, options.serverPort.Value, credentials, channelOptions);
            TestService.TestServiceClient client = new TestService.TestServiceClient(channel);
            await RunTestCaseAsync(options.testCase, client);
            channel.ShutdownAsync().Wait();
        }