harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r398904 - in /incubator/harmony/enhanced/classlib/trunk/modules/security: make/common/ src/main/java/common/java/security/ src/test/java/common/tests/api/java/security/
Date Tue, 02 May 2006 11:08:55 GMT
Author: mloenko
Date: Tue May  2 04:08:53 2006
New Revision: 398904

URL: http://svn.apache.org/viewcvs?rev=398904&view=rev
Log:
fixes for HARMONY-430
security tests failures

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/make/common/build.xml
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Security.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/AlgorithmParameterGeneratorTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/AlgorithmParametersTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SecurityTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/make/common/build.xml
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/make/common/build.xml?rev=398904&r1=398903&r2=398904&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/make/common/build.xml (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/make/common/build.xml Tue May
 2 04:08:53 2006
@@ -114,16 +114,15 @@
 
                     <!-- Harmony exclude list -->
                     <exclude name="java/security/serialization/KeyPairTest.java"/>
-                    <exclude name="java/security/serialization/AccessControlExceptionTest.java"/>
-                    <exclude name="java/security/serialization/InvalidParameterExceptionTest.java"/>
-
+                    <!-- Designed to run via classpath -->
                     <exclude name="tests/api/java/security/AccessControllerTest.java"/>
-                    <exclude name="tests/api/java/security/AlgorithmParameterGeneratorTest.java"/>
-                    <exclude name="tests/api/java/security/AlgorithmParametersTest.java"/>
+                    <!-- test excluded due BC bug -->
                     <exclude name="tests/api/java/security/KeyStoreTest.java"/>
-                    <exclude name="tests/api/java/security/PermissionCollectionTest.java"/>
+                    <!-- Designed to run via classpath -->
+                    <exclude name="tests/api/java/security/PermissionCollectionTest.java"/>
                   
+                    <!-- No SHA1PRNG implementation yet -->
                     <exclude name="tests/api/java/security/SecureRandomTest.java"/>
-                    <exclude name="tests/api/java/security/SecurityTest.java"/>
+
                     <exclude name="tests/api/java/security/cert/CertificateFactoryTest.java"/>
                     <exclude name="tests/api/java/security/cert/X509CertificateTest.java"/>
                     <exclude name="tests/api/java/security/cert/X509CRLEntryTest.java"/>

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Security.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Security.java?rev=398904&r1=398903&r2=398904&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Security.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Security.java
Tue May  2 04:08:53 2006
@@ -306,10 +306,18 @@
                             "The fillter is not in the required format");
                 }
                 attribute = key.substring(i + 1);
+                if (attribute.trim().length() == 0) {
+                    throw new InvalidParameterException(
+                            "The fillter is not in the required format");
+                }
                 key = key.substring(0, i);
             }
             String serv = key.substring(0, j);
             String alg = key.substring(j + 1);
+            if (serv.length() == 0 || alg.length() == 0) {
+                throw new InvalidParameterException(
+                        "The fillter is not in the required format");
+            }
             Provider p;
             for (int k = 0; k < result.size(); k++) {
                 try {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/AlgorithmParameterGeneratorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/AlgorithmParameterGeneratorTest.java?rev=398904&r1=398903&r2=398904&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/AlgorithmParameterGeneratorTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/AlgorithmParameterGeneratorTest.java
Tue May  2 04:08:53 2006
@@ -18,6 +18,7 @@
 import java.math.BigInteger;
 import java.security.AlgorithmParameterGenerator;
 import java.security.AlgorithmParameters;
+import java.security.InvalidAlgorithmParameterException;
 import java.security.NoSuchProviderException;
 import java.security.Provider;
 import java.security.SecureRandom;
@@ -151,14 +152,19 @@
 	 * @tests java.security.AlgorithmParameterGenerator#init(java.security.spec.AlgorithmParameterSpec)
 	 */
 	public void test_initLjava_security_spec_AlgorithmParameterSpec() throws Exception {
-        	// Test for method void
-        	// java.security.AlgorithmParameterGenerator.init(java.security.spec.AlgorithmParameterSpec)
-        	// checks that no exception is thrown
-       		DSAParameterSpec spec = new DSAParameterSpec(BigInteger.ONE,
-       				BigInteger.ONE, BigInteger.ONE);
-       		AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
-       				.getInstance("DSA");
-       		gen.init(spec);
+        // Test for method void
+        // java.security.AlgorithmParameterGenerator.init(java.security.spec.AlgorithmParameterSpec)
+        // checks that InvalidAlgorithmParameterException is thrown
+        DSAParameterSpec spec = new DSAParameterSpec(BigInteger.ONE,
+                BigInteger.ONE, BigInteger.ONE);
+        AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
+                .getInstance("DSA");
+        try {
+            gen.init(spec);
+            fail("No expected InvalidAlgorithmParameterException");
+        } catch (InvalidAlgorithmParameterException e) {
+            //expected
+        }
 	}
 
 	/**
@@ -166,14 +172,19 @@
 	 *        java.security.SecureRandom)
 	 */
 	public void test_initLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom()
throws Exception {
-		// Test for method void
-		// java.security.AlgorithmParameterGenerator.init(java.security.spec.AlgorithmParameterSpec,
-		// java.security.SecureRandom)
-        	// checks that no exception is thrown
-		DSAParameterSpec spec = new DSAParameterSpec(BigInteger.ONE,
-				BigInteger.ONE, BigInteger.ONE);
-		AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
-				.getInstance("DSA");
-		gen.init(spec, new SecureRandom());
+        // Test for method void
+        // java.security.AlgorithmParameterGenerator.init(java.security.spec.AlgorithmParameterSpec,
+        // java.security.SecureRandom)
+        // checks that InvalidAlgorithmParameterException  is thrown
+        DSAParameterSpec spec = new DSAParameterSpec(BigInteger.ONE,
+                BigInteger.ONE, BigInteger.ONE);
+        AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
+                .getInstance("DSA");
+        try {
+            gen.init(spec, new SecureRandom());
+            fail("No expected InvalidAlgorithmParameterException");
+        } catch (InvalidAlgorithmParameterException e) {
+            //expected
+        }
 	}
-}
\ No newline at end of file
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/AlgorithmParametersTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/AlgorithmParametersTest.java?rev=398904&r1=398903&r2=398904&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/AlgorithmParametersTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/AlgorithmParametersTest.java
Tue May  2 04:08:53 2006
@@ -62,24 +62,24 @@
 	/**
 	 * @tests java.security.AlgorithmParameters#getEncoded(java.lang.String)
 	 */
-	public void test_getEncodedLjava_lang_String() throws Exception {
-		// Test for method byte []
-		// java.security.AlgorithmParameters.getEncoded(java.lang.String)
-		AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
-
-		byte[] enc = null;
-		try {
-			params.init(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
-					BigInteger.ONE));
-			enc = params.getEncoded("JUNK");
-			fail("bogus format should have resulted in IOException");
-		} catch (IOException e) {
-			// expected
-		}
-
-		enc = params.getEncoded("ASN.1");
-		assertNotNull("ANS.1 should be supported", enc);
-	}
+    public void test_getEncodedLjava_lang_String() throws Exception {
+        // Test for method byte []
+        // java.security.AlgorithmParameters.getEncoded(java.lang.String)
+        AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
+
+        params.init(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
+                BigInteger.ONE));
+        
+        // getEncoded behavior is not specified for unknown 'format'
+        // different providers work in different manner:
+        // 1.5 RI provider uses primary encoding format,
+        // but BC provider returns null.
+        // As it is provider specific behavior - it is not tested.
+        //byte[] enc = params.getEncoded("JUNK");
+
+        byte[] enc = params.getEncoded("ASN.1");
+        assertNotNull("ANS.1 should be supported", enc);
+    }
 
 	/**
 	 * @tests java.security.AlgorithmParameters#getInstance(java.lang.String)
@@ -133,83 +133,58 @@
 	/**
 	 * @tests java.security.AlgorithmParameters#getProvider()
 	 */
-	public void test_getProvider() {
+	public void test_getProvider() throws Exception {
 		// Test for method java.security.Provider
 		// java.security.AlgorithmParameters.getProvider()
-		try {
-			Provider p = AlgorithmParameters.getInstance("DSA").getProvider();
-			assertNotNull("provider is null", p);
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm");
-		}
+        Provider p = AlgorithmParameters.getInstance("DSA").getProvider();
+        assertNotNull("provider is null", p);
+
 	}
 
 	/**
 	 * @tests java.security.AlgorithmParameters#init(byte[])
 	 */
-	public void test_init$B() {
+	public void test_init$B() throws Exception {
 		// Test for method void java.security.AlgorithmParameters.init(byte [])
-		try {
-			AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
-			params.init(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
-					BigInteger.ONE));
-			byte[] encoded = params.getEncoded();
-			assertNotNull("encoded spec is null", encoded);
-			AlgorithmParameters params2 = AlgorithmParameters
-					.getInstance("DSA");
-			params2.init(encoded);
-			byte[] encodedAfter = params2.getEncoded();
-			assertTrue("param encoded is different", Arrays.equals(encoded,
-					encodedAfter));
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm");
-		} catch (IOException e) {
-			fail("IOException getting encoded");
-		} catch (InvalidParameterSpecException e) {
-			fail("cant pass DSAParameterSpec");
-		}
+        AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
+        params.init(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
+                BigInteger.ONE));
+        byte[] encoded = params.getEncoded();
+        assertNotNull("encoded spec is null", encoded);
+        AlgorithmParameters params2 = AlgorithmParameters.getInstance("DSA");
+        params2.init(encoded);
+        byte[] encodedAfter = params2.getEncoded();
+        assertTrue("param encoded is different", Arrays.equals(encoded,
+                encodedAfter));
 	}
 
 	/**
 	 * @tests java.security.AlgorithmParameters#init(byte[], java.lang.String)
 	 */
-	public void test_init$BLjava_lang_String() {
+	public void test_init$BLjava_lang_String() throws Exception {
 		// Test for method void java.security.AlgorithmParameters.init(byte [],
 		// java.lang.String)
-		try {
-			AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
-			params.init(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
-					BigInteger.ONE));
-			byte[] encoded = params.getEncoded();
-			assertNotNull("encoded spec is null", encoded);
-			AlgorithmParameters params2 = AlgorithmParameters
-					.getInstance("DSA");
-			params2.init(encoded, "ASN.1");
-			byte[] encodedAfter = params2.getEncoded();
-			assertTrue("param encoded is different", Arrays.equals(encoded,
-					encodedAfter));
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm");
-		} catch (IOException e) {
-			fail("IOException getting encoded");
-		} catch (InvalidParameterSpecException e) {
-			fail("cant pass DSAParameterSpec");
-		}
+        AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
+        params.init(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
+                BigInteger.ONE));
+        byte[] encoded = params.getEncoded();
+        assertNotNull("encoded spec is null", encoded);
+        AlgorithmParameters params2 = AlgorithmParameters.getInstance("DSA");
+        params2.init(encoded, "ASN.1");
+        byte[] encodedAfter = params2.getEncoded();
+        assertTrue("param encoded is different", Arrays.equals(encoded,
+                encodedAfter));
 
 		try {
-			AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
+			params = AlgorithmParameters.getInstance("DSA");
 			params.init(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
 					BigInteger.ONE));
-			byte[] encoded = params.getEncoded();
+			encoded = params.getEncoded();
 			assertNotNull("encoded spec is null", encoded);
 			params.init(encoded, "DOUGLASMAWSON");
 			fail("unsupported format should have raised IOException");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm");
 		} catch (IOException e) {
 			// expected
-		} catch (InvalidParameterSpecException e) {
-			fail("cant pass DSAParameterSpec");
 		}
 
 	}
@@ -217,36 +192,23 @@
 	/**
 	 * @tests java.security.AlgorithmParameters#init(java.security.spec.AlgorithmParameterSpec)
 	 */
-	public void test_initLjava_security_spec_AlgorithmParameterSpec() {
+	public void test_initLjava_security_spec_AlgorithmParameterSpec() throws Exception {
 		// Test for method void
 		// java.security.AlgorithmParameters.init(java.security.spec.AlgorithmParameterSpec)
 		AlgorithmParameters params = null;
-		try {
-			params = AlgorithmParameters.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm");
-		}
-
-		try {
-			params.init(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
-					BigInteger.ONE));
-		} catch (InvalidParameterSpecException e) {
-			fail("cant pass DSAParameterSpec");
-		}
+        params = AlgorithmParameters.getInstance("DSA");
+        params.init(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
+                BigInteger.ONE));
 	}
 
 	/**
 	 * @tests java.security.AlgorithmParameters#toString()
 	 */
-	public void test_toString() {
+	public void test_toString() throws Exception {
 		// Test for method java.lang.String
 		// java.security.AlgorithmParameters.toString()
-		try {
-			String str = AlgorithmParameters.getInstance("DSA").toString();
-			assertNull("toString should be null", str);
-		} catch (NoSuchAlgorithmException e) {
-			e.printStackTrace();
-			assertTrue("getInstance did not find algorithm", false);
-		}
+        String str = AlgorithmParameters.getInstance("DSA").toString();
+        assertNull("toString should be null", str);
+
 	}
-}
\ No newline at end of file
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SecurityTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SecurityTest.java?rev=398904&r1=398903&r2=398904&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SecurityTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SecurityTest.java
Tue May  2 04:08:53 2006
@@ -38,7 +38,6 @@
 		// java.security.Security.getProperty(java.lang.String)
 		Security.setProperty("keyTestAlternate", "testing a property set");
 		assertEquals("the property value returned for keyTestAlternate was incorrect",
-				
 						"testing a property set", Security.getProperty("keyTestAlternate"));
 	}
 
@@ -53,7 +52,6 @@
 
 		Security.setProperty("keyTest", "permission to set property");
 		assertEquals("the property value returned for keyTest was not correct",
-				
 						"permission to set property", Security.getProperty("keyTest"));
 
 	}
@@ -80,8 +78,6 @@
 			// providers.
 			assertTrue("provider is not found at the expected position",
 					provTest[prefPos - 1].getName().equals(rsaName));
-		} catch (Exception e) {
-			fail("Unexpected exception : " + e);
 		} finally {
 			// Now remove it - does nothing if provider not actually installed
 			Security.removeProvider(rsaName);
@@ -98,8 +94,6 @@
 					result2.getName().equals(test.getName())
 							&& result2.getInfo().equals(test.getInfo())
 							&& result2.getVersion() == test.getVersion());
-		} catch (Exception e) {
-			fail("Unexpected exception : " + e);
 		} finally {
 			// Now remove it - does nothing if provider not actually installed
 			Security.removeProvider(test.getName());
@@ -126,8 +120,6 @@
 			Security.getProviders();
 			assertEquals("addProvider method did not return a -1 for "
 					+ "a provider already added", -1, prefPosEntAdded);
-		} catch (Exception e) {
-			fail("Unexpected exception : " + e);
 		} finally {
 			// Now remove it - does nothing if provider not actually installed
 			Security.removeProvider(entrust.getName());
@@ -251,9 +243,6 @@
 			fail("InvalidParameterException should be thrown <Signature.SHA1withDSA :512>");
 		} catch (InvalidParameterException e) {
 			// Expected
-		} catch (Exception e) {
-			fail("<Signature.SHA1withDSA :512> - Expected InvalidParameterException but got
a "
-					+ e);
 		}
 	}
 
@@ -415,13 +404,8 @@
 		filter = new Hashtable();
 		filter.put("Provider.id name", "DRLCertFactory");
 		provTest = Security.getProviders(filter);
-		if (provTest == null) {
-			assertEquals("Filter : <Provider.id name, DRLCertFactory >",
-					0, getProvidersCount(filter));
-		} else {
-			assertEquals("Filter : <Provider.id name, DRLCertFactory>",
-					getProvidersCount(filter), provTest.length);
-		}
+        assertEquals("Filter : <Provider.id name, DRLCertFactory >",
+                null, provTest);
 
 		// exception - no attribute name after the service.algorithm yet we
 		// still supply an expected value. This is not valid.
@@ -432,9 +416,6 @@
 			fail("InvalidParameterException should be thrown <Signature.SHA1withDSA><512>");
 		} catch (InvalidParameterException e) {
 			// Expected
-		} catch (Exception e) {
-			fail("InvalidParameterException was expected for"
-					+ " <Signature.SHA1withDSA><512> " + " but we got a " + e);
 		}
 
 		// exception - space character in the service.algorithm pair. Not valid.
@@ -445,9 +426,6 @@
 			fail("InvalidParameterException should be thrown <Signature. KeySize><512>");
 		} catch (InvalidParameterException e) {
 			// Expected
-		} catch (Exception e) {
-			fail("InvalidParameterException was expected for"
-					+ " <Signature. KeySize><512> " + " but we got a " + e);
 		}
 	}
 
@@ -478,8 +456,6 @@
 			int referAdded = Security.insertProviderAt(jceProvider, 3);
 			assertEquals("the method insertProviderAt did not "
 					+ "return a -1 for providers already added", -1, referAdded);
-		} catch (Exception e) {
-			fail("Unexpected exception : " + e);
 		} finally {
 			// Tidy up before we leave
 			Security.removeProvider(jceProvider.getName());
@@ -523,8 +499,6 @@
 						"the provider entrust is found after it was removed",
 						provTest[i].getName() != entrust.getName());
 			}
-		} catch (Exception e) {
-			fail("Unexpected exception : " + e);
 		} finally {
 			// Tidy up - the following calls do nothing if the providers were
 			// already removed above.



Mime
View raw message