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