[Jboss-cvs] JBossAS SVN: r56637 - branches/Branch_4_0/testsuite/src/main/org/jboss/test/web/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Sep 8 00:02:52 EDT 2006
Author: bstansberry at jboss.com
Date: 2006-09-08 00:02:51 -0400 (Fri, 08 Sep 2006)
New Revision: 56637
Modified:
branches/Branch_4_0/testsuite/src/main/org/jboss/test/web/test/ClusteredSingleSignOnUnitTestCase.java
branches/Branch_4_0/testsuite/src/main/org/jboss/test/web/test/SingleSignOnUnitTestCase.java
Log:
Refactor redundant code
Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/web/test/ClusteredSingleSignOnUnitTestCase.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/web/test/ClusteredSingleSignOnUnitTestCase.java 2006-09-08 03:37:35 UTC (rev 56636)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/web/test/ClusteredSingleSignOnUnitTestCase.java 2006-09-08 04:02:51 UTC (rev 56637)
@@ -1,6 +1,6 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -21,25 +21,16 @@
*/
package org.jboss.test.web.test;
-import java.net.HttpURLConnection;
-
import junit.framework.Test;
-import org.apache.commons.httpclient.Cookie;
-import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpState;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-
import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
import org.jboss.test.JBossClusteredTestCase;
/** Tests of web app single sign-on in a clustered environment
*
- * TODO general refactoring; a lot of duplicated code here
- *
* @author Brian Stansberry
* @version $Revision$
*/
@@ -114,62 +105,23 @@
String serverA = httpURLs[0];
String serverB = httpURLs[1];
+ String warA1 = serverA + "/war1/";
+ String warB1 = serverB + "/war1/";
+ String warB2 = serverB + "/war2/";
+
// Start by accessing the secured index.html of war1
HttpClient httpConn = new HttpClient();
- GetMethod indexGet = new GetMethod(serverA+"/war1/index.html");
- int responseCode = httpConn.executeMethod(indexGet);
- String body = indexGet.getResponseBodyAsString();
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 );
+ SSOBaseCase.checkAccessDenied(httpConn, warA1 + "index.html");
HttpState state = httpConn.getState();
- Cookie[] cookies = state.getCookies();
- String sessionID = null;
- for(int c = 0; c < cookies.length; c ++)
- {
- Cookie k = cookies[c];
- if( k.getName().equalsIgnoreCase("JSESSIONID") )
- sessionID = k.getValue();
-}
+
+ String sessionID = SSOBaseCase.getSessionIdFromState(state);
log.debug("Saw JSESSIONID="+sessionID);
+
// Submit the login form
- PostMethod formPost = new PostMethod(serverA+"/war1/j_security_check");
- formPost.addRequestHeader("Referer", serverA+"/war1/login.html");
- formPost.addParameter("j_username", "jduke");
- formPost.addParameter("j_password", "theduke");
- responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
- formPost, state);
- String response = formPost.getStatusText();
- log.debug("responseCode="+responseCode+", response="+response);
- assertTrue("Saw HTTP_MOVED_TEMP("+responseCode+")",
- responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
+ SSOBaseCase.executeFormLogin(httpConn, warA1);
- // Follow the redirect to the index.html page
- Header location = formPost.getResponseHeader("Location");
- String indexURI = location.getValue();
- GetMethod war1Index = new GetMethod(indexURI);
- responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
- war1Index, state);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war1Index.getResponseBodyAsString();
- if( body.indexOf("j_security_check") > 0 )
- fail("get of "+indexURI+" redirected to login page");
-
- cookies = state.getCookies();
- String ssoID = null;
- for(int c = 0; c < cookies.length; c ++)
- {
- Cookie k = cookies[c];
- if( k.getName().equalsIgnoreCase("JSESSIONIDSSO") )
- {
- ssoID = k.getValue();
- // Make an sso cookie to send to serverB
- Cookie copy = SSOBaseCase.copyCookie(k, serverB);
- state.addCookie(copy);
- log.debug("Added state cookie: "+copy);
- }
- }
- assertTrue("Saw JSESSIONIDSSO", ssoID != null);
+ String ssoID = SSOBaseCase.processSSOCookie(state, serverA, serverB);
log.debug("Saw JSESSIONIDSSO="+ssoID);
// Pause a moment before switching wars to better simulate real life
@@ -182,16 +134,7 @@
// Now try getting the war2 index using the JSESSIONIDSSO cookie
log.debug("Prepare /war2/index.html get");
- GetMethod war2Index = new GetMethod(serverB+"/war2/index.html");
- responseCode = httpConn.executeMethod(war2Index.getHostConfiguration(),
- war2Index, state);
- response = war2Index.getStatusText();
- log.debug("responseCode="+responseCode+", response="+response);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war2Index.getResponseBodyAsString();
- log.debug("body: "+body);
- if( body.indexOf("j_security_check") > 0 )
- fail("get of /war2/index.html redirected to login page");
+ SSOBaseCase.checkAccessAllowed(httpConn, warB2 + "index.html");
// Sleep some more to allow the updated sso to propagate back to serverA
if (!serverA.equals(serverB))
@@ -209,18 +152,9 @@
if (!serverA.equals(serverB))
Thread.sleep(500);
- // Now try getting the war1 index using the JSESSIONIDSSO cookie
+ // Now try getting the war1 index using the JSESSIONIDSSO cookie
log.debug("Prepare /war1/index.html get");
- war1Index = new GetMethod(serverB+"/war1/index.html");
- responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
- war1Index, state);
- response = war1Index.getStatusText();
- log.debug("responseCode="+responseCode+", response="+response);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war1Index.getResponseBodyAsString();
- log.debug("body: "+body);
- if( body.indexOf("j_security_check") > 0 )
- fail("get of /war1/index.html redirected to login page");
+ SSOBaseCase.checkAccessAllowed(httpConn, warB1 + "index.html");
}
/** Test single sign-on across two web apps using form based auth
@@ -256,48 +190,20 @@
log.info(System.getProperties());
log.info("serverA: "+serverA);
+ String warA3 = serverA + "/war3/";
+
// Start by accessing the secured index.html of war1
HttpClient httpConn = new HttpClient();
- GetMethod indexGet = new GetMethod(serverA+"/war3/index.jsp");
- int responseCode = httpConn.executeMethod(indexGet);
- String body = indexGet.getResponseBodyAsString();
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 );
+ SSOBaseCase.checkAccessDenied(httpConn, warA3 + "index.jsp");
HttpState state = httpConn.getState();
- Cookie[] cookies = state.getCookies();
- String sessionID = null;
- for(int c = 0; c < cookies.length; c ++)
- {
- Cookie k = cookies[c];
- if( k.getName().equalsIgnoreCase("JSESSIONID") )
- sessionID = k.getValue();
- }
+
+ String sessionID = SSOBaseCase.getSessionIdFromState(state);
log.debug("Saw JSESSIONID="+sessionID);
-
+
// Submit the login form
- PostMethod formPost = new PostMethod(serverA+"/war3/j_security_check");
- formPost.addRequestHeader("Referer", serverA+"/war3/login.html");
- formPost.addParameter("j_username", "jduke");
- formPost.addParameter("j_password", "theduke");
- responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
- formPost, state);
- String response = formPost.getStatusText();
- log.debug("responseCode="+responseCode+", response="+response);
- assertTrue("Saw HTTP_MOVED_TEMP("+responseCode+")",
- responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
+ SSOBaseCase.executeFormLogin(httpConn, warA3);
- // Follow the redirect to the index.html page
- Header location = formPost.getResponseHeader("Location");
- String indexURI = location.getValue();
- GetMethod war1Index = new GetMethod(indexURI);
- responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
- war1Index, state);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war1Index.getResponseBodyAsString();
- if( body.indexOf("j_security_check") > 0 )
- fail("get of "+indexURI+" redirected to login page");
-
// Wait more than 65 secs to let session time out
// 5 secs for the session timeout, 2 * 30 secs for the processor thread
// TODO for some reason it takes 1 min for processExpires to run ???
@@ -311,14 +217,7 @@
}
// Try accessing war1 again
- war1Index = new GetMethod(serverA+"/war3/index.jsp");
- responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
- war1Index, state);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war1Index.getResponseBodyAsString();
- log.debug("body: " + body);
- if( body.indexOf("j_security_check") < 0 )
- fail("get of /war1/index.html not redirected to login page");
+ SSOBaseCase.checkAccessDenied(httpConn, warA3 + "index.jsp");
}
}
Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/web/test/SingleSignOnUnitTestCase.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/web/test/SingleSignOnUnitTestCase.java 2006-09-08 03:37:35 UTC (rev 56636)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/web/test/SingleSignOnUnitTestCase.java 2006-09-08 04:02:51 UTC (rev 56637)
@@ -1,6 +1,6 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
More information about the jboss-cvs-commits
mailing list