• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 The gRPC Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.grpc.testing.integration;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotEquals;
21 
22 import io.grpc.ManagedChannel;
23 import io.grpc.internal.AbstractServerImplBuilder;
24 import io.grpc.internal.testing.TestUtils;
25 import io.grpc.netty.GrpcSslContexts;
26 import io.grpc.netty.NettyChannelBuilder;
27 import io.grpc.netty.NettyServerBuilder;
28 import io.netty.handler.ssl.ClientAuth;
29 import io.netty.handler.ssl.SupportedCipherSuiteFilter;
30 import java.io.IOException;
31 import java.net.InetAddress;
32 import java.net.InetSocketAddress;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.junit.runners.JUnit4;
36 
37 /**
38  * Integration tests for GRPC over HTTP2 using the Netty framework.
39  */
40 @RunWith(JUnit4.class)
41 public class Http2NettyTest extends AbstractInteropTest {
42 
43   @Override
getServerBuilder()44   protected AbstractServerImplBuilder<?> getServerBuilder() {
45     // Starts the server with HTTPS.
46     try {
47       return NettyServerBuilder.forPort(0)
48           .flowControlWindow(65 * 1024)
49           .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
50           .sslContext(GrpcSslContexts
51               .forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"))
52               .clientAuth(ClientAuth.REQUIRE)
53               .trustManager(TestUtils.loadCert("ca.pem"))
54               .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
55               .build());
56     } catch (IOException ex) {
57       throw new RuntimeException(ex);
58     }
59   }
60 
61   @Override
createChannel()62   protected ManagedChannel createChannel() {
63     try {
64       NettyChannelBuilder builder = NettyChannelBuilder
65           .forAddress(TestUtils.testServerAddress(getPort()))
66           .flowControlWindow(65 * 1024)
67           .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
68           .sslContext(GrpcSslContexts
69               .forClient()
70               .keyManager(TestUtils.loadCert("client.pem"), TestUtils.loadCert("client.key"))
71               .trustManager(TestUtils.loadX509Cert("ca.pem"))
72               .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
73               .build());
74       io.grpc.internal.TestingAccessor.setStatsImplementation(
75           builder, createClientCensusStatsModule());
76       return builder.build();
77     } catch (Exception ex) {
78       throw new RuntimeException(ex);
79     }
80   }
81 
82   @Test
remoteAddr()83   public void remoteAddr() throws Exception {
84     InetSocketAddress isa = (InetSocketAddress) obtainRemoteClientAddr();
85     assertEquals(InetAddress.getLoopbackAddress(), isa.getAddress());
86     // It should not be the same as the server
87     assertNotEquals(getPort(), isa.getPort());
88   }
89 
90   @Test
localAddr()91   public void localAddr() throws Exception {
92     InetSocketAddress isa = (InetSocketAddress) obtainLocalClientAddr();
93     assertEquals(InetAddress.getLoopbackAddress(), isa.getAddress());
94     assertEquals(getPort(), isa.getPort());
95   }
96 
97   @Test
tlsInfo()98   public void tlsInfo() {
99     assertX500SubjectDn("CN=testclient, O=Internet Widgits Pty Ltd, ST=Some-State, C=AU");
100   }
101 }
102