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 tests.api.javax.net.ssl; 19 20 import java.net.Socket; 21 import java.security.Principal; 22 import java.security.PrivateKey; 23 import java.security.cert.X509Certificate; 24 25 import javax.net.ssl.X509ExtendedKeyManager; 26 27 import junit.framework.TestCase; 28 29 /** 30 * Tests for <code>X509ExtendedKeyManager</code> class constructors and methods. 31 * 32 */ 33 public class X509ExtendedKeyManagerTest extends TestCase { 34 35 private class MockX509ExtendedKeyManager extends X509ExtendedKeyManager { 36 public MockX509ExtendedKeyManager() { 37 super(); 38 } 39 40 /** 41 * @see javax.net.ssl.X509KeyManager#chooseClientAlias(java.lang.String[], java.security.Principal[], java.net.Socket) 42 */ 43 public String chooseClientAlias(String[] arg0, Principal[] arg1, Socket arg2) { 44 // it is a fake 45 return null; 46 } 47 48 /** 49 * @see javax.net.ssl.X509KeyManager#chooseServerAlias(java.lang.String, java.security.Principal[], java.net.Socket) 50 */ 51 public String chooseServerAlias(String arg0, Principal[] arg1, Socket arg2) { 52 // it is a fake 53 return null; 54 } 55 56 /** 57 * @see javax.net.ssl.X509KeyManager#getCertificateChain(java.lang.String) 58 */ 59 public X509Certificate[] getCertificateChain(String arg0) { 60 // it is a fake 61 return null; 62 } 63 64 /** 65 * @see javax.net.ssl.X509KeyManager#getClientAliases(java.lang.String, java.security.Principal[]) 66 */ 67 public String[] getClientAliases(String arg0, Principal[] arg1) { 68 // it is a fake 69 return null; 70 } 71 72 /** 73 * @see javax.net.ssl.X509KeyManager#getPrivateKey(java.lang.String) 74 */ 75 public PrivateKey getPrivateKey(String arg0) { 76 // it is a fake 77 return null; 78 } 79 80 /** 81 * @see javax.net.ssl.X509KeyManager#getServerAliases(java.lang.String, java.security.Principal[]) 82 */ 83 public String[] getServerAliases(String arg0, Principal[] arg1) { 84 // it is a fake 85 return null; 86 } 87 } 88 89 /** 90 * javax.net.ssl.X509ExtendedKeyManager#X509ExtendedKeyManager() 91 */ 92 public final void test_Constructor() { 93 try { 94 new MockX509ExtendedKeyManager(); 95 } catch (Exception e) { 96 fail("Unexpected exception " + e.toString()); 97 } 98 } 99 100 /** 101 * javax.net.ssl.X509ExtendedKeyManager 102 * #chooseEngineClientAlias(java.lang.String[], 103 * java.security.Principal[], javax.net.ssl.SSLEngine) 104 */ 105 public final void test_chooseEngineClientAlias() { 106 X509ExtendedKeyManager km = new MyX509ExtendedKeyManager(); 107 if (km.chooseEngineClientAlias(null, null, null) != null) { 108 fail("non null result"); 109 } 110 } 111 112 /** 113 * javax.net.ssl.X509ExtendedKeyManager 114 * #chooseEngineServerAlias(java.lang.String, 115 * java.security.Principal[], javax.net.ssl.SSLEngine) 116 */ 117 public final void test_chooseEngineServerAlias() { 118 X509ExtendedKeyManager km = new MyX509ExtendedKeyManager(); 119 if (km.chooseEngineServerAlias(null, null, null) != null) { 120 fail("non null result"); 121 } 122 } 123 124 } 125 126 class MyX509ExtendedKeyManager extends X509ExtendedKeyManager { 127 128 /* 129 * @see javax.net.ssl.X509KeyManager#chooseClientAlias(java.lang.String[], 130 * java.security.Principal[], java.net.Socket) 131 */ 132 public String chooseClientAlias(String[] keyType, Principal[] issuers, 133 Socket socket) { 134 return null; 135 } 136 137 /* 138 * @see javax.net.ssl.X509KeyManager#chooseServerAlias(java.lang.String, 139 * java.security.Principal[], java.net.Socket) 140 */ 141 public String chooseServerAlias(String keyType, Principal[] issuers, 142 Socket socket) { 143 return null; 144 } 145 146 /* 147 * @see javax.net.ssl.X509KeyManager#getCertificateChain(java.lang.String) 148 */ 149 public X509Certificate[] getCertificateChain(String alias) { 150 return null; 151 } 152 153 /* 154 * @see javax.net.ssl.X509KeyManager#getClientAliases(java.lang.String, 155 * java.security.Principal[]) 156 */ 157 public String[] getClientAliases(String keyType, Principal[] issuers) { 158 return null; 159 } 160 161 /* 162 * @see javax.net.ssl.X509KeyManager#getServerAliases(java.lang.String, 163 * java.security.Principal[]) 164 */ 165 public String[] getServerAliases(String keyType, Principal[] issuers) { 166 return null; 167 } 168 169 /* 170 * @see javax.net.ssl.X509KeyManager#getPrivateKey(java.lang.String) 171 */ 172 public PrivateKey getPrivateKey(String alias) { 173 return null; 174 } 175 176 } 177