1 22 package org.jboss.test.web.test; 23 24 import java.net.HttpURLConnection ; 25 26 import junit.framework.Test; 27 28 import org.apache.commons.httpclient.Cookie; 29 import org.apache.commons.httpclient.Header; 30 import org.apache.commons.httpclient.HttpClient; 31 import org.apache.commons.httpclient.HttpState; 32 import org.apache.commons.httpclient.methods.GetMethod; 33 import org.apache.commons.httpclient.methods.PostMethod; 34 35 import org.jboss.jmx.adaptor.rmi.RMIAdaptor; 36 import org.jboss.test.JBossClusteredTestCase; 37 38 39 46 public class ClusteredSingleSignOnUnitTestCase 47 extends JBossClusteredTestCase 48 { 49 private static boolean deployed0 = true; 52 private static boolean deployed1 = true; 53 54 private RMIAdaptor[] adaptors = null; 55 56 public ClusteredSingleSignOnUnitTestCase(String name) 57 { 58 super(name); 59 } 60 61 63 public static Test suite() throws Exception 64 { 65 Test t1 = JBossClusteredTestCase.getDeploySetup(ClusteredSingleSignOnUnitTestCase.class, 66 "web-sso-clustered.ear"); 67 return t1; 68 } 69 70 protected void setUp() throws Exception 71 { 72 super.setUp(); 73 74 adaptors = getAdaptors(); 75 if (!deployed0) 76 { 77 deploy(adaptors[0], "web-sso-clustered.ear"); 78 deployed0 = true; 79 } 80 if (!deployed1) 81 { 82 deploy(adaptors[1], "web-sso-clustered.ear"); 83 deployed1 = true; 84 } 85 } 86 87 97 public void testWebappUndeploy() throws Exception 98 { 99 log.info("+++ testWebappUndeploy"); 100 101 String [] httpURLs = super.getHttpURLs(); 102 103 String serverA = httpURLs[0]; 104 String serverB = httpURLs[1]; 105 106 HttpClient httpConn = new HttpClient(); 108 GetMethod indexGet = new GetMethod(serverA+"/war1/index.html"); 109 int responseCode = httpConn.executeMethod(indexGet); 110 String body = indexGet.getResponseBodyAsString(); 111 assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK); 112 assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 ); 113 114 HttpState state = httpConn.getState(); 115 Cookie[] cookies = state.getCookies(); 116 String sessionID = null; 117 for(int c = 0; c < cookies.length; c ++) 118 { 119 Cookie k = cookies[c]; 120 if( k.getName().equalsIgnoreCase("JSESSIONID") ) 121 sessionID = k.getValue(); 122 } 123 log.debug("Saw JSESSIONID="+sessionID); 124 125 PostMethod formPost = new PostMethod(serverA+"/war1/j_security_check"); 127 formPost.addRequestHeader("Referer", serverA+"/war1/login.html"); 128 formPost.addParameter("j_username", "jduke"); 129 formPost.addParameter("j_password", "theduke"); 130 responseCode = httpConn.executeMethod(formPost.getHostConfiguration(), 131 formPost, state); 132 String response = formPost.getStatusText(); 133 log.debug("responseCode="+responseCode+", response="+response); 134 assertTrue("Saw HTTP_MOVED_TEMP("+responseCode+")", 135 responseCode == HttpURLConnection.HTTP_MOVED_TEMP); 136 137 Header location = formPost.getResponseHeader("Location"); 139 String indexURI = location.getValue(); 140 GetMethod war1Index = new GetMethod(indexURI); 141 responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(), 142 war1Index, state); 143 assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK); 144 body = war1Index.getResponseBodyAsString(); 145 if( body.indexOf("j_security_check") > 0 ) 146 fail("get of "+indexURI+" redirected to login page"); 147 148 cookies = state.getCookies(); 149 String ssoID = null; 150 for(int c = 0; c < cookies.length; c ++) 151 { 152 Cookie k = cookies[c]; 153 if( k.getName().equalsIgnoreCase("JSESSIONIDSSO") ) 154 { 155 ssoID = k.getValue(); 156 Cookie copy = SSOBaseCase.copyCookie(k, serverB); 158 state.addCookie(copy); 159 log.debug("Added state cookie: "+copy); 160 } 161 } 162 assertTrue("Saw JSESSIONIDSSO", ssoID != null); 163 log.debug("Saw JSESSIONIDSSO="+ssoID); 164 165 if (!serverA.equals(serverB)) 171 Thread.sleep(500); 172 173 log.debug("Prepare /war2/index.html get"); 175 GetMethod war2Index = new GetMethod(serverB+"/war2/index.html"); 176 responseCode = httpConn.executeMethod(war2Index.getHostConfiguration(), 177 war2Index, state); 178 response = war2Index.getStatusText(); 179 log.debug("responseCode="+responseCode+", response="+response); 180 assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK); 181 body = war2Index.getResponseBodyAsString(); 182 log.debug("body: "+body); 183 if( body.indexOf("j_security_check") > 0 ) 184 fail("get of /war2/index.html redirected to login page"); 185 186 if (!serverA.equals(serverB)) 188 Thread.sleep(500); 189 190 194 undeploy(adaptors[0], "web-sso-clustered.ear"); 196 deployed0 = false; 197 198 if (!serverA.equals(serverB)) 200 Thread.sleep(500); 201 202 log.debug("Prepare /war1/index.html get"); 204 war1Index = new GetMethod(serverB+"/war1/index.html"); 205 responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(), 206 war1Index, state); 207 response = war1Index.getStatusText(); 208 log.debug("responseCode="+responseCode+", response="+response); 209 assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK); 210 body = war1Index.getResponseBodyAsString(); 211 log.debug("body: "+body); 212 if( body.indexOf("j_security_check") > 0 ) 213 fail("get of /war1/index.html redirected to login page"); 214 } 215 216 217 221 public void testFormAuthSingleSignOn() throws Exception 222 { 223 log.info("+++ testFormAuthSingleSignOn"); 224 String [] httpURLs = super.getHttpURLs(); 225 226 String serverA = httpURLs[0]; 227 String serverB = httpURLs[1]; 228 log.info(System.getProperties()); 229 log.info("serverA: "+serverA); 230 log.info("serverB: "+serverB); 231 SSOBaseCase.executeFormAuthSingleSignOnTest(serverA, serverB, getLog()); 232 } 233 234 240 public void testSessionExpiration() 241 throws Exception 242 { 243 log.info("+++ testSessionExpiration"); 244 String [] httpURLs = super.getHttpURLs(); 245 246 String serverA = httpURLs[0]; 247 log.info(System.getProperties()); 248 log.info("serverA: "+serverA); 249 250 HttpClient httpConn = new HttpClient(); 252 GetMethod indexGet = new GetMethod(serverA+"/war3/index.jsp"); 253 int responseCode = httpConn.executeMethod(indexGet); 254 String body = indexGet.getResponseBodyAsString(); 255 assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK); 256 assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 ); 257 258 HttpState state = httpConn.getState(); 259 Cookie[] cookies = state.getCookies(); 260 String sessionID = null; 261 for(int c = 0; c < cookies.length; c ++) 262 { 263 Cookie k = cookies[c]; 264 if( k.getName().equalsIgnoreCase("JSESSIONID") ) 265 sessionID = k.getValue(); 266 } 267 log.debug("Saw JSESSIONID="+sessionID); 268 269 PostMethod formPost = new PostMethod(serverA+"/war3/j_security_check"); 271 formPost.addRequestHeader("Referer", serverA+"/war3/login.html"); 272 formPost.addParameter("j_username", "jduke"); 273 formPost.addParameter("j_password", "theduke"); 274 responseCode = httpConn.executeMethod(formPost.getHostConfiguration(), 275 formPost, state); 276 String response = formPost.getStatusText(); 277 log.debug("responseCode="+responseCode+", response="+response); 278 assertTrue("Saw HTTP_MOVED_TEMP("+responseCode+")", 279 responseCode == HttpURLConnection.HTTP_MOVED_TEMP); 280 281 Header location = formPost.getResponseHeader("Location"); 283 String indexURI = location.getValue(); 284 GetMethod war1Index = new GetMethod(indexURI); 285 responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(), 286 war1Index, state); 287 assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK); 288 body = war1Index.getResponseBodyAsString(); 289 if( body.indexOf("j_security_check") > 0 ) 290 fail("get of "+indexURI+" redirected to login page"); 291 292 try { 297 Thread.sleep(65500); 298 } 299 catch (InterruptedException ie) 300 { 301 log.debug("Interrupted while waiting for session expiration"); 302 } 303 304 war1Index = new GetMethod(serverA+"/war3/index.jsp"); 306 responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(), 307 war1Index, state); 308 assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK); 309 body = war1Index.getResponseBodyAsString(); 310 log.debug("body: " + body); 311 if( body.indexOf("j_security_check") < 0 ) 312 fail("get of /war1/index.html not redirected to login page"); 313 314 } 315 } 316 | Popular Tags |