Testing updates.
* Fixing MavenTestingUtils.toTargetURL() mistake. * Moving phase from generate-resources to generate-test-resources * Fixing testing flow in JettyPolicyRuntimeTest git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@695 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
735454017b
commit
8b50f2e543
|
@ -38,7 +38,7 @@
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>unpack</id>
|
<id>unpack</id>
|
||||||
<phase>generate-resources</phase>
|
<phase>generate-test-resources</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>unpack</goal>
|
<goal>unpack</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
</execution>
|
</execution>
|
||||||
<execution>
|
<execution>
|
||||||
<id>copy</id>
|
<id>copy</id>
|
||||||
<phase>generate-resources</phase>
|
<phase>generate-test-resources</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>copy</goal>
|
<goal>copy</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
|
|
@ -61,6 +61,7 @@ public class KeystoreEntry extends AbstractEntry
|
||||||
return keystore;
|
return keystore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void expand( PolicyContext context ) throws PolicyException
|
public void expand( PolicyContext context ) throws PolicyException
|
||||||
{
|
{
|
||||||
url = context.evaluate( url );
|
url = context.evaluate( url );
|
||||||
|
|
|
@ -88,12 +88,11 @@ public class JettyPolicyRuntimeTest extends TestCase
|
||||||
File test3 = new File( "/tmp/foo/bar/do" );
|
File test3 = new File( "/tmp/foo/bar/do" );
|
||||||
test3.mkdirs();
|
test3.mkdirs();
|
||||||
test3.delete();
|
test3.delete();
|
||||||
assertTrue( "Under AllPermission we are allowed", true );
|
|
||||||
}
|
}
|
||||||
catch ( AccessControlException ace )
|
catch ( AccessControlException ace )
|
||||||
{
|
{
|
||||||
//ace.printStackTrace();
|
ace.printStackTrace(System.err);
|
||||||
assertFalse( "Exception was thrown which it shouldn't have been", true );
|
fail("Should NOT have thrown an AccessControlException");
|
||||||
}
|
}
|
||||||
|
|
||||||
JettyPolicy ap2 = new JettyPolicy(getSinglePolicy("global-file-read-only-tmp-permission.policy"),evaluator);
|
JettyPolicy ap2 = new JettyPolicy(getSinglePolicy("global-file-read-only-tmp-permission.policy"),evaluator);
|
||||||
|
@ -102,17 +101,17 @@ public class JettyPolicyRuntimeTest extends TestCase
|
||||||
|
|
||||||
Policy.setPolicy( ap2 );
|
Policy.setPolicy( ap2 );
|
||||||
|
|
||||||
// Test that the new policy does replace the old one and we are now now allowed
|
// Test that the new policy does replace the old one and we are now not allowed
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File test3 = new File( "/tmp/foo/bar/do" );
|
File test3 = new File( "/tmp/foo/bar/do" );
|
||||||
test3.mkdirs();
|
test3.mkdirs();
|
||||||
assertFalse( "We should be restricted and not get here.", true );
|
|
||||||
|
fail("Should have thrown an AccessControlException");
|
||||||
}
|
}
|
||||||
catch ( AccessControlException ace )
|
catch ( AccessControlException ace )
|
||||||
{
|
{
|
||||||
//ace.printStackTrace();
|
// Expected Path
|
||||||
assertTrue( "Exception was thrown as it should be.", true );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -143,14 +142,14 @@ public class JettyPolicyRuntimeTest extends TestCase
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File test3 = new File( "/tmp/foo/bar/do" );
|
File test3 = new File("/tmp/foo/bar/do");
|
||||||
test3.mkdirs();
|
test3.mkdirs();
|
||||||
assertTrue( "we should not get here", false );
|
|
||||||
|
fail("Should have thrown an AccessControlException");
|
||||||
}
|
}
|
||||||
catch ( AccessControlException ace )
|
catch (AccessControlException ace)
|
||||||
{
|
{
|
||||||
//ace.printStackTrace();
|
// Expected Path
|
||||||
assertTrue( "Exception was thrown", true );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +163,6 @@ public class JettyPolicyRuntimeTest extends TestCase
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("test");
|
|
||||||
|
|
||||||
JettyPolicy ap = new JettyPolicy(getSinglePolicy("jetty-certificate.policy"),evaluator);
|
JettyPolicy ap = new JettyPolicy(getSinglePolicy("jetty-certificate.policy"),evaluator);
|
||||||
|
|
||||||
// ap.dump( System.out );
|
// ap.dump( System.out );
|
||||||
|
@ -192,37 +189,23 @@ public class JettyPolicyRuntimeTest extends TestCase
|
||||||
|
|
||||||
ap.refresh();
|
ap.refresh();
|
||||||
|
|
||||||
try
|
Class<?> clazz = loader.loadClass("org.eclipse.jetty.toolchain.test.policy.Tester");
|
||||||
{
|
|
||||||
Class<?> clazz = loader.loadClass("org.eclipse.jetty.toolchain.test.policy.Tester");
|
Method m = clazz.getMethod("testEcho",new Class[]
|
||||||
|
{ String.class });
|
||||||
Method m = clazz.getMethod( "testEcho", new Class[] {String.class} );
|
|
||||||
|
String foo = (String)m.invoke(clazz.newInstance(),new Object[]
|
||||||
String foo = (String)m.invoke( clazz.newInstance(), new Object[] {"foo"} );
|
{ "foo" });
|
||||||
|
|
||||||
assertEquals("foo", foo );
|
assertEquals("foo",foo);
|
||||||
|
|
||||||
Method m2 = clazz.getMethod( "testReadSystemProperty", new Class[] {String.class} );
|
Method m2 = clazz.getMethod("testReadSystemProperty",new Class[]
|
||||||
|
{ String.class });
|
||||||
m2.invoke( clazz.newInstance(), new Object[] {"foo"} );
|
|
||||||
|
m2.invoke(clazz.newInstance(),new Object[]
|
||||||
assertTrue( "system property access was granted", true );
|
{ "foo" });
|
||||||
}
|
|
||||||
catch ( ClassNotFoundException e )
|
assertTrue("system property access was granted",true);
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
assertFalse( "should not have got here", true );
|
|
||||||
}
|
|
||||||
catch ( SecurityException e )
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
assertFalse( "should not have got here", true );
|
|
||||||
}
|
|
||||||
catch ( IllegalAccessException e )
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
assertFalse( "should not have got here", true );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -260,8 +243,6 @@ public class JettyPolicyRuntimeTest extends TestCase
|
||||||
|
|
||||||
ap.refresh();
|
ap.refresh();
|
||||||
|
|
||||||
boolean excepted = false;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Class<?> clazz = loader.loadClass("org.eclipse.jetty.toolchain.test.policy.Tester");
|
Class<?> clazz = loader.loadClass("org.eclipse.jetty.toolchain.test.policy.Tester");
|
||||||
|
@ -274,27 +255,15 @@ public class JettyPolicyRuntimeTest extends TestCase
|
||||||
|
|
||||||
Method m2 = clazz.getMethod( "testReadSystemProperty", new Class[] {String.class} );
|
Method m2 = clazz.getMethod( "testReadSystemProperty", new Class[] {String.class} );
|
||||||
|
|
||||||
m2.invoke( clazz.newInstance(), new Object[] {"foobar"} );
|
m2.invoke(clazz.newInstance(),new Object[]
|
||||||
|
{ "foobar" });
|
||||||
}
|
|
||||||
catch ( ClassNotFoundException e )
|
fail("Should have thrown an InvocationTargetException");
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
assertFalse( "should not have got here", true );
|
|
||||||
}
|
}
|
||||||
catch ( InvocationTargetException e )
|
catch ( InvocationTargetException e )
|
||||||
{
|
{
|
||||||
assertTrue(e.getCause().getMessage().contains( "access denied" ));
|
assertTrue(e.getCause().getMessage().contains( "access denied" ));
|
||||||
|
|
||||||
excepted = true; // we hope to get here
|
|
||||||
}
|
}
|
||||||
catch ( IllegalAccessException e )
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
assertFalse( "should not have got here", true );
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( "checking that we through a security exception", excepted );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> getSinglePolicy(String name)
|
private Set<String> getSinglePolicy(String name)
|
||||||
|
|
|
@ -41,10 +41,21 @@ public class MavenTestingUtils
|
||||||
|
|
||||||
if (cwd == null)
|
if (cwd == null)
|
||||||
{
|
{
|
||||||
|
// System property not set.
|
||||||
|
|
||||||
|
// Use CWD.
|
||||||
cwd = System.getProperty("user.dir");
|
cwd = System.getProperty("user.dir");
|
||||||
|
basedir = new File(cwd);
|
||||||
|
|
||||||
|
// Set the System property.
|
||||||
|
System.setProperty("basedir",basedir.getAbsolutePath());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Has system property, use it.
|
||||||
|
basedir = new File(cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
basedir = new File(cwd);
|
|
||||||
baseURI = basedir.toURI();
|
baseURI = basedir.toURI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,6 +204,6 @@ public class MavenTestingUtils
|
||||||
|
|
||||||
public static URL toTargetURL(String path) throws MalformedURLException
|
public static URL toTargetURL(String path) throws MalformedURLException
|
||||||
{
|
{
|
||||||
return getBaseURI().resolve(path).toURL();
|
return getBaseURI().resolve("target/" + path).toURL();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue