001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.net.ssl;
019:
020: import java.io.IOException;
021: import java.net.URL;
022: import java.security.cert.Certificate;
023:
024: import junit.framework.TestCase;
025:
026: /**
027: * Tests for <code>HttpsURLConnection</code> class constructors and methods.
028: *
029: */
030: public class HttpsURLConnection_ImplTest extends TestCase {
031:
032: public final void testGetDefaultHostnameVerifier() {
033:
034: HostnameVerifier ver = HttpsURLConnection
035: .getDefaultHostnameVerifier();
036: if (!(ver instanceof DefaultHostnameVerifier)) {
037: fail("Incorrect instance");
038: }
039: if (ver.verify("localhost", null)) {
040: fail("connection should not be permitted");
041: }
042: }
043:
044: public final void testGetHostnameVerifier() {
045:
046: HttpsURLConnection con = new MyHttpsURLConnection(null);
047: HostnameVerifier ver = con.getHostnameVerifier();
048: if (!(ver instanceof DefaultHostnameVerifier)) {
049: fail("Incorrect instance");
050: }
051: if (ver.verify("localhost", null)) {
052: fail("connection should not be permitted");
053: }
054: }
055: }
056:
057: class MyHttpsURLConnection extends HttpsURLConnection {
058:
059: public MyHttpsURLConnection(URL url) {
060: super (url);
061: }
062:
063: /*
064: * @see javax.net.ssl.HttpsURLConnection#getCipherSuite()
065: */
066: public String getCipherSuite() {
067: return null;
068: }
069:
070: /*
071: * @see javax.net.ssl.HttpsURLConnection#getLocalCertificates()
072: */
073: public Certificate[] getLocalCertificates() {
074: return null;
075: }
076:
077: /*
078: * @see javax.net.ssl.HttpsURLConnection#getServerCertificates()
079: */
080: public Certificate[] getServerCertificates()
081: throws SSLPeerUnverifiedException {
082: return null;
083: }
084:
085: /*
086: * @see java.net.HttpURLConnection#disconnect()
087: */
088: public void disconnect() {
089: }
090:
091: /*
092: * @see java.net.HttpURLConnection#usingProxy()
093: */
094: public boolean usingProxy() {
095: return false;
096: }
097:
098: /*
099: * @see java.net.URLConnection#connect()
100: */
101: public void connect() throws IOException {
102: }
103: }
|