Home | History | Annotate | Download | only in ssl
      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 
     18 package javax.net.ssl;
     19 
     20 import java.io.IOException;
     21 import java.net.URL;
     22 import java.security.cert.Certificate;
     23 
     24 import junit.framework.TestCase;
     25 
     26 /**
     27  * Tests for <code>HttpsURLConnection</code> class constructors and methods.
     28  *
     29  */
     30 public class HttpsURLConnection_ImplTest extends TestCase {
     31 
     32     public final void testGetDefaultHostnameVerifier() {
     33 
     34         HostnameVerifier ver = HttpsURLConnection.getDefaultHostnameVerifier();
     35         if (!(ver instanceof DefaultHostnameVerifier)) {
     36             fail("Incorrect instance");
     37         }
     38         if (ver.verify("localhost", null)) {
     39             fail("connection should not be permitted");
     40         }
     41     }
     42 
     43     public final void testGetHostnameVerifier() {
     44 
     45         HttpsURLConnection con = new MyHttpsURLConnection(null);
     46         HostnameVerifier ver = con.getHostnameVerifier();
     47         if (!(ver instanceof DefaultHostnameVerifier)) {
     48             fail("Incorrect instance");
     49         }
     50         if (ver.verify("localhost", null)) {
     51             fail("connection should not be permitted");
     52         }
     53     }
     54 }
     55 
     56 class MyHttpsURLConnection extends HttpsURLConnection {
     57 
     58     public MyHttpsURLConnection(URL url) {
     59         super(url);
     60     }
     61 
     62     /*
     63      * @see javax.net.ssl.HttpsURLConnection#getCipherSuite()
     64      */
     65     @Override
     66     public String getCipherSuite() {
     67         return null;
     68     }
     69 
     70     /*
     71      * @see javax.net.ssl.HttpsURLConnection#getLocalCertificates()
     72      */
     73     @Override
     74     public Certificate[] getLocalCertificates() {
     75         return null;
     76     }
     77 
     78     /*
     79      * @see javax.net.ssl.HttpsURLConnection#getServerCertificates()
     80      */
     81     @Override
     82     public Certificate[] getServerCertificates()
     83             throws SSLPeerUnverifiedException {
     84         return null;
     85     }
     86 
     87     /*
     88      * @see java.net.HttpURLConnection#disconnect()
     89      */
     90     @Override
     91     public void disconnect() {
     92     }
     93 
     94     /*
     95      * @see java.net.HttpURLConnection#usingProxy()
     96      */
     97     @Override
     98     public boolean usingProxy() {
     99         return false;
    100     }
    101 
    102     /*
    103      * @see java.net.URLConnection#connect()
    104      */
    105     @Override
    106     public void connect() throws IOException {
    107     }
    108 }
    109