1 22 package org.jboss.test.securitymgr.test; 23 24 import java.net.URL ; 25 26 import org.jboss.test.JBossTestCase; 27 import org.jboss.test.JBossTestSetup; 28 import org.jboss.test.util.web.HttpUtils; 29 import org.apache.commons.httpclient.Header; 30 import org.apache.commons.httpclient.HttpMethodBase; 31 import junit.framework.Test; 32 import junit.framework.TestSuite; 33 34 39 public class WarPermissionsUnitTestCase 40 extends JBossTestCase 41 { 42 private String baseURL = HttpUtils.getBaseURL(); 43 44 public WarPermissionsUnitTestCase(String name) 45 { 46 super(name); 47 } 48 49 public void testPackedAllowedPermissions() 50 throws Exception 51 { 52 URL url = new URL (baseURL+"packed/FileAccessServlet?file=allow"); 53 HttpMethodBase request = HttpUtils.accessURL(url); 54 Header hdr = request.getResponseHeader("X-CodeSource"); 55 log.info("X-CodeSource: "+hdr); 56 assertTrue("X-CodeSource("+hdr+") is NOT null", hdr != null); 57 hdr = request.getResponseHeader("X-RealPath"); 58 log.info("X-RealPath: "+hdr); 59 assertTrue("X-RealPath("+hdr+") is NOT null", hdr != null); 60 hdr = request.getResponseHeader("X-Exception"); 61 log.info("X-Exception: "+hdr); 62 assertTrue("X-Exception("+hdr+") is null", hdr == null); 63 } 64 public void testUnpackedAllowedPermissions() 65 throws Exception 66 { 67 URL url = new URL (baseURL+"unpacked/FileAccessServlet?file=allow"); 68 HttpMethodBase request = HttpUtils.accessURL(url); 69 Header hdr = request.getResponseHeader("X-CodeSource"); 70 log.info("X-CodeSource: "+hdr); 71 assertTrue("X-CodeSource("+hdr+") is NOT null", hdr != null); 72 hdr = request.getResponseHeader("X-RealPath"); 73 log.info("X-RealPath: "+hdr); 74 assertTrue("X-RealPath("+hdr+") is NOT null", hdr != null); 75 hdr = request.getResponseHeader("X-Exception"); 76 log.info("X-Exception: "+hdr); 77 assertTrue("X-Exception("+hdr+") is null", hdr == null); 78 } 79 80 public static Test suite() throws Exception 81 { 82 TestSuite suite = new TestSuite(); 83 suite.addTest(new TestSuite(WarPermissionsUnitTestCase.class)); 84 85 Test wrapper = new JBossTestSetup(suite) 87 { 88 protected void setUp() throws Exception 89 { 90 super.setUp(); 91 redeploy("securitymgr/unpacked.war"); 92 redeploy("securitymgr/packed.war"); 93 } 94 protected void tearDown() throws Exception 95 { 96 undeploy("securitymgr/unpacked.war"); 97 undeploy("securitymgr/packed.war"); 98 super.tearDown(); 99 } 100 }; 101 return wrapper; 102 } 103 104 } 105 | Popular Tags |