Home | History | Annotate | Download | only in ssl
      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 
     39 public class KeyManagerFactorySpiTests extends TestCase {
     40 
     41     /**
     42      * Constructor for KeyManegerFactorySpiTests.
     43      *
     44      * @param arg0
     45      */
     46     public KeyManagerFactorySpiTests(String arg0) {
     47         super(arg0);
     48     }
     49 
     50     /**
     51      * Test for <code>KeyManagerFactorySpi</code> constructor
     52      * Assertion: constructs KeyManagerFactorySpi
     53      */
     54     public void testKeyManagerFactorySpi01()
     55             throws Exception {
     56         KeyManagerFactorySpi kmfSpi = new MyKeyManagerFactorySpi();
     57         assertNull(kmfSpi.engineGetKeyManagers());
     58         KeyStore kStore = null;
     59         ManagerFactoryParameters mfp = null;
     60 
     61         char[] pass = { 'a', 'b', 'c' };
     62 
     63         try {
     64             kmfSpi.engineInit(kStore, null);
     65             fail("KeyStoreException must be thrown");
     66         } catch (KeyStoreException e) {
     67         }
     68         try {
     69             kmfSpi.engineInit(kStore, pass);
     70             fail("UnrecoverableKeyException must be thrown");
     71         } catch (UnrecoverableKeyException e) {
     72         }
     73         try {
     74             kmfSpi.engineInit(mfp);
     75             fail("InvalidAlgorithmParameterException must be thrown");
     76         } catch (InvalidAlgorithmParameterException e) {
     77         }
     78         assertNull("getKeyManagers() should return null object",
     79                 kmfSpi.engineGetKeyManagers());
     80 
     81         try {
     82             kStore = KeyStore.getInstance(KeyStore.getDefaultType());
     83             kStore.load(null, null);
     84         } catch (KeyStoreException e) {
     85             fail("default keystore type is not supported");
     86             return;
     87         }
     88         kmfSpi.engineInit(kStore, pass);
     89 
     90         mfp = new MyKeyManagerFactorySpi.Parameters(kStore, null);
     91         try {
     92             kmfSpi.engineInit(mfp);
     93             fail("InvalidAlgorithmParameterException must be thrown");
     94         } catch (InvalidAlgorithmParameterException e) {
     95         }
     96         mfp = new MyKeyManagerFactorySpi.Parameters(kStore, pass);
     97         kmfSpi.engineInit(mfp);
     98     }
     99 }
    100 
    101