• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
19  * @author Vera Y. Petrashkova
20  */
21 
22 package javax.net.ssl;
23 
24 import java.security.InvalidAlgorithmParameterException;
25 import java.security.KeyStore;
26 import java.security.KeyStoreException;
27 import java.security.UnrecoverableKeyException;
28 
29 import javax.net.ssl.KeyManagerFactorySpi;
30 
31 import junit.framework.TestCase;
32 
33 
34 /**
35  * Tests for <code>KeyManagerFactorySpi</code> class constructors and methods.
36  */
37 
38 public class KeyManagerFactorySpiTests extends TestCase {
39 
40     /**
41      * Constructor for KeyManegerFactorySpiTests.
42      *
43      * @param arg0
44      */
KeyManagerFactorySpiTests(String arg0)45     public KeyManagerFactorySpiTests(String arg0) {
46         super(arg0);
47     }
48 
49     /**
50      * Test for <code>KeyManagerFactorySpi</code> constructor
51      * Assertion: constructs KeyManagerFactorySpi
52      */
testKeyManagerFactorySpi01()53     public void testKeyManagerFactorySpi01()
54             throws Exception {
55         KeyManagerFactorySpi kmfSpi = new MyKeyManagerFactorySpi();
56         assertNull(kmfSpi.engineGetKeyManagers());
57         KeyStore kStore = null;
58         ManagerFactoryParameters mfp = null;
59 
60         char[] pass = { 'a', 'b', 'c' };
61 
62         try {
63             kmfSpi.engineInit(kStore, null);
64             fail("KeyStoreException must be thrown");
65         } catch (KeyStoreException e) {
66         }
67         try {
68             kmfSpi.engineInit(kStore, pass);
69             fail("UnrecoverableKeyException must be thrown");
70         } catch (UnrecoverableKeyException e) {
71         }
72         try {
73             kmfSpi.engineInit(mfp);
74             fail("InvalidAlgorithmParameterException must be thrown");
75         } catch (InvalidAlgorithmParameterException e) {
76         }
77         assertNull("getKeyManagers() should return null object",
78                 kmfSpi.engineGetKeyManagers());
79 
80         try {
81             kStore = KeyStore.getInstance(KeyStore.getDefaultType());
82             kStore.load(null, null);
83         } catch (KeyStoreException e) {
84             fail("default keystore type is not supported");
85             return;
86         }
87         kmfSpi.engineInit(kStore, pass);
88 
89         mfp = new MyKeyManagerFactorySpi.Parameters(kStore, null);
90         try {
91             kmfSpi.engineInit(mfp);
92             fail("InvalidAlgorithmParameterException must be thrown");
93         } catch (InvalidAlgorithmParameterException e) {
94         }
95         mfp = new MyKeyManagerFactorySpi.Parameters(kStore, pass);
96         kmfSpi.engineInit(mfp);
97     }
98 }
99 
100