User: starksm
Date: 02/02/28 18:21:43
Modified: src/main/org/jboss/test/securitymgr/test
EJBSpecUnitTestCase.java SecurityUnitTestCase.java
Added: src/main/org/jboss/test/securitymgr/test
PolicyUnitTestCase.java
Log:
Add additional tests
Revision Changes Path
1.3 +65 -12
jbosstest/src/main/org/jboss/test/securitymgr/test/EJBSpecUnitTestCase.java
Index: EJBSpecUnitTestCase.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/securitymgr/test/EJBSpecUnitTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- EJBSpecUnitTestCase.java 28 Feb 2002 08:43:20 -0000 1.2
+++ EJBSpecUnitTestCase.java 1 Mar 2002 02:21:43 -0000 1.3
@@ -31,12 +31,11 @@
};
@author [EMAIL PROTECTED]
-@version $Revision: 1.2 $
+@version $Revision: 1.3 $
*/
public class EJBSpecUnitTestCase
extends JBossTestCase
{
- org.apache.log4j.Category log = getLog();
public EJBSpecUnitTestCase(String name)
{
@@ -54,7 +53,7 @@
{
// This should fail because the bean calls File.exists()
bean.read("nofile.txt");
- fail("Was able to call IOSession.read");
+ doFail("Was able to call IOSession.read");
}
catch(Exception e)
{
@@ -65,7 +64,7 @@
{
// This should fail because the bean calls File.exists()
bean.write("nofile.txt");
- fail("Was able to call IOSession.write");
+ doFail("Was able to call IOSession.write");
}
catch(Exception e)
{
@@ -81,7 +80,7 @@
try
{
bean.listen(0);
- fail("Was able to call IOSession.listen");
+ doFail("Was able to call IOSession.listen");
}
catch(Exception e)
{
@@ -120,7 +119,7 @@
try
{
bean.createClassLoader();
- fail("Was able to call IOSession.createClassLoader");
+ doFail("Was able to call IOSession.createClassLoader");
}
catch(Exception e)
{
@@ -130,7 +129,7 @@
try
{
bean.getContextClassLoader();
- //fail("Was able to call IOSession.getContextClassLoader");
+ //doFail("Was able to call IOSession.getContextClassLoader");
log.debug("Was able to call IOSession.getContextClassLoader");
}
catch(Exception e)
@@ -141,7 +140,7 @@
try
{
bean.setContextClassLoader();
- fail("Was able to call IOSession.setContextClassLoader");
+ doFail("Was able to call IOSession.setContextClassLoader");
}
catch(Exception e)
{
@@ -150,6 +149,39 @@
bean.remove();
}
+ public void testReflection() throws Exception
+ {
+ log.debug("+++ testReflection()");
+ IOSession bean = getIOSession();
+ try
+ {
+ bean.useReflection();
+ doFail("Was able to call IOSession.useReflection");
+ }
+ catch(Exception e)
+ {
+ log.debug("IOSession.useReflection failed as expected", e);
+ }
+ bean.remove();
+ }
+
+ public void testThreadAccess() throws Exception
+ {
+ log.debug("+++ testThreadAccess()");
+ IOSession bean = getIOSession();
+ try
+ {
+ // This test will fail because the calling thread it not in the root
thread group
+ bean.renameThread();
+ doFail("Was able to call IOSession.renameThread");
+ }
+ catch(Exception e)
+ {
+ log.debug("IOSession.renameThread failed as expected", e);
+ }
+ bean.remove();
+ }
+
public void testSystemAccess() throws Exception
{
log.debug("+++ testSystemAccess()");
@@ -157,7 +189,7 @@
try
{
bean.createSecurityMgr();
- fail("Was able to call IOSession.createSecurityMgr");
+ doFail("Was able to call IOSession.createSecurityMgr");
}
catch(Exception e)
{
@@ -167,7 +199,7 @@
try
{
bean.createSecurityMgr();
- fail("Was able to call IOSession.changeSystemOut");
+ doFail("Was able to call IOSession.changeSystemOut");
}
catch(Exception e)
{
@@ -177,7 +209,7 @@
try
{
bean.changeSystemErr();
- fail("Was able to call IOSession.changeSystemErr");
+ doFail("Was able to call IOSession.changeSystemErr");
}
catch(Exception e)
{
@@ -186,8 +218,18 @@
try
{
+ bean.loadLibrary();
+ doFail("Was able to call IOSession.loadLibrary");
+ }
+ catch(Exception e)
+ {
+ log.debug("IOSession.loadLibrary failed as expected", e);
+ }
+
+ try
+ {
bean.systemExit(1);
- fail("Was able to call IOSession.systemExit");
+ doFail("Was able to call IOSession.systemExit");
}
catch(Exception e)
{
@@ -212,5 +254,16 @@
IOSession bean = home.create();
log.debug("Created IOSession");
return bean;
+ }
+
+ private void doFail(String msg)
+ {
+ log.error(msg);
+ fail(msg);
+ }
+ private void doFail(String msg, Throwable t)
+ {
+ log.error(msg, t);
+ fail(msg);
}
}
1.2 +0 -2
jbosstest/src/main/org/jboss/test/securitymgr/test/SecurityUnitTestCase.java
Index: SecurityUnitTestCase.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/securitymgr/test/SecurityUnitTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SecurityUnitTestCase.java 28 Feb 2002 08:43:20 -0000 1.1
+++ SecurityUnitTestCase.java 1 Mar 2002 02:21:43 -0000 1.2
@@ -7,8 +7,6 @@
package org.jboss.test.securitymgr.test;
import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
import javax.naming.InitialContext;
import org.jboss.test.securitymgr.interfaces.Bad;
@@ -24,7 +22,7 @@
standard EJB programming restrictions.
@author [EMAIL PROTECTED]
-@version $Revision: 1.1 $
+@version $Revision: 1.2 $
*/
public class SecurityUnitTestCase extends JBossTestCase
{
1.1
jbosstest/src/main/org/jboss/test/securitymgr/test/PolicyUnitTestCase.java
Index: PolicyUnitTestCase.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.securitymgr.test;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import org.jboss.test.securitymgr.ejb.BadBean;
import org.jboss.test.securitymgr.ejb.IOStatelessSessionBean;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.log4j.Category;
import org.jboss.test.JBossTestCase;
/** Tests of the security permission enforcement that creates and directly
invokes the ejb methods to test the security policy permissions
without the noise of the ejb container.
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public class PolicyUnitTestCase extends JBossTestCase
{
public PolicyUnitTestCase(String name)
{
super(name);
}
/** Test that a bean cannot access the SecurityAssociation class
*/
public void testSecurityAssociation() throws Exception
{
log.debug("+++ testSecurityAssociation()");
BadBean bean = getBadSession();
try
{
bean.getSecurityAssociationPrincipal();
doFail("Was able to call Bad.getSecurityAssociationPrincipal");
}
catch(Exception e)
{
log.debug("Bad.getSecurityAssociationPrincipal failed as expected", e);
}
try
{
bean.getSecurityAssociationCredential();
doFail("Was able to call Bad.getSecurityAssociationCredential");
}
catch(Exception e)
{
log.debug("Bad.getSecurityAssociationCredential failed as expected", e);
}
try
{
bean.setSecurityAssociationPrincipal(null);
doFail("Was able to call Bad.setSecurityAssociationPrincipal");
}
catch(Exception e)
{
log.debug("Bad.setSecurityAssociationPrincipal failed as expected", e);
}
try
{
char[] password = "secret".toCharArray();
bean.setSecurityAssociationCredential(password);
doFail("Was able to call Bad.setSecurityAssociationCredential");
}
catch(Exception e)
{
log.debug("Bad.setSecurityAssociationCredential failed as expected", e);
}
}
/** Test that a bean cannot access the filesystem using java.io.File
*/
public void testFileIO() throws Exception
{
log.debug("+++ testFileIO()");
IOStatelessSessionBean bean = getIOSession();
try
{
// This should fail because the bean calls File.exists()
bean.read("nofile.txt");
doFail("Was able to call IOSession.read");
}
catch(Exception e)
{
log.debug("IOSession.read failed as expected", e);
}
try
{
// This should fail because the bean calls File.exists()
bean.write("nofile.txt");
doFail("Was able to call IOSession.write");
}
catch(Exception e)
{
log.debug("IOSession.write failed as expected", e);
}
}
public void testSockets() throws Exception
{
log.debug("+++ testSockets()");
IOStatelessSessionBean bean = getIOSession();
try
{
bean.listen(0);
doFail("Was able to call IOSession.listen");
}
catch(Exception e)
{
log.debug("IOSession.listen failed as expected", e);
}
final ServerSocket tmp = new ServerSocket(0);
log.debug("Created ServerSocket: "+tmp);
final Category theLog = log;
Thread t = new Thread("Acceptor")
{
public void run()
{
try
{
Socket s = tmp.accept();
theLog.debug("Accepted Socket: "+s);
s.close();
theLog.debug("ServerSocket thread exiting");
}
catch(IOException e)
{
}
}
};
int port = tmp.getLocalPort();
t.start();
bean.connect("localhost", port);
tmp.close();
}
public void testClassLoaders() throws Exception
{
log.debug("+++ testClassLoaders()");
IOStatelessSessionBean bean = getIOSession();
try
{
bean.createClassLoader();
doFail("Was able to call IOSession.createClassLoader");
}
catch(Exception e)
{
log.debug("IOSession.createClassLoader failed as expected", e);
}
try
{
bean.getContextClassLoader();
//doFail("Was able to call IOSession.getContextClassLoader");
log.debug("Was able to call IOSession.getContextClassLoader");
}
catch(Exception e)
{
log.debug("IOSession.getContextClassLoader failed as expected", e);
}
try
{
bean.setContextClassLoader();
doFail("Was able to call IOSession.setContextClassLoader");
}
catch(Exception e)
{
log.debug("IOSession.setContextClassLoader failed as expected", e);
}
}
public void testReflection() throws Exception
{
log.debug("+++ testReflection()");
IOStatelessSessionBean bean = getIOSession();
try
{
bean.useReflection();
doFail("Was able to call IOSession.useReflection");
}
catch(Exception e)
{
log.debug("IOSession.useReflection failed as expected", e);
}
}
public void testThreadAccess() throws Exception
{
log.debug("+++ testThreadAccess()");
IOStatelessSessionBean bean = getIOSession();
try
{
// This test will fail because the calling thread it not in the root thread
group
bean.renameThread();
doFail("Was able to call IOSession.renameThread");
}
catch(Exception e)
{
log.debug("IOSession.renameThread failed as expected", e);
}
}
public void testSystemAccess() throws Exception
{
log.debug("+++ testSystemAccess()");
IOStatelessSessionBean bean = getIOSession();
try
{
bean.createSecurityMgr();
doFail("Was able to call IOSession.createSecurityMgr");
}
catch(Exception e)
{
log.debug("IOSession.createSecurityMgr failed as expected", e);
}
try
{
bean.createSecurityMgr();
doFail("Was able to call IOSession.changeSystemOut");
}
catch(Exception e)
{
log.debug("IOSession.changeSystemOut failed as expected", e);
}
try
{
bean.changeSystemErr();
doFail("Was able to call IOSession.changeSystemErr");
}
catch(Exception e)
{
log.debug("IOSession.changeSystemErr failed as expected", e);
}
try
{
bean.loadLibrary();
doFail("Was able to call IOSession.loadLibrary");
}
catch(Exception e)
{
log.debug("IOSession.loadLibrary failed as expected", e);
}
/* This test can't be enforced when running in a forked VM. The
Runtime.exec adss the (java.lang.RuntimePermission exitVM) to all jars
in the caller classpath it seems. We can't let it fail as this
kills the junit vm and no results are generated.
try
{
bean.systemExit(1);
doFail("Was able to call IOSession.systemExit");
}
catch(Exception e)
{
log.debug("IOSession.systemExit failed as expected", e);
}
*/
}
/** We don't use the JBoss server so nullify this test
*/
public void testServerFound() throws Exception
{
log.debug("+++ testServerFound()");
}
/** We don't deploy anything.
*/
public static Test suite() throws Exception
{
TestSuite suite = new TestSuite(PolicyUnitTestCase.class);
//suite.addTest(new PolicyUnitTestCase("testReflection"));
return suite;
}
private BadBean getBadSession()
{
BadBean bean = new BadBean();
return bean;
}
private IOStatelessSessionBean getIOSession()
{
IOStatelessSessionBean bean = new IOStatelessSessionBean();
return bean;
}
private void doFail(String msg)
{
log.error(msg);
fail(msg);
}
private void doFail(String msg, Throwable t)
{
log.error(msg, t);
fail(msg);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development