1 /* 2 * Copyright 2016 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.okhttp; 18 19 import static io.grpc.okhttp.OkHttpTlsUpgrader.canonicalizeHost; 20 import static org.junit.Assert.assertEquals; 21 import static org.junit.Assert.assertTrue; 22 23 import io.grpc.okhttp.internal.Protocol; 24 import org.junit.Test; 25 import org.junit.runner.RunWith; 26 import org.junit.runners.JUnit4; 27 28 /** Unit tests for {@link io.grpc.okhttp.OkHttpTlsUpgrader}. */ 29 @RunWith(JUnit4.class) 30 public class OkHttpTlsUpgraderTest { upgrade_grpcExp()31 @Test public void upgrade_grpcExp() { 32 assertTrue( 33 OkHttpTlsUpgrader.TLS_PROTOCOLS.indexOf(Protocol.GRPC_EXP) == -1 34 || OkHttpTlsUpgrader.TLS_PROTOCOLS.indexOf(Protocol.GRPC_EXP) 35 < OkHttpTlsUpgrader.TLS_PROTOCOLS.indexOf(Protocol.HTTP_2)); 36 } 37 38 @Test public void canonicalizeHosts() { 39 assertEquals("::1", canonicalizeHost("::1")); 40 assertEquals("::1", canonicalizeHost("[::1]")); 41 assertEquals("127.0.0.1", canonicalizeHost("127.0.0.1")); 42 assertEquals("some.long.url.com", canonicalizeHost("some.long.url.com")); 43 44 // Extra square brackets in a malformed URI are retained 45 assertEquals("[::1]", canonicalizeHost("[[::1]]")); 46 } 47 } 48