commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1509019 - in /commons/sandbox/weaver/trunk/example/src: main/java/org/apache/commons/weaver/privilizer/example/ test/java/org/apache/commons/weaver/privilizer/example/ test/resources/
Date Wed, 31 Jul 2013 20:36:16 GMT
Author: mbenson
Date: Wed Jul 31 20:36:15 2013
New Revision: 1509019

URL: http://svn.apache.org/r1509019
Log:
rearrange test setup so we can show, with the combo of policy=NEVER and 'sec' profile, that
not privilizing indeed does not work

Added:
    commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/Setup.java
      - copied, changed from r1508992, commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java
Modified:
    commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/NoArgsTest.java
    commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/OverloadingTest.java
    commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/PrivateMethodsTest.java
    commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticNoArgsTest.java
    commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticOverloadingTest.java
    commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticPrivateMethodsTest.java
    commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticUsingArgsTest.java
    commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingArgsTest.java
    commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java
    commons/sandbox/weaver/trunk/example/src/test/resources/java.policy

Copied: commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/Setup.java
(from r1508992, commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/Setup.java?p2=commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/Setup.java&p1=commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java&r1=1508992&r2=1509019&rev=1509019&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java
(original)
+++ commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/Setup.java
Wed Jul 31 20:36:15 2013
@@ -15,50 +15,22 @@
  */
 package org.apache.commons.weaver.privilizer.example;
 
-public class Utils {
-    public static class More {
-        private More() {
-        }
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
-        public static String getProperty() {
-            return Utils.getProperty("bar");
-        }
-
-        public static String getTopStackElementClassName() {
-            return Thread.currentThread().getStackTrace()[1].getClassName();
-        }
-    }
-
-    private Utils() {
-    }
-
-    public static final String FOO = "foo".intern();
-
-    public static String readPublicConstant() {
-        return FOO;
-    }
-
-    public static String getProperty() {
-        return getProperty("foo");
-    }
-
-    public static String getProperty(int i, String key) {
-        if (i <= 0) {
-            return getProperty(key);
-        }
-        return getProperty(--i, key);
-    }
-
-    public static String getProperty(String key) {
-        return System.getProperty(key);
-    }
-
-    private static Integer n;
-    static {
-        n = Integer.valueOf(999);
-    }
-
-    public static int readPrivateField() {
-        return n;
+class Setup {
+    /**
+     * This simply allows us to to set up test classes by doing
+     * privileged things without granting privileges to the test
+     * code itself and thus making it impossible to test the effects
+     * of privilization.
+     */
+    public static void setProperty(final String name, final String value) {
+        AccessController.doPrivileged(new PrivilegedAction<Void>() {
+            public Void run() {
+                System.setProperty(name, value);
+                return null;
+            }
+        });
     }
 }

Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/NoArgsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/NoArgsTest.java?rev=1509019&r1=1509018&r2=1509019&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/NoArgsTest.java
(original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/NoArgsTest.java
Wed Jul 31 20:36:15 2013
@@ -33,14 +33,7 @@ public class NoArgsTest {
 
     @Before
     public void setUp() throws Exception {
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-
-            @Override
-            public Void run() {
-                System.setProperty("foo", "foo-value");
-                return null;
-            }
-        });
+        Setup.setProperty("foo", "foo-value");
         noArgs = new NoArgs();
     }
 

Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/OverloadingTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/OverloadingTest.java?rev=1509019&r1=1509018&r2=1509019&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/OverloadingTest.java
(original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/OverloadingTest.java
Wed Jul 31 20:36:15 2013
@@ -28,15 +28,9 @@ public class OverloadingTest {
 
     @Before
     public void setUp() throws Exception {
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-            @Override
-            public Void run() {
-                System.setProperty("foo", "foo-value");
-                System.setProperty("bar", "bar-value");
-                System.setProperty("baz", "baz-value");
-                return null;
-            }
-        });
+        Setup.setProperty("foo", "foo-value");
+        Setup.setProperty("bar", "bar-value");
+        Setup.setProperty("baz", "baz-value");
         overloading = new Overloading();
     }
 

Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/PrivateMethodsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/PrivateMethodsTest.java?rev=1509019&r1=1509018&r2=1509019&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/PrivateMethodsTest.java
(original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/PrivateMethodsTest.java
Wed Jul 31 20:36:15 2013
@@ -28,15 +28,9 @@ public class PrivateMethodsTest {
 
     @Before
     public void setUp() throws Exception {
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-            @Override
-            public Void run() {
-                System.setProperty("foo", "foo-value");
-                System.setProperty("bar", "bar-value");
-                System.setProperty("baz", "baz-value");
-                return null;
-            }
-        });
+        Setup.setProperty("foo", "foo-value");
+        Setup.setProperty("bar", "bar-value");
+        Setup.setProperty("baz", "baz-value");
         privateMethods = new PrivateMethods();
     }
 

Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticNoArgsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticNoArgsTest.java?rev=1509019&r1=1509018&r2=1509019&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticNoArgsTest.java
(original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticNoArgsTest.java
Wed Jul 31 20:36:15 2013
@@ -31,14 +31,7 @@ import org.junit.Test;
 public class StaticNoArgsTest {
     @Before
     public void setUp() throws Exception {
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-
-            @Override
-            public Void run() {
-                System.setProperty("foo", "foo-value");
-                return null;
-            }
-        });
+        Setup.setProperty("foo", "foo-value");
     }
 
     @Test

Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticOverloadingTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticOverloadingTest.java?rev=1509019&r1=1509018&r2=1509019&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticOverloadingTest.java
(original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticOverloadingTest.java
Wed Jul 31 20:36:15 2013
@@ -27,15 +27,9 @@ public class StaticOverloadingTest {
 
     @Before
     public void setUp() throws Exception {
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-            @Override
-            public Void run() {
-                System.setProperty("foo", "foo-value");
-                System.setProperty("bar", "bar-value");
-                System.setProperty("baz", "baz-value");
-                return null;
-            }
-        });
+        Setup.setProperty("foo", "foo-value");
+        Setup.setProperty("bar", "bar-value");
+        Setup.setProperty("baz", "baz-value");
     }
 
     @Test

Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticPrivateMethodsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticPrivateMethodsTest.java?rev=1509019&r1=1509018&r2=1509019&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticPrivateMethodsTest.java
(original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticPrivateMethodsTest.java
Wed Jul 31 20:36:15 2013
@@ -27,15 +27,9 @@ public class StaticPrivateMethodsTest {
 
     @Before
     public void setUp() throws Exception {
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-            @Override
-            public Void run() {
-                System.setProperty("foo", "foo-value");
-                System.setProperty("bar", "bar-value");
-                System.setProperty("baz", "baz-value");
-                return null;
-            }
-        });
+        Setup.setProperty("foo", "foo-value");
+        Setup.setProperty("bar", "bar-value");
+        Setup.setProperty("baz", "baz-value");
     }
 
     @Test

Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticUsingArgsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticUsingArgsTest.java?rev=1509019&r1=1509018&r2=1509019&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticUsingArgsTest.java
(original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticUsingArgsTest.java
Wed Jul 31 20:36:15 2013
@@ -32,15 +32,9 @@ public class StaticUsingArgsTest {
 
     @Before
     public void setUp() throws Exception {
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-            @Override
-            public Void run() {
-                System.setProperty("foo", "foo-value");
-                System.setProperty("bar", "bar-value");
-                System.setProperty("baz", "baz-value");
-                return null;
-            }
-        });
+        Setup.setProperty("foo", "foo-value");
+        Setup.setProperty("bar", "bar-value");
+        Setup.setProperty("baz", "baz-value");
     }
 
     @Test

Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingArgsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingArgsTest.java?rev=1509019&r1=1509018&r2=1509019&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingArgsTest.java
(original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingArgsTest.java
Wed Jul 31 20:36:15 2013
@@ -33,15 +33,9 @@ public class UsingArgsTest {
 
     @Before
     public void setUp() throws Exception {
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-            @Override
-            public Void run() {
-                System.setProperty("foo", "foo-value");
-                System.setProperty("bar", "bar-value");
-                System.setProperty("baz", "baz-value");
-                return null;
-            }
-        });
+        Setup.setProperty("foo", "foo-value");
+        Setup.setProperty("bar", "bar-value");
+        Setup.setProperty("baz", "baz-value");
         usingArgs = new UsingArgs();
     }
 

Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java?rev=1509019&r1=1509018&r2=1509019&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java
(original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java
Wed Jul 31 20:36:15 2013
@@ -29,15 +29,9 @@ public class UsingBlueprintsTest {
 
     @Before
     public void setUp() throws Exception {
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-            @Override
-            public Void run() {
-                System.setProperty("foo", "foo-value");
-                System.setProperty("bar", "bar-value");
-                System.setProperty("baz", "baz-value");
-                return null;
-            }
-        });
+        Setup.setProperty("foo", "foo-value");
+        Setup.setProperty("bar", "bar-value");
+        Setup.setProperty("baz", "baz-value");
         usingBlueprints = new UsingBlueprints();
     }
 

Modified: commons/sandbox/weaver/trunk/example/src/test/resources/java.policy
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/resources/java.policy?rev=1509019&r1=1509018&r2=1509019&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/resources/java.policy (original)
+++ commons/sandbox/weaver/trunk/example/src/test/resources/java.policy Wed Jul 31 20:36:15
2013
@@ -37,24 +37,11 @@ grant codeBase "file://${user.home}/.m2/
   permission java.security.AllPermission;
 };
 
-// if you set up eclipse to propagate this property it will work :D
-grant codeBase "file://${eclipse.home}/-"
-{
-  permission java.security.AllPermission;
-};
-
-// and our own testcases
-
-grant codeBase "file://${user.dir}/target/test-classes/-"
-{
-  permission java.security.AllPermission;
-};
-
 grant codeBase "file://${user.dir}/target/classes/-"
 {
-  permission java.util.PropertyPermission "foo", "read";
-  permission java.util.PropertyPermission "bar", "read";
-  permission java.util.PropertyPermission "baz", "read";
+  permission java.util.PropertyPermission "foo", "read,write";
+  permission java.util.PropertyPermission "bar", "read,write";
+  permission java.util.PropertyPermission "baz", "read,write";
   permission java.lang.RuntimePermission "accessDeclaredMembers";
   permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
 };



Mime
View raw message