Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 23385 invoked from network); 18 Jan 2007 05:13:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Jan 2007 05:13:18 -0000 Received: (qmail 68902 invoked by uid 500); 18 Jan 2007 05:13:24 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 68886 invoked by uid 500); 18 Jan 2007 05:13:24 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 68877 invoked by uid 99); 18 Jan 2007 05:13:24 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Jan 2007 21:13:24 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Jan 2007 21:13:17 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id CC1E31A981A; Wed, 17 Jan 2007 21:12:12 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@harmony.apache.org From: smishura@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070118051212.CC1E31A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 Policy */ 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 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