1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package javax.net.ssl; 19 20import java.io.IOException; 21import java.net.URL; 22import java.security.cert.Certificate; 23 24import junit.framework.TestCase; 25 26/** 27 * Tests for <code>HttpsURLConnection</code> class constructors and methods. 28 */ 29public class HttpsURLConnection_ImplTest extends TestCase { 30 31 public final void testGetDefaultHostnameVerifier() { 32 33 HostnameVerifier ver = HttpsURLConnection.getDefaultHostnameVerifier(); 34 if (!(ver instanceof DefaultHostnameVerifier)) { 35 fail("Incorrect instance"); 36 } 37 if (ver.verify("localhost", null)) { 38 fail("connection should not be permitted"); 39 } 40 } 41 42 public final void testGetHostnameVerifier() { 43 44 HttpsURLConnection con = new MyHttpsURLConnection(null); 45 HostnameVerifier ver = con.getHostnameVerifier(); 46 if (!(ver instanceof DefaultHostnameVerifier)) { 47 fail("Incorrect instance"); 48 } 49 if (ver.verify("localhost", null)) { 50 fail("connection should not be permitted"); 51 } 52 } 53} 54 55class MyHttpsURLConnection extends HttpsURLConnection { 56 57 public MyHttpsURLConnection(URL url) { 58 super(url); 59 } 60 61 /* 62 * @see javax.net.ssl.HttpsURLConnection#getCipherSuite() 63 */ 64 @Override 65 public String getCipherSuite() { 66 return null; 67 } 68 69 /* 70 * @see javax.net.ssl.HttpsURLConnection#getLocalCertificates() 71 */ 72 @Override 73 public Certificate[] getLocalCertificates() { 74 return null; 75 } 76 77 /* 78 * @see javax.net.ssl.HttpsURLConnection#getServerCertificates() 79 */ 80 @Override 81 public Certificate[] getServerCertificates() 82 throws SSLPeerUnverifiedException { 83 return null; 84 } 85 86 /* 87 * @see java.net.HttpURLConnection#disconnect() 88 */ 89 @Override 90 public void disconnect() { 91 } 92 93 /* 94 * @see java.net.HttpURLConnection#usingProxy() 95 */ 96 @Override 97 public boolean usingProxy() { 98 return false; 99 } 100 101 /* 102 * @see java.net.URLConnection#connect() 103 */ 104 @Override 105 public void connect() throws IOException { 106 } 107} 108