Fix for #308859 (Update test suite to JUnit4 - Module jetty-policy).
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1753 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
15dc2319d1
commit
8f6bde3ccd
|
@ -6,6 +6,7 @@ jetty-7.1.1-SNAPSHOT
|
|||
+ 308850 Update test suite to JUnit4 - Module jetty-annotations
|
||||
+ 308853 Update test suite to JUnit4 - Module jetty-deploy
|
||||
+ 308854 Update test suite to JUnit4 - Module jetty-http
|
||||
+ 308859 Update test suite to JUnit4 - Module jetty-policy
|
||||
|
||||
jetty-7.1.0 5 May 2010
|
||||
+ 306353 fixed cross context dispatch to root context.
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<archive>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
|
@ -95,7 +95,7 @@
|
|||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-policy</artifactId>
|
||||
|
@ -103,17 +103,17 @@
|
|||
<type>jar</type>
|
||||
<overWrite>true</overWrite>
|
||||
<includes>**</includes>
|
||||
<outputDirectory>${jetty.test.policy.loc}</outputDirectory>
|
||||
<outputDirectory>${jetty.test.policy.loc}</outputDirectory>
|
||||
<destFileName>jetty-test-policy.jar</destFileName>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
|
@ -122,6 +122,7 @@
|
|||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit4-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package org.eclipse.jetty.policy;
|
||||
//========================================================================
|
||||
//Copyright (c) Webtide LLC
|
||||
//------------------------------------------------------------------------
|
||||
//All rights reserved. This program and the accompanying materials
|
||||
//are made available under the terms of the Eclipse Public License v1.0
|
||||
//and Apache License v2.0 which accompanies this distribution.
|
||||
//The Eclipse Public License is available at
|
||||
//The Eclipse Public License is available at
|
||||
//http://www.eclipse.org/legal/epl-v10.html
|
||||
//The Apache License v2.0 is available at
|
||||
//http://www.opensource.org/licenses/apache2.0.php
|
||||
//You may elect to redistribute this code under either of these licenses.
|
||||
//You may elect to redistribute this code under either of these licenses.
|
||||
//========================================================================
|
||||
|
||||
package org.eclipse.jetty.policy;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
@ -24,65 +24,61 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JettyPolicyRuntimeTest extends TestCase
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class JettyPolicyRuntimeTest
|
||||
{
|
||||
HashMap<String, String> evaluator = new HashMap<String, String>();
|
||||
|
||||
private HashMap<String, String> evaluator = new HashMap<String, String>();
|
||||
private boolean _runningOnWindows;
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
|
||||
@Before
|
||||
public void init() throws Exception
|
||||
{
|
||||
System.setSecurityManager(null);
|
||||
Policy.setPolicy(null);
|
||||
|
||||
_runningOnWindows = System.getProperty( "os.name" ).startsWith( "Windows" );
|
||||
|
||||
super.setUp();
|
||||
|
||||
|
||||
evaluator.put("jetty.home",MavenTestingUtils.getBaseURI().toASCIIString());
|
||||
evaluator.put("basedir",MavenTestingUtils.getBaseURI().toASCIIString());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
@After
|
||||
public void destroy() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
|
||||
System.setSecurityManager( null );
|
||||
Policy.setPolicy( null );
|
||||
System.setSecurityManager(null);
|
||||
Policy.setPolicy(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimplePolicyReplacement() throws Exception
|
||||
{
|
||||
|
||||
JettyPolicy ap = new JettyPolicy(getSinglePolicy("global-all-permission.policy"),evaluator);
|
||||
|
||||
{
|
||||
JettyPolicy ap = new JettyPolicy(getSinglePolicy("global-all-permission.policy"), evaluator);
|
||||
ap.refresh();
|
||||
|
||||
Policy.setPolicy( ap );
|
||||
System.setSecurityManager( new SecurityManager() );
|
||||
|
||||
File test = new File( "/tmp" );
|
||||
|
||||
assertTrue ( test.canRead() );
|
||||
|
||||
}
|
||||
|
||||
public void testRepeatedPolicyReplacement() throws Exception
|
||||
{
|
||||
JettyPolicy ap = new JettyPolicy(getSinglePolicy("global-all-permission.policy"),evaluator);
|
||||
|
||||
ap.refresh();
|
||||
|
||||
Policy.setPolicy( ap );
|
||||
|
||||
System.setSecurityManager( new SecurityManager() );
|
||||
|
||||
|
||||
File test = new File( "/tmp" );
|
||||
|
||||
assertTrue( test.canRead() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepeatedPolicyReplacement() throws Exception
|
||||
{
|
||||
JettyPolicy ap = new JettyPolicy(getSinglePolicy("global-all-permission.policy"),evaluator);
|
||||
ap.refresh();
|
||||
|
||||
Policy.setPolicy( ap );
|
||||
System.setSecurityManager( new SecurityManager() );
|
||||
|
||||
// Test that the all permission policy allows us to do this
|
||||
try
|
||||
{
|
||||
|
@ -95,11 +91,10 @@ public class JettyPolicyRuntimeTest extends TestCase
|
|||
ace.printStackTrace(System.err);
|
||||
fail("Should NOT have thrown an AccessControlException");
|
||||
}
|
||||
|
||||
|
||||
JettyPolicy ap2 = new JettyPolicy(getSinglePolicy("global-file-read-only-tmp-permission.policy"),evaluator);
|
||||
|
||||
ap2.refresh();
|
||||
|
||||
|
||||
Policy.setPolicy( ap2 );
|
||||
|
||||
// Test that the new policy does replace the old one and we are now not allowed
|
||||
|
@ -114,9 +109,9 @@ public class JettyPolicyRuntimeTest extends TestCase
|
|||
{
|
||||
// Expected Path
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPolicyRestrictive() throws Exception
|
||||
{
|
||||
// TODO - temporary, create alternate file to load for windows
|
||||
|
@ -127,20 +122,18 @@ public class JettyPolicyRuntimeTest extends TestCase
|
|||
}
|
||||
|
||||
JettyPolicy ap = new JettyPolicy(getSinglePolicy("global-file-read-only-tmp-permission.policy"),evaluator);
|
||||
|
||||
ap.refresh();
|
||||
|
||||
|
||||
Policy.setPolicy( ap );
|
||||
|
||||
System.setSecurityManager( new SecurityManager() );
|
||||
|
||||
|
||||
File test = new File( "/tmp" );
|
||||
|
||||
|
||||
assertTrue ( test.canRead() );
|
||||
|
||||
|
||||
File test2 = new File( "/tmp/foo" );
|
||||
assertTrue ( test2.canRead() );
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
File test3 = new File("/tmp/foo/bar/do");
|
||||
|
@ -153,9 +146,9 @@ public class JettyPolicyRuntimeTest extends TestCase
|
|||
// Expected Path
|
||||
}
|
||||
}
|
||||
|
||||
public void testCertificateLoader()
|
||||
throws Exception
|
||||
|
||||
@Test
|
||||
public void testCertificateLoader() throws Exception
|
||||
{
|
||||
// TODO - temporary, create alternate file to load for windows
|
||||
if (_runningOnWindows)
|
||||
|
@ -165,51 +158,47 @@ public class JettyPolicyRuntimeTest extends TestCase
|
|||
}
|
||||
|
||||
JettyPolicy ap = new JettyPolicy(getSinglePolicy("jetty-certificate.policy"),evaluator);
|
||||
|
||||
ap.refresh();
|
||||
|
||||
|
||||
Policy.setPolicy( ap );
|
||||
|
||||
System.setSecurityManager( new SecurityManager() );
|
||||
|
||||
|
||||
URL url = MavenTestingUtils.toTargetURL("test-policy/jetty-test-policy.jar");
|
||||
|
||||
|
||||
URLClassLoader loader ;
|
||||
if (Thread.currentThread().getContextClassLoader() != null )
|
||||
{
|
||||
loader = new URLClassLoader( new URL[]{ url }, Thread.currentThread().getContextClassLoader() );
|
||||
loader = new URLClassLoader( new URL[]{ url }, Thread.currentThread().getContextClassLoader() );
|
||||
}
|
||||
else
|
||||
{
|
||||
loader = new URLClassLoader( new URL[]{ url }, ClassLoader.getSystemClassLoader() );
|
||||
loader = new URLClassLoader( new URL[]{ url }, ClassLoader.getSystemClassLoader() );
|
||||
}
|
||||
|
||||
|
||||
Thread.currentThread().setContextClassLoader(loader);
|
||||
|
||||
|
||||
ap.refresh();
|
||||
|
||||
|
||||
Class<?> clazz = loader.loadClass("org.eclipse.jetty.toolchain.test.policy.Tester");
|
||||
|
||||
Method m = clazz.getMethod("testEcho",new Class[]
|
||||
{ String.class });
|
||||
|
||||
String foo = (String)m.invoke(clazz.newInstance(),new Object[]
|
||||
{ "foo" });
|
||||
String foo = (String)m.invoke(clazz.newInstance(), "foo");
|
||||
|
||||
assertEquals("foo",foo);
|
||||
|
||||
Method m2 = clazz.getMethod("testReadSystemProperty",new Class[]
|
||||
{ String.class });
|
||||
|
||||
m2.invoke(clazz.newInstance(),new Object[]
|
||||
{ "foo" });
|
||||
m2.invoke(clazz.newInstance(), "foo");
|
||||
|
||||
assertTrue("system property access was granted",true);
|
||||
|
||||
// ap.dump(System.out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testBadCertificateLoader()
|
||||
throws Exception
|
||||
{
|
||||
|
@ -221,43 +210,40 @@ public class JettyPolicyRuntimeTest extends TestCase
|
|||
}
|
||||
|
||||
JettyPolicy ap = new JettyPolicy(getSinglePolicy("jetty-bad-certificate.policy"),evaluator);
|
||||
|
||||
ap.refresh();
|
||||
|
||||
|
||||
Policy.setPolicy( ap );
|
||||
|
||||
System.setSecurityManager( new SecurityManager() );
|
||||
|
||||
|
||||
URL url = MavenTestingUtils.toTargetURL("test-policy/jetty-test-policy.jar");
|
||||
|
||||
|
||||
URLClassLoader loader ;
|
||||
if (Thread.currentThread().getContextClassLoader() != null )
|
||||
{
|
||||
loader = new URLClassLoader( new URL[]{ url }, Thread.currentThread().getContextClassLoader() );
|
||||
loader = new URLClassLoader( new URL[]{ url }, Thread.currentThread().getContextClassLoader() );
|
||||
}
|
||||
else
|
||||
{
|
||||
loader = new URLClassLoader( new URL[]{ url }, ClassLoader.getSystemClassLoader() );
|
||||
loader = new URLClassLoader( new URL[]{ url }, ClassLoader.getSystemClassLoader() );
|
||||
}
|
||||
|
||||
|
||||
Thread.currentThread().setContextClassLoader(loader);
|
||||
|
||||
|
||||
ap.refresh();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Class<?> clazz = loader.loadClass("org.eclipse.jetty.toolchain.test.policy.Tester");
|
||||
|
||||
|
||||
Method m = clazz.getMethod( "testEcho", new Class[] {String.class} );
|
||||
|
||||
String foo = (String)m.invoke( clazz.newInstance(), new Object[] {"foo"} );
|
||||
|
||||
|
||||
String foo = (String)m.invoke( clazz.newInstance(), "foo");
|
||||
|
||||
assertEquals("foo", foo );
|
||||
|
||||
|
||||
Method m2 = clazz.getMethod( "testReadSystemProperty", new Class[] {String.class} );
|
||||
|
||||
m2.invoke(clazz.newInstance(),new Object[]
|
||||
{ "foobar" });
|
||||
|
||||
m2.invoke(clazz.newInstance(), "foobar");
|
||||
|
||||
fail("Should have thrown an InvocationTargetException");
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
package org.eclipse.jetty.policy;
|
||||
//========================================================================
|
||||
//Copyright (c) Webtide LLC
|
||||
//------------------------------------------------------------------------
|
||||
|
@ -15,6 +14,8 @@ package org.eclipse.jetty.policy;
|
|||
//You may elect to redistribute this code under either of these licenses.
|
||||
//========================================================================
|
||||
|
||||
package org.eclipse.jetty.policy;
|
||||
|
||||
import java.io.FilePermission;
|
||||
import java.net.URL;
|
||||
import java.security.CodeSource;
|
||||
|
@ -28,98 +29,92 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JettyPolicyTest extends TestCase
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class JettyPolicyTest
|
||||
{
|
||||
HashMap<String, String> evaluator = new HashMap<String, String>();
|
||||
|
||||
private HashMap<String, String> evaluator = new HashMap<String, String>();
|
||||
|
||||
@Override
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
evaluator.put("jetty.home",MavenTestingUtils.getBaseURI().toASCIIString());
|
||||
evaluator.put("basedir",MavenTestingUtils.getBaseURI().toASCIIString());
|
||||
}
|
||||
|
||||
public void testGlobalAllPermissionLoader()
|
||||
throws Exception
|
||||
@Test
|
||||
public void testGlobalAllPermissionLoader() throws Exception
|
||||
{
|
||||
|
||||
JettyPolicy ap =
|
||||
new JettyPolicy( Collections.singleton( MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/test/resources/global-all-permission.policy" ), evaluator );
|
||||
|
||||
JettyPolicy ap = new JettyPolicy( Collections.singleton( MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/test/resources/global-all-permission.policy" ), evaluator );
|
||||
ap.refresh();
|
||||
|
||||
|
||||
PermissionCollection pc = ap.getPermissions( new ProtectionDomain( null, null ) );
|
||||
|
||||
|
||||
assertNotNull( pc );
|
||||
|
||||
|
||||
Permission testPerm = new FilePermission( "/tmp", "read" );
|
||||
|
||||
|
||||
assertTrue( pc.implies( testPerm ) );
|
||||
|
||||
for ( Enumeration<Permission> e = pc.elements(); e.hasMoreElements(); )
|
||||
|
||||
for ( Enumeration<Permission> e = pc.elements(); e.hasMoreElements(); )
|
||||
{
|
||||
System.out.println( "Permission: " + e.nextElement().getClass().getName() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testSingleCodebaseFilePermissionLoader()
|
||||
throws Exception
|
||||
@Test
|
||||
public void testSingleCodebaseFilePermissionLoader() throws Exception
|
||||
{
|
||||
JettyPolicy ap =
|
||||
new JettyPolicy( Collections.singleton( MavenTestingUtils.getBasedir().getAbsolutePath()
|
||||
+ "/src/test/resources/single-codebase-file-permission.policy" ), evaluator );
|
||||
|
||||
ap.refresh();
|
||||
|
||||
URL url = new URL( "file:///foo.jar" );
|
||||
|
||||
URL url = new URL( "file:///foo.jar" );
|
||||
CodeSource cs = new CodeSource( url, new Certificate[0]);
|
||||
|
||||
|
||||
PermissionCollection pc = ap.getPermissions( cs );
|
||||
|
||||
|
||||
assertNotNull( pc );
|
||||
|
||||
|
||||
Permission testPerm = new FilePermission( "/tmp/*", "read" );
|
||||
|
||||
|
||||
assertTrue( pc.implies( testPerm ) );
|
||||
|
||||
}
|
||||
|
||||
public void testMultipleCodebaseFilePermissionLoader()
|
||||
throws Exception
|
||||
@Test
|
||||
public void testMultipleCodebaseFilePermissionLoader() throws Exception
|
||||
{
|
||||
JettyPolicy ap =
|
||||
new JettyPolicy( Collections.singleton( MavenTestingUtils.getBasedir().getAbsolutePath()
|
||||
+ "/src/test/resources/multiple-codebase-file-permission.policy" ), evaluator );
|
||||
|
||||
ap.refresh();
|
||||
|
||||
|
||||
// ap.dump(System.out);
|
||||
|
||||
URL url = new URL( "file:///bar.jar" );
|
||||
URL url = new URL( "file:///bar.jar" );
|
||||
CodeSource cs = new CodeSource( url, new Certificate[0]);
|
||||
|
||||
|
||||
PermissionCollection pc = ap.getPermissions( cs );
|
||||
|
||||
|
||||
assertNotNull( pc );
|
||||
|
||||
|
||||
Permission testPerm = new FilePermission( "/tmp/*", "read,write" );
|
||||
Permission testPerm2 = new FilePermission( "/usr/*", "write" ); // only read was granted
|
||||
|
||||
|
||||
assertTrue( pc.implies( testPerm ) );
|
||||
assertFalse( pc.implies( testPerm2 ) );
|
||||
|
||||
}
|
||||
|
||||
public void testMultipleCodebaseMixedPermissionLoader()
|
||||
throws Exception
|
||||
@Test
|
||||
public void testMultipleCodebaseMixedPermissionLoader() throws Exception
|
||||
{
|
||||
JettyPolicy ap =
|
||||
new JettyPolicy( Collections.singleton( MavenTestingUtils.getBasedir().getAbsolutePath()
|
||||
|
@ -129,7 +124,8 @@ public class JettyPolicyTest extends TestCase
|
|||
|
||||
// ap.dump(System.out);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSCLoader() throws Exception
|
||||
{
|
||||
JettyPolicy ap = new JettyPolicy(Collections.singleton(MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/main/config/lib/policy/jetty.policy"),evaluator);
|
||||
|
@ -138,30 +134,29 @@ public class JettyPolicyTest extends TestCase
|
|||
ap.dump(System.out);
|
||||
}
|
||||
|
||||
public void testMultipleFilePermissionLoader()
|
||||
throws Exception
|
||||
@Test
|
||||
public void testMultipleFilePermissionLoader() throws Exception
|
||||
{
|
||||
Set<String> files = new HashSet<String>();
|
||||
|
||||
|
||||
files.add( MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/test/resources/single-codebase-file-permission.policy" );
|
||||
files.add( MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/test/resources/single-codebase-file-permission-2.policy" );
|
||||
|
||||
|
||||
JettyPolicy ap = new JettyPolicy( files, evaluator );
|
||||
|
||||
ap.refresh();
|
||||
|
||||
URL url = new URL( "file:///bar.jar" );
|
||||
|
||||
URL url = new URL( "file:///bar.jar" );
|
||||
CodeSource cs = new CodeSource( url, new Certificate[0]);
|
||||
|
||||
|
||||
PermissionCollection pc = ap.getPermissions( cs );
|
||||
|
||||
|
||||
assertNotNull( pc );
|
||||
|
||||
|
||||
Permission testPerm = new FilePermission( "/tmp/*", "read" );
|
||||
Permission testPerm2 = new FilePermission( "/usr/*", "write" ); //
|
||||
|
||||
Permission testPerm2 = new FilePermission( "/usr/*", "write" ); //
|
||||
|
||||
assertTrue( pc.implies( testPerm ) );
|
||||
assertFalse( pc.implies( testPerm2 ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
package org.eclipse.jetty.policy;
|
||||
//========================================================================
|
||||
//Copyright (c) Webtide LLC
|
||||
//------------------------------------------------------------------------
|
||||
|
@ -15,120 +14,110 @@ package org.eclipse.jetty.policy;
|
|||
//You may elect to redistribute this code under either of these licenses.
|
||||
//========================================================================
|
||||
|
||||
package org.eclipse.jetty.policy;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.Permission;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.jetty.policy.entry.GrantEntry;
|
||||
import org.eclipse.jetty.policy.entry.KeystoreEntry;
|
||||
import org.eclipse.jetty.policy.loader.PolicyFileScanner;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class PolicyContextTest
|
||||
extends TestCase
|
||||
{
|
||||
public static final String __PRINCIPAL = "javax.security.auth.x500.X500Principal \"CN=Jetty Policy,OU=Artifact,O=Jetty Project,L=Earth,ST=Internet,C=US\"";
|
||||
|
||||
private boolean _runningOnWindows;
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
|
||||
@Before
|
||||
public void init() throws Exception
|
||||
{
|
||||
_runningOnWindows = System.getProperty( "os.name" ).startsWith( "Windows" );
|
||||
|
||||
System.setProperty( "basedir", MavenTestingUtils.getBaseURI().toASCIIString() );
|
||||
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelfPropertyExpansion() throws Exception
|
||||
{
|
||||
|
||||
PolicyContext context = new PolicyContext();
|
||||
PolicyFileScanner loader = new PolicyFileScanner();
|
||||
PolicyContext context = new PolicyContext();
|
||||
PolicyFileScanner loader = new PolicyFileScanner();
|
||||
List<GrantEntry> grantEntries = new ArrayList<GrantEntry>();
|
||||
List<KeystoreEntry> keystoreEntries = new ArrayList<KeystoreEntry>();
|
||||
|
||||
File policyFile = new File( getWorkingDirectory() + "/src/test/resources/context/jetty-certificate.policy" );
|
||||
|
||||
|
||||
File policyFile = new File( getWorkingDirectory() + "/src/test/resources/context/jetty-certificate.policy" );
|
||||
|
||||
loader.scanStream( new InputStreamReader( new FileInputStream( policyFile ) ), grantEntries, keystoreEntries );
|
||||
|
||||
|
||||
if ( !_runningOnWindows ) //temporary, create alternate file to load for windows
|
||||
{
|
||||
|
||||
for ( Iterator<KeystoreEntry> i = keystoreEntries.iterator(); i.hasNext();)
|
||||
{
|
||||
KeystoreEntry node = i.next();
|
||||
node.expand( context );
|
||||
|
||||
context.setKeystore( node.toKeyStore() );
|
||||
}
|
||||
|
||||
GrantEntry grant = grantEntries.get( 0 );
|
||||
grant.expand( context );
|
||||
|
||||
Permission perm = grant.getPermissions().elements().nextElement();
|
||||
|
||||
|
||||
assertEquals( __PRINCIPAL, perm.getName() );
|
||||
for (KeystoreEntry node : keystoreEntries)
|
||||
{
|
||||
node.expand(context);
|
||||
|
||||
context.setKeystore(node.toKeyStore());
|
||||
}
|
||||
|
||||
GrantEntry grant = grantEntries.get( 0 );
|
||||
grant.expand( context );
|
||||
|
||||
Permission perm = grant.getPermissions().elements().nextElement();
|
||||
|
||||
assertEquals( __PRINCIPAL, perm.getName() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAliasPropertyExpansion() throws Exception
|
||||
{
|
||||
|
||||
PolicyContext context = new PolicyContext();
|
||||
PolicyFileScanner loader = new PolicyFileScanner();
|
||||
PolicyContext context = new PolicyContext();
|
||||
PolicyFileScanner loader = new PolicyFileScanner();
|
||||
List<GrantEntry> grantEntries = new ArrayList<GrantEntry>();
|
||||
List<KeystoreEntry> keystoreEntries = new ArrayList<KeystoreEntry>();
|
||||
|
||||
File policyFile = new File( getWorkingDirectory() + "/src/test/resources/context/jetty-certificate-alias.policy" );
|
||||
|
||||
|
||||
File policyFile = new File( getWorkingDirectory() + "/src/test/resources/context/jetty-certificate-alias.policy" );
|
||||
|
||||
loader.scanStream( new InputStreamReader( new FileInputStream( policyFile ) ), grantEntries, keystoreEntries );
|
||||
|
||||
|
||||
if ( !_runningOnWindows ) //temporary, create alternate file to load for windows
|
||||
{
|
||||
|
||||
for ( Iterator<KeystoreEntry> i = keystoreEntries.iterator(); i.hasNext();)
|
||||
{
|
||||
KeystoreEntry node = i.next();
|
||||
node.expand( context );
|
||||
|
||||
context.setKeystore( node.toKeyStore() );
|
||||
}
|
||||
|
||||
GrantEntry grant = grantEntries.get( 0 );
|
||||
grant.expand( context );
|
||||
|
||||
Permission perm = grant.getPermissions().elements().nextElement();
|
||||
|
||||
assertEquals( __PRINCIPAL, perm.getName() );
|
||||
for (KeystoreEntry node : keystoreEntries)
|
||||
{
|
||||
node.expand(context);
|
||||
|
||||
context.setKeystore(node.toKeyStore());
|
||||
}
|
||||
|
||||
GrantEntry grant = grantEntries.get( 0 );
|
||||
grant.expand( context );
|
||||
|
||||
Permission perm = grant.getPermissions().elements().nextElement();
|
||||
|
||||
assertEquals( __PRINCIPAL, perm.getName() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFileSeparatorExpansion() throws Exception
|
||||
{
|
||||
PolicyContext context = new PolicyContext();
|
||||
PolicyContext context = new PolicyContext();
|
||||
context.addProperty( "foo", "bar" );
|
||||
|
||||
|
||||
assertEquals(File.separator, context.evaluate( "${/}" ) );
|
||||
|
||||
assertEquals(File.separator + "bar" + File.separator, context.evaluate( "${/}${foo}${/}" ) );
|
||||
|
||||
|
||||
assertEquals(File.separator + File.separator, context.evaluate( "${/}${/}" ) );
|
||||
}
|
||||
|
||||
|
||||
private String getWorkingDirectory()
|
||||
{
|
||||
return MavenTestingUtils.getBasedir().getAbsolutePath();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue