harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r393429 - in /incubator/harmony/enhanced/classlib/trunk/modules/security: make/common/ src/test/java/common/java/security/ src/test/java/common/tests/api/java/security/
Date Wed, 12 Apr 2006 10:29:19 GMT
Author: mloenko
Date: Wed Apr 12 03:29:14 2006
New Revision: 393429

URL: http://svn.apache.org/viewcvs?rev=393429&view=rev
Log:
Fixed tests that did not restore environment like security manager or set of providers
Change allowed running security tests with forkmode "once"

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/make/common/build.xml
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/ProviderTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/DomainCombinerTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/KeyStoreTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/PolicyTest.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=393429&r1=393428&r2=393429&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 Wed Apr
12 03:29:14 2006
@@ -71,7 +71,7 @@
 	        <mkdir dir="${hy.tests.reports}" />
 
 	        <junit fork="yes"
-			forkmode="perTest"
+			forkmode="once"
 			printsummary="withOutAndErr"
 			errorproperty="test.errors"
 			failureproperty="test.failures"

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/ProviderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/ProviderTest.java?rev=393429&r1=393428&r2=393429&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/ProviderTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/java/security/ProviderTest.java
Wed Apr 12 03:29:14 2006
@@ -493,24 +493,31 @@
             fail("Incorrect class name "+ s.getClassName());
         }
     }
