01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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 org.apache.harmony.xnet.provider.jsse;
19:
20: import java.io.File;
21: import java.io.FileInputStream;
22: import java.net.Socket;
23: import java.security.KeyStore;
24:
25: import junit.framework.TestCase;
26:
27: /**
28: * Tests for <code>KeyManagerImpl</code> constructor and methods
29: *
30: */
31: public class KeyManagerImplTest extends TestCase {
32:
33: public void testKeyManagerImpl1() throws Exception {
34: KeyStore ks = null;
35: ks = KeyStore.getInstance("BKS");
36: ks.load(null, null);
37:
38: KeyManagerImpl km = new KeyManagerImpl(ks, new char[0]);
39: String[] keyType = { "RSA", "DSA" };
40: String al = km.chooseClientAlias(keyType, null, new Socket());
41: assertNull(al);
42:
43: al = km.chooseEngineClientAlias(keyType, null,
44: new SSLEngineImpl(null));
45: assertNull(al);
46:
47: al = km.chooseEngineServerAlias("RSA", null, new SSLEngineImpl(
48: null));
49: assertNull(al);
50:
51: al = km.chooseServerAlias("RSA", null, new Socket());
52: assertNull(al);
53:
54: assertNull(km.getClientAliases("RSA", null));
55:
56: assertNull(km.getServerAliases("RSA", null));
57:
58: assertNull(km.getCertificateChain("alias"));
59: assertNull(km.getPrivateKey("alias"));
60: }
61:
62: public void testKeyManagerImpl2() throws Exception {
63:
64: KeyStore ks = JSSETestData.getKeyStore();
65: char[] pwd = JSSETestData.KS_PASSWORD;
66:
67: KeyManagerImpl km = new KeyManagerImpl(ks, pwd);
68: String[] keyType = { "RSA", "DSA" };
69: String al = km.chooseClientAlias(keyType, null, new Socket());
70: assertEquals("ssl_test_store", al);
71:
72: al = km.chooseEngineClientAlias(keyType, null,
73: new SSLEngineImpl(null));
74: assertEquals("ssl_test_store", al);
75:
76: al = km.chooseEngineServerAlias("RSA", null, new SSLEngineImpl(
77: null));
78: assertEquals("ssl_test_store", al);
79:
80: al = km.chooseServerAlias("RSA", null, new Socket());
81: assertEquals("ssl_test_store", al);
82:
83: assertTrue(km.getCertificateChain("ssl_test_store") != null);
84: assertTrue(km.getPrivateKey("ssl_test_store") != null);
85: }
86:
87: }
|