User: starksm
Date: 02/02/28 00:43:20
Modified: src/main/org/jboss/test/securitymgr/test
EJBSpecUnitTestCase.java
Added: src/main/org/jboss/test/securitymgr/test
SecurityUnitTestCase.java
Log:
Add additional permission violation checks
Revision Changes Path
1.2 +139 -15
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EJBSpecUnitTestCase.java 25 Feb 2002 08:11:21 -0000 1.1
+++ EJBSpecUnitTestCase.java 28 Feb 2002 08:43:20 -0000 1.2
@@ -7,11 +7,9 @@
package org.jboss.test.securitymgr.test;
import java.io.IOException;
-import java.rmi.RemoteException;
-import javax.ejb.CreateException;
-import javax.management.ObjectName;
+import java.net.ServerSocket;
+import java.net.Socket;
import javax.naming.InitialContext;
-import javax.naming.NamingException;
import org.jboss.test.securitymgr.interfaces.IOSession;
import org.jboss.test.securitymgr.interfaces.IOSessionHome;
@@ -21,7 +19,6 @@
import junit.framework.TestSuite;
import org.jboss.test.JBossTestCase;
-import org.jboss.test.JBossTestSetup;
/** Tests of the programming restrictions defined by the EJB spec. The JBoss
server must be running under a security manager. The securitymgr-ejb.jar
@@ -34,7 +31,7 @@
};
@author [EMAIL PROTECTED]
-@version $Revision: 1.1 $
+@version $Revision: 1.2 $
*/
public class EJBSpecUnitTestCase
extends JBossTestCase
@@ -51,11 +48,7 @@
public void testFileIO() throws Exception
{
log.debug("+++ testFileIO()");
- Object obj = getInitialContext().lookup("secmgr.IOSessionHome");
- IOSessionHome home = (IOSessionHome) obj;
- log.debug("Found secmgr.IOSessionHome");
- IOSession bean = home.create();
- log.debug("Created IOSession");
+ IOSession bean = getIOSession();
try
{
@@ -63,9 +56,9 @@
bean.read("nofile.txt");
fail("Was able to call IOSession.read");
}
- catch(RemoteException e)
+ catch(Exception e)
{
- log.debug("IOSession.read failed as expected");
+ log.debug("IOSession.read failed as expected", e);
}
try
@@ -74,9 +67,131 @@
bean.write("nofile.txt");
fail("Was able to call IOSession.write");
}
- catch(RemoteException e)
+ catch(Exception e)
+ {
+ log.debug("IOSession.write failed as expected", e);
+ }
+ bean.remove();
+ }
+
+ public void testSockets() throws Exception
+ {
+ log.debug("+++ testSockets()");
+ IOSession bean = getIOSession();
+ try
+ {
+ bean.listen(0);
+ fail("Was able to call IOSession.listen");
+ }
+ catch(Exception e)
{
- log.debug("IOSession.read failed as expected");
+ log.debug("IOSession.listen failed as expected", e);
+ }
+
+ final ServerSocket tmp = new ServerSocket(0);
+ log.debug("Created ServerSocket: "+tmp);
+ Thread t = new Thread("Acceptor")
+ {
+ public void run()
+ {
+ try
+ {
+ Socket s = tmp.accept();
+ log.debug("Accepted Socket: "+s);
+ s.close();
+ log.debug("ServerSocket thread exiting");
+ }
+ catch(IOException e)
+ {
+ }
+ }
+ };
+ int port = tmp.getLocalPort();
+ t.start();
+ bean.connect("localhost", port);
+ tmp.close();
+ bean.remove();
+ }
+
+ public void testClassLoaders() throws Exception
+ {
+ log.debug("+++ testClassLoaders()");
+ IOSession bean = getIOSession();
+ try
+ {
+ bean.createClassLoader();
+ fail("Was able to call IOSession.createClassLoader");
+ }
+ catch(Exception e)
+ {
+ log.debug("IOSession.createClassLoader failed as expected", e);
+ }
+
+ try
+ {
+ bean.getContextClassLoader();
+ //fail("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();
+ fail("Was able to call IOSession.setContextClassLoader");
+ }
+ catch(Exception e)
+ {
+ log.debug("IOSession.setContextClassLoader failed as expected", e);
+ }
+ bean.remove();
+ }
+
+ public void testSystemAccess() throws Exception
+ {
+ log.debug("+++ testSystemAccess()");
+ IOSession bean = getIOSession();
+ try
+ {
+ bean.createSecurityMgr();
+ fail("Was able to call IOSession.createSecurityMgr");
+ }
+ catch(Exception e)
+ {
+ log.debug("IOSession.createSecurityMgr failed as expected", e);
+ }
+
+ try
+ {
+ bean.createSecurityMgr();
+ fail("Was able to call IOSession.changeSystemOut");
+ }
+ catch(Exception e)
+ {
+ log.debug("IOSession.changeSystemOut failed as expected", e);
+ }
+
+ try
+ {
+ bean.changeSystemErr();
+ fail("Was able to call IOSession.changeSystemErr");
+ }
+ catch(Exception e)
+ {
+ log.debug("IOSession.changeSystemErr failed as expected", e);
+ }
+
+ try
+ {
+ bean.systemExit(1);
+ fail("Was able to call IOSession.systemExit");
+ }
+ catch(Exception e)
+ {
+ log.debug("IOSession.systemExit failed as expected", e);
}
bean.remove();
}
@@ -89,4 +204,13 @@
return getDeploySetup(EJBSpecUnitTestCase.class, "securitymgr-ejb.jar");
}
+ private IOSession getIOSession() throws Exception
+ {
+ Object obj = getInitialContext().lookup("secmgr.IOSessionHome");
+ IOSessionHome home = (IOSessionHome) obj;
+ log.debug("Found secmgr.IOSessionHome");
+ IOSession bean = home.create();
+ log.debug("Created IOSession");
+ return bean;
+ }
}
1.1
jbosstest/src/main/org/jboss/test/securitymgr/test/SecurityUnitTestCase.java
Index: SecurityUnitTestCase.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 javax.naming.InitialContext;
import org.jboss.test.securitymgr.interfaces.Bad;
import org.jboss.test.securitymgr.interfaces.BadHome;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jboss.test.JBossTestCase;
/** Tests of the security permission enforcement for items outside of the
standard EJB programming restrictions.
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public class SecurityUnitTestCase extends JBossTestCase
{
org.apache.log4j.Category log = getLog();
public SecurityUnitTestCase(String name)
{
super(name);
}
/** Test that a bean cannot access the SecurityAssociation class
*/
public void testSecurityAssociation() throws Exception
{
log.debug("+++ testSecurityAssociation()");
Bad bean = getBadSession();
try
{
bean.getSecurityAssociationPrincipal();
fail("Was able to call Bad.getSecurityAssociationPrincipal");
}
catch(Exception e)
{
log.debug("Bad.getSecurityAssociationPrincipal failed as expected", e);
}
try
{
bean.getSecurityAssociationCredential();
fail("Was able to call Bad.getSecurityAssociationCredential");
}
catch(Exception e)
{
log.debug("Bad.getSecurityAssociationCredential failed as expected", e);
}
try
{
bean.setSecurityAssociationPrincipal(null);
fail("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);
fail("Was able to call Bad.setSecurityAssociationCredential");
}
catch(Exception e)
{
log.debug("Bad.setSecurityAssociationCredential failed as expected", e);
}
bean.remove();
}
/**
* Setup the test suite.
*/
public static Test suite() throws Exception
{
return getDeploySetup(SecurityUnitTestCase.class, "securitymgr-ejb.jar");
}
private Bad getBadSession() throws Exception
{
Object obj = getInitialContext().lookup("secmgr.BadHome");
BadHome home = (BadHome) obj;
log.debug("Found secmgr.BadHome");
Bad bean = home.create();
log.debug("Created Bad");
return bean;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development