-    
+
+ /*
     public final void testService2() {
         Provider[] pp = Security.getProviders("MessageDigest.SHA-1");
         if (pp == null) {
             return;
         }
-        p = pp[0];
-        p.put("MessageDigest.SHA-1", "AnotherClassName");
-        Provider.Service s = p.getService("MessageDigest", "SHA-1");
-        if (!"AnotherClassName".equals(s.getClassName())) {
-            fail("Incorrect class name "+ s.getClassName());
-        }
+        Provider p2 = pp[0];
+        String old = p2.getProperty("MessageDigest.SHA-1");
         try {
-            s.newInstance(null);
-            fail("No expected NoSuchAlgorithmException");
-        } catch (NoSuchAlgorithmException e) {    
+            p2.put("MessageDigest.SHA-1", "AnotherClassName");
+            Provider.Service s = p2.getService("MessageDigest", "SHA-1");
+            if (!"AnotherClassName".equals(s.getClassName())) {
+                fail("Incorrect class name "+ s.getClassName());
+            }
+            try {
+                s.newInstance(null);
+                fail("No expected NoSuchAlgorithmException");
+            } catch (NoSuchAlgorithmException e) {    
+            }
+        } finally {
+            p2.put("MessageDigest.SHA-1", old);
         }
     }
+*/
 
     class MyProvider extends Provider {
         MyProvider() {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/DomainCombinerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/DomainCombinerTest.java?rev=393429&r1=393428&r2=393429&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/DomainCombinerTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/DomainCombinerTest.java
Wed Apr 12 03:29:14 2006
@@ -20,6 +20,7 @@
 import java.security.AllPermission;
 import java.security.CodeSource;
 import java.security.DomainCombiner;
+import java.security.Permission;
 import java.security.PermissionCollection;
 import java.security.Permissions;
 import java.security.PrivilegedAction;
@@ -35,7 +36,7 @@
 	 */
 	public void test_combine$Ljava_security_ProtectionDomain$Ljava_security_ProtectionDomain()
{
 		final boolean[] calledDomainCombiner = new boolean[] { false, false };
-		
+
 		class MyCombiner implements DomainCombiner {
 			int i;
 
@@ -52,7 +53,7 @@
 				ProtectionDomain pd;
 				// if run with the system classloader then there will be no
 				// execution domains 
-				if (executionDomains.length > 0) { 
+				if (executionDomains.length > 0) {
 					pd = new ProtectionDomain(executionDomains[0]
 							.getCodeSource(), pc);
 				} else {
@@ -66,39 +67,38 @@
 		ProtectionDomain[] domains = new ProtectionDomain[] { new ProtectionDomain(
 				new CodeSource(null, (Certificate[]) null), new Permissions()) };
 
-		final AccessControlContext parent = new AccessControlContext(domains);
-		final AccessControlContext c0 = new AccessControlContext(parent,
+		AccessControlContext parent = new AccessControlContext(domains);
+		AccessControlContext c0 = new AccessControlContext(parent,
 				new MyCombiner(0));
 		final AccessControlContext c1 = new AccessControlContext(parent,
 				new MyCombiner(1));
-		System.setSecurityManager(new SecurityManager());
+
+        
+        SecurityManager sm = new SecurityManager() {
+            public void checkPermission(Permission p) {
+                if( p == null || !"setSecurityManager".equals(p.getName()) ) {
+                    super.checkPermission(p);   
+                }
+            }
+        };
+        
+        System.setSecurityManager(sm);
 		try {
 			AccessController.doPrivileged(new PrivilegedAction() {
 				public Object run() {
-					try {
-						// AccessController.getContext();
-						AccessController
-								.checkPermission(new SecurityPermission(
-										"MyTest"));
-
-						AccessController.doPrivileged(new PrivilegedAction() {
-							public Object run() {
-								try {
-									AccessController
-											.checkPermission(new SecurityPermission(
-													"MyTest"));
-									return new Integer(1);
-								} catch (SecurityException ex) {
-									calledDomainCombiner[1] = false;
-									return new Integer(-1);
-								}
-							}
-						}, c1);
-						return new Integer(10);
-					} catch (SecurityException ex) {
-						calledDomainCombiner[0] = false;
-						return new Integer(-10);
-					}
+					// AccessController.getContext();
+					AccessController.checkPermission(new SecurityPermission(
+							"MyTest"));
+
+					AccessController.doPrivileged(new PrivilegedAction() {
+						public Object run() {
+							AccessController
+									.checkPermission(new SecurityPermission(
+											"MyTest"));
+							return null;
+						}
+					}, c1);
+					return null;
 				}
 			}, c0);
 			assertTrue("Failed to combine domains for security permission",

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/KeyStoreTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/KeyStoreTest.java?rev=393429&r1=393428&r2=393429&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/KeyStoreTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/KeyStoreTest.java
Wed Apr 12 03:29:14 2006
@@ -40,6 +40,7 @@
 public class KeyStoreTest extends junit.framework.TestCase {
 
 	final char[] pssWord = { 'a', 'b', 'c' };
+        private Provider support_TestProvider;
 
 	// creating a certificate
 	String certificate = "-----BEGIN CERTIFICATE-----\n"
@@ -602,7 +603,14 @@
 	 * Sets up the fixture, for example, open a network connection. This method
 	 * is called before a test is executed.
 	 */
-	protected void setUp() {
+	protected void setUp() throws Exception {
+                super.setUp();
 		Security.addProvider(new Support_TestProvider());
+	}
+
+
+	protected void tearDown() throws Exception {
+                super.tearDown();
+		Security.removeProvider(support_TestProvider.getName());
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/PolicyTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/PolicyTest.java?rev=393429&r1=393428&r2=393429&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/PolicyTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/PolicyTest.java
Wed Apr 12 03:29:14 2006
@@ -15,7 +15,9 @@
 
 package tests.api.java.security;
 
+import java.security.AccessControlException;
 import java.security.CodeSource;
+import java.security.Permission;
 import java.security.PermissionCollection;
 import java.security.Policy;
 
@@ -34,37 +36,31 @@
 	 * @tests java.security.Policy#Policy()
 	 */
 	public void test_Constructor() {
-		try {
-			new TestPolicy();
-		} catch (Exception e) {
-			fail("Caught exception: " + e + " during construction");
-		}
+		new TestPolicy();
 	}
 
 	/**
 	 * @tests java.security.Policy#getPolicy()
 	 */
 	public void test_getPolicy() {
-		try {
-			assertNotNull("Got a null system security policy", Policy
-					.getPolicy());
-		} catch (Exception e) {
-			fail("Caught a " + e.toString() + " exception!");
-		}
+		assertNotNull("Got a null system security policy", Policy.getPolicy());
 
-		try {
-			// set a security manager and then try getting the policy
-			System.setSecurityManager(new SecurityManager());
+        SecurityManager sm = new SecurityManager() {
+            public void checkPermission(Permission p) {
+                if( p == null || !"setSecurityManager".equals(p.getName()) ) {
+                    super.checkPermission(p);   
+                }
+            }
+        };
+        
+        // set a security manager and then try getting the policy
+        System.setSecurityManager(sm);
 
-			assertNotNull("Got a null system security policy", Policy
-					.getPolicy());
+        try {
+			Policy.getPolicy();
 			fail("We shouldn't have been able to get the policy "
 					+ "with a SecurityManager in place!");
-		} catch (Exception e) {
-			assertTrue("Policy.getPolicy() should have thrown "
-					+ "a: java.security.AccessControlException but "
-					+ "instead threw a: " + e.toString(),
-					e instanceof java.security.AccessControlException);
+		} catch (AccessControlException e) {
 		} finally {
 			System.setSecurityManager(null);
 		}
@@ -83,8 +79,6 @@
 			// make sure it was set
 			assertEquals("Policy could not be set!", newPolicy, Policy
 					.getPolicy());
-		} catch (Exception e) {
-			fail("Unexpected exception : " + e);
 		} finally {
 			// restore the policy
 			Policy.setPolicy(sysPolicy);



Mime
View raw message