harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r498914 - in /harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/java/security/ main/java/common/org/apache/harmony/security/internal/nls/ test/api/java/org/apache/harmony/security/tests/java/security/
Date Tue, 23 Jan 2007 04:25:49 GMT
Author: smishura
Date: Mon Jan 22 20:25:48 2007
New Revision: 498914

URL: http://svn.apache.org/viewvc?view=rev&rev=498914
Log:
Fix for KeyStoreSpi.engineLoad(KeyStore.LoadStoreParameter) method: 
* throw UnsupportedOperationException in case of null protection parameter
* add separate test case for the method

Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/KeyStoreSpi.java
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/KeyStoreSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/KeyStoreSpi.java?view=diff&rev=498914&r1=498913&r2=498914
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/KeyStoreSpi.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/KeyStoreSpi.java
Mon Jan 22 20:25:48 2007
@@ -84,10 +84,6 @@
         }
         char[] pwd;
         KeyStore.ProtectionParameter pp = param.getProtectionParameter();
-        if (pp == null) {
-            throw new IllegalArgumentException(
-                    Messages.getString("security.34")); //$NON-NLS-1$
-        }
         if (pp instanceof KeyStore.PasswordProtection) {
             try {
                 pwd = ((KeyStore.PasswordProtection) pp).getPassword();

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/internal/nls/messages.properties?view=diff&rev=498914&r1=498913&r2=498914
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/internal/nls/messages.properties
Mon Jan 22 20:25:48 2007
@@ -224,7 +224,6 @@
 security.31=target type field is corrupted
 security.32=Error decoding certificate
 security.33=Not Supported operation
-security.34=ProtectionParameter is not defined
 security.35=protectionParameter is neither PasswordProtection nor CallbackHandlerProtection
instance
 security.36=Password was destroyed
 security.37=ProtectionParameter object is not PasswordProtection: {0}

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java?view=diff&rev=498914&r1=498913&r2=498914
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java
Mon Jan 22 20:25:48 2007
@@ -21,17 +21,24 @@
 */
 
 package org.apache.harmony.security.tests.java.security;
-import java.security.*;
 import java.io.IOException;
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.KeyStoreSpi;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableEntryException;
+import java.security.UnrecoverableKeyException;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateException;
 import java.util.Date;
 
+import junit.framework.TestCase;
+
 import org.apache.harmony.security.tests.support.MyKeyStoreSpi;
+import org.apache.harmony.security.tests.support.MyLoadStoreParams;
 import org.apache.harmony.security.tests.support.cert.MyCertificate;
 
-import junit.framework.TestCase;
-
 
 /**
  * Tests for <code>KeyStoreSpi</code> constructor and methods
@@ -69,10 +76,6 @@
 
         tmpEntry entry = new tmpEntry();
         tmpProtection pPar = new tmpProtection();
-        try {
-            ksSpi.engineLoad(null);
-        } catch (UnsupportedOperationException e) {
-        }
 
         try {
             ksSpi.engineStore(null);
@@ -148,6 +151,44 @@
             ksSpi.engineStore(null, null);
             fail("IOException must be thrown");
         } catch (IOException e) {
+        }
+    }
+    
+    /**
+     * @tests java.security.KeyStoreSpi#engineLoad(KeyStore.LoadStoreParameter)
+     */
+    public void test_engineLoadLjava_security_KeyStore_LoadStoreParameter()
+            throws Exception {
+
+        final String msg = "error";
+
+        KeyStoreSpi ksSpi = new MyKeyStoreSpi() {
+            public void engineLoad(InputStream stream, char[] password) {
+                assertNull(stream);
+                assertNull(password);
+                throw new RuntimeException(msg);
+            }
+        };
+        try {
+            ksSpi.engineLoad(null);
+            fail("Should throw exception");
+        } catch (RuntimeException e) {
+            assertSame(msg, e.getMessage());
+        }
+
+        // test: protection parameter is null  
+        try {
+            ksSpi.engineLoad(new MyLoadStoreParams(null));
+            fail("No expected UnsupportedOperationException");
+        } catch (UnsupportedOperationException e) {
+        }
+
+        // test: protection parameter is not instanceof 
+        // PasswordProtection or CallbackHandlerProtection
+        try {
+            ksSpi.engineLoad(new MyLoadStoreParams(new tmpProtection()));
+            fail("No expected UnsupportedOperationException");
+        } catch (UnsupportedOperationException e) {
         }
     }
     



Mime
View raw message