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 io.grpc.ChannelCredentials; 20 import io.grpc.ServerBuilder; 21 import io.grpc.ServerCredentials; 22 import io.grpc.TlsChannelCredentials; 23 import io.grpc.TlsServerCredentials; 24 import io.grpc.internal.testing.TestUtils; 25 import io.grpc.netty.InternalNettyChannelBuilder; 26 import io.grpc.netty.InternalNettyServerBuilder; 27 import io.grpc.netty.NettyChannelBuilder; 28 import io.grpc.netty.NettyServerBuilder; 29 import io.grpc.testing.TlsTesting; 30 import java.io.IOException; 31 import java.net.InetSocketAddress; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.junit.runners.JUnit4; 35 36 /** 37 * Integration tests for GRPC over HTTP2 using the Netty framework. 38 */ 39 @RunWith(JUnit4.class) 40 public class Http2NettyTest extends AbstractInteropTest { 41 42 @Override getServerBuilder()43 protected ServerBuilder<?> getServerBuilder() { 44 // Starts the server with HTTPS. 45 try { 46 ServerCredentials serverCreds = TlsServerCredentials.newBuilder() 47 .keyManager(TlsTesting.loadCert("server1.pem"), TlsTesting.loadCert("server1.key")) 48 .trustManager(TlsTesting.loadCert("ca.pem")) 49 .clientAuth(TlsServerCredentials.ClientAuth.REQUIRE) 50 .build(); 51 NettyServerBuilder builder = NettyServerBuilder.forPort(0, serverCreds) 52 .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) 53 .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); 54 // Disable the default census stats tracer, use testing tracer instead. 55 InternalNettyServerBuilder.setStatsEnabled(builder, false); 56 return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); 57 } catch (IOException ex) { 58 throw new RuntimeException(ex); 59 } 60 } 61 62 @Override createChannelBuilder()63 protected NettyChannelBuilder createChannelBuilder() { 64 try { 65 ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder() 66 .keyManager(TlsTesting.loadCert("client.pem"), TlsTesting.loadCert("client.key")) 67 .trustManager(TlsTesting.loadCert("ca.pem")) 68 .build(); 69 NettyChannelBuilder builder = NettyChannelBuilder 70 .forAddress("localhost", ((InetSocketAddress) getListenAddress()).getPort(), channelCreds) 71 .overrideAuthority(TestUtils.TEST_SERVER_HOST) 72 .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) 73 .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); 74 // Disable the default census stats interceptor, use testing interceptor instead. 75 InternalNettyChannelBuilder.setStatsEnabled(builder, false); 76 return builder.intercept(createCensusStatsClientInterceptor()); 77 } catch (Exception ex) { 78 throw new RuntimeException(ex); 79 } 80 } 81 82 @Test tlsInfo()83 public void tlsInfo() { 84 assertX500SubjectDn("CN=testclient, O=Internet Widgits Pty Ltd, ST=Some-State, C=AU"); 85 } 86 } 87