harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r506473 - in /harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/java/security/Provider.java test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java
Date Mon, 12 Feb 2007 14:58:41 GMT
Author: smishura
Date: Mon Feb 12 06:58:40 2007
New Revision: 506473

URL: http://svn.apache.org/viewvc?view=rev&rev=506473
Log:
Correct fix for HARMONY-2761
[classlib][security] Security.getProviders throws NumberFormatException unexpectedly

The case with KeySize attribute was a special case of the bug - NPE was thrown for other attributes
Also an attribute and its value should be case insensitive

Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java?view=diff&rev=506473&r1=506472&r2=506473
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java
Mon Feb 12 06:58:40 2007
@@ -310,32 +310,21 @@
     // returns true if the implementation meets the constraint expressed by the
     // specified attribute name/value pair.
     private boolean checkAttribute(String servAlg, String attribute, String val) {
-        if (attribute.equalsIgnoreCase("KeySize")) { //$NON-NLS-1$
-
-            String attributeValue = getProperty(servAlg + " KeySize"); //$NON-NLS-1$
-            if (attributeValue == null) {
-                // provider doesn't provide KeySize attribute for the service
-                return false;
-            }
-
-            if (Integer.valueOf(attributeValue).compareTo(Integer.valueOf(val)) < 0) {
-                return false;
-            } else {
-                return true;
-            }
-        } else if (attribute.equalsIgnoreCase("ImplementedId")) { //$NON-NLS-1$
-            if (!getProperty(servAlg + " ImplementedId").equals(val)) { //$NON-NLS-1$
-                return false;
-            } else {
-                return true;
-            }
-        } else { // other attributes
-            if (!getProperty(servAlg + " " + attribute).equals(val)) { //$NON-NLS-1$
-                return false;
-            } else {
-                return true;
+        
+        String attributeValue = getPropertyIgnoreCase(servAlg + ' ' + attribute);
+        if (attributeValue != null) {
+            if (attribute.equalsIgnoreCase("KeySize")) { //$NON-NLS-1$
+                if (Integer.valueOf(attributeValue).compareTo(
+                        Integer.valueOf(val)) >= 0) {
+                    return true;
+                }
+            } else { // other attributes
+                if (attributeValue.equalsIgnoreCase(val)) {
+                    return true;
+                }
             }
         }
+        return false;
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java?view=diff&rev=506473&r1=506472&r2=506473
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecurityTest.java
Mon Feb 12 06:58:40 2007
@@ -221,9 +221,23 @@
 
             filter = "MyService.MyAlgorithm KeySize:1025";
             assertNull(filter, Security.getProviders(filter));
-            
+
+            // attribute name and value are case insensitive 
+            filter = "MyService.MyAlgorithm imPLementedIn:softWARE";
+            assertTrue(filter, Arrays.equals(new Provider[] { p }, Security
+                    .getProviders(filter)));
+            filter = "MyService.MyAlgorithm ATTribute:attributeVALUE";
+            assertTrue(filter, Arrays.equals(new Provider[] { p }, Security
+                    .getProviders(filter)));
+
             // Regression for HARMONY-2761
-            filter = "MyService.MyAlgorithmNoKeySize KeySize:512";
+            filter = "MyService.NoKeySize KeySize:512";
+            assertNull(filter, Security.getProviders(filter));
+
+            filter = "MyService.NoImplementedIn ImplementedIn:Software";
+            assertNull(filter, Security.getProviders(filter));
+
+            filter = "ABCService.NoAttribute Attribute:ABC";
             assertNull(filter, Security.getProviders(filter));
         } finally { //clean up
             Security.removeProvider(p.getName());
@@ -274,11 +288,29 @@
             m.put("MessageDigest.SHA-1", "");
             assertNull("MyService.MyAlgorithm KeySize:1025", Security
                     .getProviders(m));
-            
+
+            // attribute name and value are case insensitive 
+            m.clear();
+            m.put("MyService.MyAlgorithm imPLementedIn", "softWARE");
+            assertTrue(Arrays.equals(new Provider[] { p }, Security
+                    .getProviders(m)));
+            m.clear();
+            m.put("MyService.MyAlgorithm ATTribute", "attributeVALUE");
+            assertTrue(Arrays.equals(new Provider[] { p }, Security
+                    .getProviders(m)));
+
             // Regression for HARMONY-2761
             m.clear();
-            m.put("MyService.MyAlgorithmNoKeySize KeySize", "512");
+            m.put("MyService.NoKeySize KeySize", "512");
             assertNull("No KeySize attribute", Security.getProviders(m));
+            
+            m.clear();
+            m.put("MyService.NoImplementedIn ImplementedIn", "Software");
+            assertNull("No ImplementedIn attribute", Security.getProviders(m));
+            
+            m.clear();
+            m.put("ABCService.NoAttribute Attribute", "ABC");
+            assertNull(Security.getProviders(m));
         } finally { //clean up
             Security.removeProvider(p.getName());
         }
@@ -328,10 +360,17 @@
             put("MessageDigest.SHA-1", "SomeClassName");
             put("MyService.MyAlgorithm", "SomeClassName");
             put("MyService.MyAlgorithm KeySize", "1024");
+            put("MyService.MyAlgorithm ImplementedIn", "Software");
+            put("MyService.MyAlgorithm Attribute", "AttributeValue");
 
             // service has no KeySize attribute
-            put("MyService.MyAlgorithmNoKeySize", "SomeClassName");
+            put("MyService.NoKeySize", "SomeClassName");
+
+            // service has no ImplementedIn attribute
+            put("MyService.NoImplementedIn", "SomeClassName");
+
+            // service has no 'Attribute' attribute
+            put("ABCService.NoAttribute", "SomeClassName");
         }
     }
-
 }



Mime
View raw message