Author: erodriguez
Date: Fri Nov  5 17:00:23 2004
New Revision: 56716

Modified:
   
incubator/directory/kerberos/trunk/kerberos/src/test/org/apache/kerberos/kdc/BootstrapStoreTest.java
Log:
Integrated auto-key creation into BootstrapStore, simplifying test class.

Modified: 
incubator/directory/kerberos/trunk/kerberos/src/test/org/apache/kerberos/kdc/BootstrapStoreTest.java
==============================================================================
--- 
incubator/directory/kerberos/trunk/kerberos/src/test/org/apache/kerberos/kdc/BootstrapStoreTest.java
        (original)
+++ 
incubator/directory/kerberos/trunk/kerberos/src/test/org/apache/kerberos/kdc/BootstrapStoreTest.java
        Fri Nov  5 17:00:23 2004
@@ -18,16 +18,15 @@
 
 
 import junit.framework.TestCase;
+import org.apache.kerberos.kdc.store.BootstrapStore;
 
 import javax.security.auth.kerberos.KerberosKey;
-import javax.security.auth.kerberos.KerberosPrincipal;
-import java.io.*;
-import java.util.Map;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.ObjectInputStream;
 import java.util.HashMap;
 import java.util.Iterator;
-
-import org.apache.kerberos.crypto.Confounder;
-import org.apache.kerberos.crypto.DesStringToKey;
+import java.util.Map;
 
 
 /**
@@ -49,72 +48,41 @@
     {
        KdcConfiguration config = new KdcConfiguration();
        File tempBootstrapStore = new File(config.getKerberosKeysLocation());
-        if (tempBootstrapStore.exists()) {
+
+        if ( tempBootstrapStore.exists() )
+        {
             tempBootstrapStore.delete();
         }
+
        assertFalse( tempBootstrapStore.exists() );
     }
 
-    public void testKeyStoreCreation() throws Exception
+    public void testInitKeyStore() throws Exception
     {
         KdcConfiguration config = new KdcConfiguration();
 
-               Map entries = new HashMap();
+               BootstrapStore keyStore = new BootstrapStore(config);
 
-               addToMap(entries, makeRandomKeyFor(config.getKdcPrincipal()));
+        keyStore.init();
 
-        if ( config.getChangepwPrincipal() != null )
-        {
-                   addToMap(entries, 
makeRandomKeyFor(config.getChangepwPrincipal()));
-        }
-
-        if ( config.getLdapPrincipal() != null )
-        {
-                   addToMap(entries, makePredefinedKey(5, "1cb96792580404f8", 
config.getLdapPrincipal()));
-        }
-
-               FileOutputStream out = new 
FileOutputStream(config.getKerberosKeysLocation());
-               ObjectOutputStream s = new ObjectOutputStream(out);
-               s.writeObject(entries);
-               s.flush();
+        assertNotNull( keyStore.getEntry( config.getKdcPrincipal() ));
+        assertNotNull( keyStore.getEntry( config.getChangepwPrincipal() ));
        }
 
-       public void testKeyStore() throws Exception
+       public void testReadKeyStore() throws Exception
     {
         KdcConfiguration config = new KdcConfiguration();
 
-               FileInputStream in = new 
FileInputStream(config.getKerberosKeysLocation());
-               ObjectInputStream s = new ObjectInputStream(in);
-               Map map = (HashMap)s.readObject();
+               FileInputStream in = new FileInputStream( 
config.getKerberosKeysLocation() );
+               ObjectInputStream s = new ObjectInputStream( in );
+               Map map = ( HashMap ) s.readObject();
+
                Iterator it = map.values().iterator();
-               while (it.hasNext()) {
-                       KerberosKey key = (KerberosKey)it.next();
+               while ( it.hasNext() )
+        {
+                       KerberosKey key = ( KerberosKey ) it.next();
                        assertNotNull( key.getEncoded() );
                }
-       }
-
-    private KerberosKey makePredefinedKey(int keyVersion, String hexKey, 
KerberosPrincipal principal)
-    {
-        final int DES_KEY_TYPE = 3;
-
-               byte[] bytes = TestUtils.getBytesFromHexString(hexKey);
-               return new KerberosKey(principal, bytes, DES_KEY_TYPE, 
keyVersion);
-       }
-
-
-       private KerberosKey makeRandomKeyFor(KerberosPrincipal principal)
-    {
-        final int DES_KEY_TYPE = 3;
-               int keyVersion = 1;
-
-               byte[] randomBytes = Confounder.bytes(8);
-               DesStringToKey randomKey = new DesStringToKey(new 
String(randomBytes));
-               return new KerberosKey(principal, randomKey.getKey(), 
DES_KEY_TYPE, keyVersion);
-       }
-
-    private void addToMap(Map map, KerberosKey key)
-    {
-               map.put(key.getPrincipal().getName(), key);
        }
 }
 

Reply via email to