1 22 package org.jboss.test.web.test.ssl; 23 24 import java.net.HttpURLConnection ; 25 26 import junit.framework.Test; 27 import org.apache.commons.httpclient.Header; 28 import org.apache.commons.httpclient.HttpClient; 29 import org.apache.commons.httpclient.methods.GetMethod; 30 import org.jboss.test.JBossTestCase; 31 32 38 public class SSLUnitTestCase extends JBossTestCase 39 { 40 private String baseHttpNoAuth = "http://" + getServerHost() + ":" + Integer.getInteger("web.port", 8080) + "/"; 41 private String baseHttpsNoAuth = "https://" + getServerHost() + ":" + Integer.getInteger("secureweb.port", 8443) + "/"; 42 43 public SSLUnitTestCase(String name) 44 { 45 super(name); 46 } 47 48 52 public void testHttpRedirect() throws Exception 53 { 54 log.info("+++ testHttpRedirect"); 55 doHttpRedirect(baseHttpNoAuth); 56 } 57 62 public void testHttpRedirectSecurityDomain() throws Exception 63 { 64 log.info("+++ testHttpRedirectSecurityDomain"); 65 int port = Integer.getInteger("web.port", 8080).intValue(); 66 port += 1000; 67 String httpNoAuth = "http://" + getServerHost() + ":" + port + "/"; 68 doHttpRedirect(httpNoAuth); 69 } 70 71 75 public void testHttps() throws Exception 76 { 77 log.info("+++ testHttps"); 78 doHttps(baseHttpsNoAuth); 79 } 80 81 public void testHttpsSecurityDomain() throws Exception 82 { 83 log.info("+++ testHttps"); 84 int port = Integer.getInteger("secureweb.port", 8443).intValue(); 85 port += 1000; 86 String httpsNoAuth = "https://" + getServerHost() + ":" + port + "/"; 87 doHttps(httpsNoAuth); 88 } 89 90 94 public void testEncryptPassword() throws Exception 95 { 96 log.info("+++ testHttps"); 97 int port = Integer.getInteger("secureweb.port", 8443).intValue(); 98 port += 1500; 99 String httpsNoAuth = "https://" + getServerHost() + ":" + port + "/"; 100 doHttps(httpsNoAuth); 101 } 102 103 104 private void doHttpRedirect(String httpNoAuth) throws Exception 105 { 106 log.info("+++ testHttpRedirect, httpNoAuth="+httpNoAuth); 107 HttpClient httpConn = new HttpClient(); 109 String url = httpNoAuth+"clientcert-auth/unrestricted/SecureServlet"; 110 log.info("Accessing: "+url); 111 GetMethod get = new GetMethod(url); 112 int responseCode = httpConn.executeMethod(get); 113 String status = get.getStatusText(); 114 log.debug(status); 115 assertTrue("Get HTTP_MOVED_TEMP("+responseCode+")", responseCode == HttpURLConnection.HTTP_MOVED_TEMP); 116 117 Header hdr = get.getResponseHeader("Location"); 118 url = hdr.getValue(); 119 get = new GetMethod(url); 120 responseCode = httpConn.executeMethod(get); 121 status = get.getStatusText(); 122 log.debug(status); 123 assertTrue("Get OK("+responseCode+")", responseCode == HttpURLConnection.HTTP_OK); 124 } 125 public void doHttps(String httpsNoAuth) throws Exception 126 { 127 log.info("+++ doHttps, httpsNoAuth="+httpsNoAuth); 128 HttpClient httpConn = new HttpClient(); 130 String url = httpsNoAuth+"clientcert-auth/unrestricted/SecureServlet"; 131 log.info("Accessing: "+url); 132 GetMethod get = new GetMethod(url); 133 int responseCode = httpConn.executeMethod(get); 134 String status = get.getStatusText(); 135 log.debug(status); 136 assertTrue("Get OK("+responseCode+")", responseCode == HttpURLConnection.HTTP_OK); 137 } 138 139 141 public static Test suite() throws Exception 142 { 143 Test suite = getDeploySetup(SSLUnitTestCase.class, "clientcert-auth.war"); 144 return suite; 145 } 146 } 147 | Popular Tags |