harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r497300 - in /harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/org/apache/harmony/security/fortress/ test/api/java/org/apache/harmony/security/tests/java/security/ test/resources/
Date Thu, 18 Jan 2007 05:12:12 GMT
Author: smishura
Date: Wed Jan 17 21:12:11 2007
New Revision: 497300

URL: http://svn.apache.org/viewvc?view=rev&rev=497300
Log:
Add test for property expansion + apply patch from HARMONY-2910:
[classlib][security] Harmony cannot identify 'codeBase' feature in policy file

The patch fixed 4 cases. In 2 cases Harmony still fails - need investigation

Added:
    harmony/enhanced/classlib/trunk/modules/security/src/test/resources/PolicyTest.txt   (with
props)
Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicyParser.java
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicyTest.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicyParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicyParser.java?view=diff&rev=497300&r1=497299&r2=497300
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicyParser.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/fortress/DefaultPolicyParser.java
Wed Jan 17 21:12:11 2007
@@ -196,8 +196,11 @@
                     system) : ge.codebase);
             //Fix HARMONY-1963
             if ("file".equals(codebase.getProtocol())) { //$NON-NLS-1$
-                codebase = new URL("file:/" +  //$NON-NLS-1$
-                        new File(codebase.getFile()).getCanonicalPath());
+            	File codeFile = new File(codebase.getFile());
+            	if (codeFile.isAbsolute()) {
+            		codebase = new URL("file://" +  //$NON-NLS-1$
+                            codeFile.getAbsolutePath());            		
+            	}
             }
         }
         if (ge.signers != null) {

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicyTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicyTest.java?view=diff&rev=497300&r1=497299&r2=497300
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicyTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PolicyTest.java
Wed Jan 17 21:12:11 2007
@@ -22,7 +22,9 @@
 
 package org.apache.harmony.security.tests.java.security;
 
+import java.net.URL;
 import java.security.CodeSource;
+import java.security.Permission;
 import java.security.PermissionCollection;
 import java.security.Policy;
 import java.security.ProtectionDomain;
@@ -35,12 +37,17 @@
 import junit.framework.TestCase;
 
 import org.apache.harmony.security.tests.support.SecurityChecker;
+import org.apache.harmony.security.tests.support.TestUtils;
+
+import tests.support.resource.Support_Resources;
 
 /**
  * Tests for <code>Policy</code>
  */
 public class PolicyTest extends TestCase {
 
+    public static final String JAVA_SECURITY_POLICY = "java.security.policy";
+
     public static void main(String[] args) {
         junit.textui.TestRunner.run(PolicyTest.class);
     }
@@ -180,5 +187,68 @@
         } finally {
             Policy.setPolicy(oldPolicy);
         }
+    }
+    
+    /**
+     * Test property expansion in policy files 
+     */
+    public void testPropertyExpansion() throws Exception {
+
+        // Regression for HARMONY-1963 and HARMONY-2910
+        String policyFile = Support_Resources
+                .getAbsoluteResourcePath("PolicyTest.txt");
+        String oldSysProp = System.getProperty(JAVA_SECURITY_POLICY);
+        Policy oldPolicy = Policy.getPolicy();
+
+        try {
+            System.setProperty(JAVA_SECURITY_POLICY, policyFile);
+
+            // test: absolute paths
+            assertCodeBasePropertyExpansion("/11111/*", "/11111/-");
+            assertCodeBasePropertyExpansion("/22222/../22222/*", "/22222/-");
+            //FIXME assertCodeBasePropertyExpansion("/33333/*", "/33333/../33333/-");
+
+            // test: relative paths
+            assertCodeBasePropertyExpansion("44444/*", "44444/-");
+            assertCodeBasePropertyExpansion("55555/../55555/*", "55555/-");
+            //FIXME assertCodeBasePropertyExpansion("66666/*", "66666/../66666/-");
+        } finally {
+            TestUtils.setSystemProperty(JAVA_SECURITY_POLICY, oldSysProp);
+            Policy.setPolicy(oldPolicy);
+        }
+    }
+
+    /**
+     * Asserts codeBase property expansion in policy file
+     * 
+     * @param codeSourceURL -
+     *            code source for policy object
+     * @param codeBaseURL -
+     *            system propery value for expansion in policy file
+     */
+    private void assertCodeBasePropertyExpansion(String codeSourceURL,
+            String codeBaseURL) throws Exception {
+
+        Policy.setPolicy(null); //reset policy
+        System.setProperty("test.bin.dir", codeBaseURL);
+
+        Policy p = Policy.getPolicy();
+        CodeSource codeSource = new CodeSource(
+                new URL("file:" + codeSourceURL),
+                (java.security.cert.Certificate[]) null);
+        
+        PermissionCollection pCollection = p.getPermissions(codeSource);
+        Enumeration<Permission> elements = pCollection.elements();
+
+        SecurityPermission perm = new SecurityPermission(
+                "codeBaseForPolicyTest");
+
+        while (elements.hasMoreElements()) {
+            if (elements.nextElement().equals(perm)) {
+                return; // passed
+            }
+        }
+        fail("Failed to find SecurityPermission for codeSource="
+                + codeSourceURL + ", codeBase=" + codeBaseURL);
     }
 }

Added: harmony/enhanced/classlib/trunk/modules/security/src/test/resources/PolicyTest.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/resources/PolicyTest.txt?view=auto&rev=497300
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/resources/PolicyTest.txt (added)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/resources/PolicyTest.txt Wed
Jan 17 21:12:11 2007
@@ -0,0 +1,3 @@
+grant codeBase "file:${test.bin.dir}" {
+   permission java.security.SecurityPermission "codeBaseForPolicyTest"; 
+}; 

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/test/resources/PolicyTest.txt
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message