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.
|
||||
|
|
|
@ -122,6 +122,7 @@
|
|||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit4-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
package org.eclipse.jetty.policy;
|
||||
//========================================================================
|
||||
//Copyright (c) Webtide LLC
|
||||
//------------------------------------------------------------------------
|
||||
|
@ -12,6 +11,7 @@ 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.lang.reflect.InvocationTargetException;
|
||||
|
@ -24,44 +24,42 @@ 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 );
|
||||
|
@ -69,18 +67,16 @@ public class JettyPolicyRuntimeTest extends TestCase
|
|||
|
||||
File test = new File( "/tmp" );
|
||||
|
||||
assertTrue ( test.canRead() );
|
||||
|
||||
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
|
||||
|
@ -97,7 +93,6 @@ public class JettyPolicyRuntimeTest extends TestCase
|
|||
}
|
||||
|
||||
JettyPolicy ap2 = new JettyPolicy(getSinglePolicy("global-file-read-only-tmp-permission.policy"),evaluator);
|
||||
|
||||
ap2.refresh();
|
||||
|
||||
Policy.setPolicy( ap2 );
|
||||
|
@ -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,11 +122,9 @@ 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" );
|
||||
|
@ -154,8 +147,8 @@ public class JettyPolicyRuntimeTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
public void testCertificateLoader()
|
||||
throws Exception
|
||||
@Test
|
||||
public void testCertificateLoader() throws Exception
|
||||
{
|
||||
// TODO - temporary, create alternate file to load for windows
|
||||
if (_runningOnWindows)
|
||||
|
@ -165,11 +158,9 @@ 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");
|
||||
|
@ -193,23 +184,21 @@ public class JettyPolicyRuntimeTest extends TestCase
|
|||
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,11 +210,9 @@ 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");
|
||||
|
@ -250,14 +237,13 @@ public class JettyPolicyRuntimeTest extends TestCase
|
|||
|
||||
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,33 +29,31 @@ 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 );
|
||||
|
@ -67,16 +66,14 @@ public class JettyPolicyTest extends TestCase
|
|||
{
|
||||
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" );
|
||||
|
@ -89,11 +86,10 @@ public class JettyPolicyTest extends TestCase
|
|||
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()
|
||||
|
@ -115,11 +111,10 @@ public class JettyPolicyTest extends TestCase
|
|||
|
||||
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()
|
||||
|
@ -130,6 +125,7 @@ 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,8 +134,8 @@ 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>();
|
||||
|
||||
|
@ -163,5 +159,4 @@ public class JettyPolicyTest extends TestCase
|
|||
assertTrue( pc.implies( testPerm ) );
|
||||
assertFalse( pc.implies( testPerm2 ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
package org.eclipse.jetty.policy;
|
||||
//========================================================================
|
||||
//Copyright (c) Webtide LLC
|
||||
//------------------------------------------------------------------------
|
||||
|
@ -15,42 +14,38 @@ 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();
|
||||
List<GrantEntry> grantEntries = new ArrayList<GrantEntry>();
|
||||
|
@ -62,13 +57,11 @@ public class PolicyContextTest
|
|||
|
||||
if ( !_runningOnWindows ) //temporary, create alternate file to load for windows
|
||||
{
|
||||
|
||||
for ( Iterator<KeystoreEntry> i = keystoreEntries.iterator(); i.hasNext();)
|
||||
for (KeystoreEntry node : keystoreEntries)
|
||||
{
|
||||
KeystoreEntry node = i.next();
|
||||
node.expand( context );
|
||||
node.expand(context);
|
||||
|
||||
context.setKeystore( node.toKeyStore() );
|
||||
context.setKeystore(node.toKeyStore());
|
||||
}
|
||||
|
||||
GrantEntry grant = grantEntries.get( 0 );
|
||||
|
@ -76,14 +69,13 @@ public class PolicyContextTest
|
|||
|
||||
Permission perm = grant.getPermissions().elements().nextElement();
|
||||
|
||||
|
||||
assertEquals( __PRINCIPAL, perm.getName() );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAliasPropertyExpansion() throws Exception
|
||||
{
|
||||
|
||||
PolicyContext context = new PolicyContext();
|
||||
PolicyFileScanner loader = new PolicyFileScanner();
|
||||
List<GrantEntry> grantEntries = new ArrayList<GrantEntry>();
|
||||
|
@ -95,13 +87,11 @@ public class PolicyContextTest
|
|||
|
||||
if ( !_runningOnWindows ) //temporary, create alternate file to load for windows
|
||||
{
|
||||
|
||||
for ( Iterator<KeystoreEntry> i = keystoreEntries.iterator(); i.hasNext();)
|
||||
for (KeystoreEntry node : keystoreEntries)
|
||||
{
|
||||
KeystoreEntry node = i.next();
|
||||
node.expand( context );
|
||||
node.expand(context);
|
||||
|
||||
context.setKeystore( node.toKeyStore() );
|
||||
context.setKeystore(node.toKeyStore());
|
||||
}
|
||||
|
||||
GrantEntry grant = grantEntries.get( 0 );
|
||||
|
@ -113,6 +103,7 @@ public class PolicyContextTest
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSeparatorExpansion() throws Exception
|
||||
{
|
||||
PolicyContext context = new PolicyContext();
|
||||
|
@ -122,7 +113,6 @@ public class PolicyContextTest
|
|||
|
||||
assertEquals(File.separator + "bar" + File.separator, context.evaluate( "${/}${foo}${/}" ) );
|
||||
|
||||
|
||||
assertEquals(File.separator + File.separator, context.evaluate( "${/}${/}" ) );
|
||||
}
|
||||
|
||||
|
@ -130,5 +120,4 @@ public class PolicyContextTest
|
|||
{
|
||||
return MavenTestingUtils.getBasedir().getAbsolutePath();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue