1 /* 2 * Copyright 2016 The Android Open Source Project 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 org.conscrypt.javax.net.ssl; 18 19 import static org.junit.Assert.assertEquals; 20 21 import java.util.Arrays; 22 import javax.net.ssl.SNIHostName; 23 import javax.net.ssl.StandardConstants; 24 import org.conscrypt.TestUtils; 25 import org.junit.Test; 26 import org.junit.runner.RunWith; 27 import org.junit.runners.JUnit4; 28 29 @RunWith(JUnit4.class) 30 public class SNIHostNameTest { 31 @Test 32 public void test_byteArray_Constructor() throws Exception { 33 TestUtils.assumeSNIHostnameAvailable(); 34 35 // From draft-josefsson-idn-test-vectors-00 section 5.2 36 byte[] idnEncoded = new byte[] { 37 (byte) 0xE4, (byte) 0xBB, (byte) 0x96, (byte) 0xE4, (byte) 0xBB, (byte) 0xAC, 38 (byte) 0xE4, (byte) 0xB8, (byte) 0xBA, (byte) 0xE4, (byte) 0xBB, (byte) 0x80, 39 (byte) 0xE4, (byte) 0xB9, (byte) 0x88, (byte) 0xE4, (byte) 0xB8, (byte) 0x8D, 40 (byte) 0xE8, (byte) 0xAF, (byte) 0xB4, (byte) 0xE4, (byte) 0xB8, (byte) 0xAD, 41 (byte) 0xE6, (byte) 0x96, (byte) 0x87, 42 }; 43 44 SNIHostName hostName = new SNIHostName(idnEncoded); 45 assertEquals("xn--ihqwcrb4cv8a8dqg056pqjye", hostName.getAsciiName()); 46 assertEquals(StandardConstants.SNI_HOST_NAME, hostName.getType()); 47 assertEquals(Arrays.toString(idnEncoded), Arrays.toString(hostName.getEncoded())); 48 } 49 } 50