OLD | NEW |
(Empty) | |
| 1 #region Copyright notice and license |
| 2 |
| 3 // Copyright 2015, Google Inc. |
| 4 // All rights reserved. |
| 5 // |
| 6 // Redistribution and use in source and binary forms, with or without |
| 7 // modification, are permitted provided that the following conditions are |
| 8 // met: |
| 9 // |
| 10 // * Redistributions of source code must retain the above copyright |
| 11 // notice, this list of conditions and the following disclaimer. |
| 12 // * Redistributions in binary form must reproduce the above |
| 13 // copyright notice, this list of conditions and the following disclaimer |
| 14 // in the documentation and/or other materials provided with the |
| 15 // distribution. |
| 16 // * Neither the name of Google Inc. nor the names of its |
| 17 // contributors may be used to endorse or promote products derived from |
| 18 // this software without specific prior written permission. |
| 19 // |
| 20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 |
| 32 #endregion |
| 33 |
| 34 using System; |
| 35 using System.Collections.Generic; |
| 36 using System.IO; |
| 37 using System.Linq; |
| 38 using System.Threading; |
| 39 using System.Threading.Tasks; |
| 40 using Grpc.Core; |
| 41 using Grpc.Core.Utils; |
| 42 using Grpc.Testing; |
| 43 using NUnit.Framework; |
| 44 |
| 45 namespace Grpc.IntegrationTesting |
| 46 { |
| 47 /// <summary> |
| 48 /// Test SSL credentials where server authenticates client |
| 49 /// and client authenticates the server. |
| 50 /// </summary> |
| 51 public class SslCredentialsTest |
| 52 { |
| 53 const string Host = "localhost"; |
| 54 Server server; |
| 55 Channel channel; |
| 56 TestService.ITestServiceClient client; |
| 57 |
| 58 [TestFixtureSetUp] |
| 59 public void Init() |
| 60 { |
| 61 var rootCert = File.ReadAllText(TestCredentials.ClientCertAuthorityP
ath); |
| 62 var keyCertPair = new KeyCertificatePair( |
| 63 File.ReadAllText(TestCredentials.ServerCertChainPath), |
| 64 File.ReadAllText(TestCredentials.ServerPrivateKeyPath)); |
| 65 |
| 66 var serverCredentials = new SslServerCredentials(new[] { keyCertPair
}, rootCert, true); |
| 67 var clientCredentials = new SslCredentials(rootCert, keyCertPair); |
| 68 |
| 69 server = new Server |
| 70 { |
| 71 Services = { TestService.BindService(new TestServiceImpl()) }, |
| 72 Ports = { { Host, ServerPort.PickUnused, serverCredentials } } |
| 73 }; |
| 74 server.Start(); |
| 75 |
| 76 var options = new List<ChannelOption> |
| 77 { |
| 78 new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCred
entials.DefaultHostOverride) |
| 79 }; |
| 80 |
| 81 channel = new Channel(Host, server.Ports.Single().BoundPort, clientC
redentials, options); |
| 82 client = TestService.NewClient(channel); |
| 83 } |
| 84 |
| 85 [TestFixtureTearDown] |
| 86 public void Cleanup() |
| 87 { |
| 88 channel.ShutdownAsync().Wait(); |
| 89 server.ShutdownAsync().Wait(); |
| 90 } |
| 91 |
| 92 [Test] |
| 93 public void AuthenticatedClientAndServer() |
| 94 { |
| 95 var response = client.UnaryCall(new SimpleRequest { ResponseSize = 1
0 }); |
| 96 Assert.AreEqual(10, response.Payload.Body.Length); |
| 97 } |
| 98 } |
| 99 } |
OLD | NEW |