harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r725021 - in /harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security: KeyStore2Test.java KeyStore3Test.java
Date Wed, 10 Dec 2008 07:25:05 GMT
Author: tonywu
Date: Tue Dec  9 23:25:04 2008
New Revision: 725021

URL: http://svn.apache.org/viewvc?rev=725021&view=rev
Log:
Add some testcases for KeyStore

Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore3Test.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java?rev=725021&r1=725020&r2=725021&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java
Tue Dec  9 23:25:04 2008
@@ -19,19 +19,28 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.Key;
 import java.security.KeyPair;
 import java.security.KeyPairGenerator;
 import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.KeyStoreSpi;
+import java.security.NoSuchAlgorithmException;
 import java.security.PrivateKey;
 import java.security.Provider;
 import java.security.PublicKey;
 import java.security.SecureRandom;
 import java.security.Security;
 import java.security.UnrecoverableKeyException;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Set;
@@ -588,6 +597,122 @@
 
 		assertEquals("the size of the keyStore is not 3", 3, keyTest.size());
 	}
+    
+    
+    public void test_Constructor() throws Exception {
+        KeyStore ks = new MockKeyStore(new MockKeyStoreSpi(), null,
+                "MockKeyStore");
+        ks.load(null, null);
+        ks.store(null, null);
+
+        ks = new MockKeyStore(new MockKeyStoreSpi(), null, "MockKeyStore");
+        ks.load(null);
+        try {
+            ks.store(null);
+            fail("should throw UnsupportedOperationException.");
+        } catch (UnsupportedOperationException e) {
+            // expected.
+        }
+    }
+    
+    public class MockKeyStore extends KeyStore{
+
+        public MockKeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type) {
+            super(keyStoreSpi, provider, type);            
+        }
+    }
+    
+    public class MockKeyStoreSpi extends KeyStoreSpi {
+
+        @Override
+        public Enumeration<String> engineAliases() {
+            return null;
+        }
+
+        @Override
+        public boolean engineContainsAlias(String alias) {
+            return false;
+        }
+
+        @Override
+        public void engineDeleteEntry(String alias) throws KeyStoreException {
+            return;
+        }
+
+        @Override
+        public Certificate engineGetCertificate(String alias) {
+            return null;
+        }
+
+        @Override
+        public String engineGetCertificateAlias(Certificate cert) {
+            return null;
+        }
+
+        @Override
+        public Certificate[] engineGetCertificateChain(String alias) {
+            return null;
+        }
+
+        @Override
+        public Date engineGetCreationDate(String alias) {
+            return null;
+        }
+
+        @Override
+        public Key engineGetKey(String alias, char[] password)
+                throws NoSuchAlgorithmException, UnrecoverableKeyException {
+            return null;
+        }
+
+        @Override
+        public boolean engineIsCertificateEntry(String alias) {
+            return false;
+        }
+
+        @Override
+        public boolean engineIsKeyEntry(String alias) {
+            return false;
+        }
+
+        @Override
+        public void engineLoad(InputStream stream, char[] password)
+                throws IOException, NoSuchAlgorithmException,
+                CertificateException {
+            return;
+        }
+
+        @Override
+        public void engineSetCertificateEntry(String alias, Certificate cert)
+                throws KeyStoreException {
+            return;
+        }
+
+        @Override
+        public void engineSetKeyEntry(String alias, Key key, char[] password,
+                Certificate[] chain) throws KeyStoreException {
+            return;
+        }
+
+        @Override
+        public void engineSetKeyEntry(String alias, byte[] key,
+                Certificate[] chain) throws KeyStoreException {
+            return;
+        }
+
+        @Override
+        public int engineSize() {
+            return 0;
+        }
+
+        @Override
+        public void engineStore(OutputStream stream, char[] password)
+                throws IOException, NoSuchAlgorithmException,
+                CertificateException {
+            return;
+        }
+        
+    }
 
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore3Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore3Test.java?rev=725021&r1=725020&r2=725021&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore3Test.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore3Test.java
Tue Dec  9 23:25:04 2008
@@ -18,6 +18,7 @@
 package org.apache.harmony.security.tests.java.security;
 
 import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -30,6 +31,9 @@
 import java.security.NoSuchAlgorithmException;
 import java.security.Provider;
 import java.security.UnrecoverableKeyException;
+import java.security.KeyStore.Builder;
+import java.security.KeyStore.PasswordProtection;
+import java.security.KeyStore.ProtectionParameter;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
@@ -148,6 +152,31 @@
         mockKeyStore.store(null, null);
     }
     
+    public void test_getKeyStore() throws KeyStoreException,
+            NoSuchAlgorithmException, CertificateException,
+            FileNotFoundException, IOException {
+
+        String alias = "JKS";
+        char[] pwd = new char[] { '1', '2', '3', '4', '5', '6' };
+        InputStream fis = KeyStore2Test.class
+                .getResourceAsStream("builderimpl.ks");
+        KeyStore ks = KeyStore.getInstance(alias);
+        ks.load(fis, pwd);
+        Builder b = Builder.newInstance(ks, new PasswordProtection(pwd));
+        KeyStore firstKeyStore = b.getKeyStore();
+        ProtectionParameter firstProtParameter = b
+                .getProtectionParameter(alias);
+        assertSame(firstKeyStore, b.getKeyStore());
+        assertSame(firstProtParameter, b.getProtectionParameter(alias));
+
+        b = Builder.newInstance(alias, ks.getProvider(),
+                new KeyStore.PasswordProtection(pwd));
+        firstKeyStore = b.getKeyStore();
+        firstProtParameter = b.getProtectionParameter(alias);
+        assertNotSame(firstKeyStore, b.getKeyStore());
+        assertSame(firstProtParameter, b.getProtectionParameter(alias));
+    }
+    
     protected void setUp() throws Exception {
         super.setUp();
         mockKeyStore = new MyKeyStore(new MyKeyStoreSpi(), null, "MyKeyStore");



Mime
View raw message