harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r469230 - in /incubator/harmony/enhanced/classlib/trunk/modules: luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ luni/src/test/java/tests/api/java/net/ security/src/test/api/java/org/apache/harmony/security/tests/java/security/
Date Mon, 30 Oct 2006 18:57:49 GMT
Author: tellison
Date: Mon Oct 30 10:57:48 2006
New Revision: 469230

URL: http://svn.apache.org/viewvc?view=rev&rev=469230
Log:
Apply patch HARMONY-1674 ([classlib][luni/security] Tests depend on presence of ~/.java.policy
file)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MutableSecurityManager.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetAddressTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AccessController2Test.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Policy2Test.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MutableSecurityManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MutableSecurityManager.java?view=diff&rev=469230&r1=469229&r2=469230
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MutableSecurityManager.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MutableSecurityManager.java
Mon Oct 30 10:57:48 2006
@@ -25,6 +25,8 @@
     static final RuntimePermission SET_SECURITY_MANAGER = new RuntimePermission("setSecurityManager");
     
     private final Set<Permission> permissions;
+    
+    private String deny;
 
     public MutableSecurityManager() {
         super();
@@ -49,11 +51,18 @@
     void clearPermissions() {
         permissions.clear();
     }
+    
+    void denyPermission(String name) {
+        deny = name;
+    }
 
     @Override
     public void checkPermission(Permission permission) {
         if (permissions.contains(permission)) {
             return;
+        }
+        if (permission.getName().equals(deny)){
+            throw new SecurityException();
         }
         super.checkPermission(permission);
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java?view=diff&rev=469230&r1=469229&r2=469230
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java
Mon Oct 30 10:57:48 2006
@@ -16,6 +16,10 @@
 
 package org.apache.harmony.luni.tests.java.lang;
 
+import java.io.File;
+
+import tests.support.Support_Exec;
+
 import junit.framework.TestCase;
 
 public class SecurityManagerTest extends TestCase {
@@ -26,6 +30,7 @@
     public void test_checkMemberAccessLjava_lang_ClassI() {
         MutableSecurityManager sm = new MutableSecurityManager();
         sm.addPermission(MutableSecurityManager.SET_SECURITY_MANAGER);
+        sm.denyPermission("accessDeclaredMembers");
         System.setSecurityManager(sm);
         try {
             try {
@@ -48,19 +53,42 @@
     /**
      * @tests java.lang.SecurityManager#checkPermission(java.security.Permission)
      */
-    public void test_checkPermissionLjava_security_Permission() {
-        MutableSecurityManager sm = new MutableSecurityManager();
-        sm.addPermission(MutableSecurityManager.SET_SECURITY_MANAGER);
-        System.setSecurityManager(sm);
-        try {
+    public void test_checkPermissionLjava_security_Permission()
+            throws Exception {
+
+        // tmp user home to avoid presence of ${user.home}/.java.policy
+        String tmpUserHome = System.getProperty("java.io.tmpdir")
+                + File.separatorChar + "tmpUserHomeForSecurityManagerTest";
+        File dir = new File(tmpUserHome);
+        if (!dir.exists()) {
+            dir.mkdirs();
+            dir.deleteOnExit();
+        }
+        String javaPolycy = tmpUserHome + File.separatorChar + ".java.policy";
+        assertFalse("There should be no java policy file: " + javaPolycy,
+                new File(javaPolycy).exists());
+
+        String[] arg = new String[] { "-Duser.home=" + tmpUserHome,
+                checkPermissionLjava_security_PermissionTesting.class.getName() };
+
+        Support_Exec.execJava(arg, null, true);
+    }
+
+    private static class checkPermissionLjava_security_PermissionTesting {
+        public static void main(String[] args) {
+            MutableSecurityManager sm = new MutableSecurityManager();
+            sm.addPermission(MutableSecurityManager.SET_SECURITY_MANAGER);
+            System.setSecurityManager(sm);
             try {
-                System.getSecurityManager().checkPermission(
-                        new RuntimePermission("createClassLoader"));
-                fail("This should throw a SecurityException");
-            } catch (SecurityException e) {
+                try {
+                    System.getSecurityManager().checkPermission(
+                            new RuntimePermission("createClassLoader"));
+                    fail("This should throw a SecurityException");
+                } catch (SecurityException e) {
+                }
+            } finally {
+                System.setSecurityManager(null);
             }
-        } finally {
-            System.setSecurityManager(null);
         }
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetAddressTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetAddressTest.java?view=diff&rev=469230&r1=469229&r2=469230
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetAddressTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetAddressTest.java
Mon Oct 30 10:57:48 2006
@@ -517,6 +517,9 @@
             if (permission.getName().equals("setSecurityManager")){
                 return;
             }
+            if (permission.getName().equals("3d.com")){
+                throw new SecurityException();
+            }
             super.checkPermission(permission);
         }
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AccessController2Test.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AccessController2Test.java?view=diff&rev=469230&r1=469229&r2=469230
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AccessController2Test.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AccessController2Test.java
Mon Oct 30 10:57:48 2006
@@ -17,37 +17,63 @@
 
 package org.apache.harmony.security.tests.java.security;
 
+import java.io.File;
 import java.security.AccessController;
 import java.security.AllPermission;
 import java.security.PrivilegedAction;
 
+import tests.support.Support_Exec;
+
 public class AccessController2Test extends junit.framework.TestCase {
 
 	/**
 	 * @tests java.security.AccessController#doPrivileged(java.security.PrivilegedAction)
 	 */
-	public void test_doPrivilegedLjava_security_PrivilegedAction() {
-		// Test for method java.lang.Object
-		// java.security.AccessController.doPrivileged(java.security.PrivilegedAction)
-
-		// Pass fail flag...
-		Boolean pass;
-
-		// First test 1 argument version (TBD).
-
-		// Then test 2 argument version. 
-		pass = (Boolean) AccessController.doPrivileged(new PrivilegedAction() {
-			public Object run() {
-				try {
-					AccessController.checkPermission(new AllPermission());
-					return new Boolean(false);
-				} catch (SecurityException ex) {
-					return new Boolean(true);
-				}
-			}
-		}, null);
-		assertTrue("Got AllPermission by passing in a null PD", pass
-				.booleanValue());
+	public void test_doPrivilegedLjava_security_PrivilegedAction() throws Exception {
+
+         // tmp user home to avoid presence of ${user.home}/.java.policy
+        String tmpUserHome = System.getProperty("java.io.tmpdir")
+                + File.separatorChar + "tmpUserHomeForAccessController2Test";
+        File dir = new File(tmpUserHome);
+        if (!dir.exists()) {
+            dir.mkdirs();
+            dir.deleteOnExit();
+        }
+        String javaPolycy = tmpUserHome + File.separatorChar
+                + ".java.policy";
+        assertFalse("There should be no java policy file: " + javaPolycy,
+                new File(javaPolycy).exists());
+
+        String[] arg = new String[] { "-Duser.home=" + tmpUserHome,
+                doPrivilegedLjava_security_PrivilegedActionTesting.class.getName() };
+
+        Support_Exec.execJava(arg, null, true);
+    }
+        
+    public static class doPrivilegedLjava_security_PrivilegedActionTesting {
+        public static void main(String[] args) {
+
+            // Pass fail flag...
+            Boolean pass;
+
+            // First test 1 argument version (TBD).
+
+            // Then test 2 argument version.
+            pass = (Boolean) AccessController.doPrivileged(
+                    new PrivilegedAction() {
+                        public Object run() {
+                            try {
+                                AccessController
+                                        .checkPermission(new AllPermission());
+                                return new Boolean(false);
+                            } catch (SecurityException ex) {
+                                return new Boolean(true);
+                            }
+                        }
+                    }, null);
+            assertTrue("Got AllPermission by passing in a null PD", pass
+                    .booleanValue());
 
-	}
+        }
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Policy2Test.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Policy2Test.java?view=diff&rev=469230&r1=469229&r2=469230
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Policy2Test.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Policy2Test.java
Mon Oct 30 10:57:48 2006
@@ -49,9 +49,13 @@
 
         SecurityManager sm = new SecurityManager() {
             public void checkPermission(Permission p) {
-                if( p == null || !"setSecurityManager".equals(p.getName()) ) {
-                    super.checkPermission(p);   
+                if ("setSecurityManager".equals(p.getName())) {
+                    return;
                 }
+                if ("getPolicy".equals(p.getName())) {
+                    throw new AccessControlException("getPolicy");
+                }
+                super.checkPermission(p);
             }
         };
         



Mime
View raw message