[jboss-cvs] JBossAS SVN: r58952 - trunk/testsuite/src/main/org/jboss/test/web/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Dec 8 23:33:25 EST 2006
Author: bstansberry at jboss.com
Date: 2006-12-08 23:33:24 -0500 (Fri, 08 Dec 2006)
New Revision: 58952
Modified:
trunk/testsuite/src/main/org/jboss/test/web/test/ClusteredSingleSignOnUnitTestCase.java
Log:
Test SSO after undeploy with both distributed and non-distributed webapps
Use CacheHelper to test SSO count
Modified: trunk/testsuite/src/main/org/jboss/test/web/test/ClusteredSingleSignOnUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/test/ClusteredSingleSignOnUnitTestCase.java 2006-12-09 04:32:12 UTC (rev 58951)
+++ trunk/testsuite/src/main/org/jboss/test/web/test/ClusteredSingleSignOnUnitTestCase.java 2006-12-09 04:33:24 UTC (rev 58952)
@@ -1,45 +1,43 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* 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.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
package org.jboss.test.web.test;
-import java.net.HttpURLConnection;
+import java.util.Set;
+import javax.management.ObjectName;
+
import junit.framework.Test;
+import junit.framework.TestSuite;
-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.cache.Fqn;
import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.web.CacheHelper;
/** 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$
*/
@@ -62,15 +60,23 @@
*/
public static Test suite() throws Exception
{
- Test t1 = JBossClusteredTestCase.getDeploySetup(ClusteredSingleSignOnUnitTestCase.class,
- "web-sso-clustered.ear");
- return t1;
+ // Have to build the suite in detail, as testSessionExpiration must come first
+ TestSuite suite = new TestSuite();
+ suite.addTest(new ClusteredSingleSignOnUnitTestCase("testSessionExpiration"));
+ suite.addTest(new ClusteredSingleSignOnUnitTestCase("testFormAuthSingleSignOn"));
+ suite.addTest(new ClusteredSingleSignOnUnitTestCase("testUndeployNonClusteredWebapp"));
+ suite.addTest(new ClusteredSingleSignOnUnitTestCase("testUndeployClusteredWebapp"));
+
+ return JBossClusteredTestCase.getDeploySetup(suite, "web-sso-clustered.ear");
}
-
+
protected void setUp() throws Exception
{
super.setUp();
+ log.debug("deployed0 = " + deployed0);
+ log.debug("deployed1 = " + deployed1);
+
adaptors = getAdaptors();
if (!deployed0)
{
@@ -84,6 +90,28 @@
}
}
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ log.debug("deployed0 = " + deployed0);
+ log.debug("deployed1 = " + deployed1);
+ }
+
+ public void testUndeployNonClusteredWebapp() throws Exception
+ {
+ log.info("+++ testUndeployNonClusteredWebapp");
+
+ webappUndeployTest("war4", "war5");
+ }
+
+ public void testUndeployClusteredWebapp() throws Exception
+ {
+ log.info("+++ testUndeployClusteredWebapp");
+
+ webappUndeployTest("war1", "war2");
+ }
+
/**
* Tests that undeploying a webapp on one server doesn't kill an sso
* that also has a session from another webapp associated with it.
@@ -94,72 +122,30 @@
*
* @throws Exception
*/
- public void testWebappUndeploy() throws Exception
+ private void webappUndeployTest(String firstWar, String secondWar) throws Exception
{
- log.info("+++ testWebappUndeploy");
-
String[] httpURLs = super.getHttpURLs();
String serverA = httpURLs[0];
String serverB = httpURLs[1];
+ String warA1 = serverA + "/" + firstWar +"/";
+ String warB1 = serverB + "/" + firstWar +"/";
+ String warB2 = serverB + "/" + secondWar +"/";
+
// 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
@@ -172,16 +158,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))
@@ -199,18 +176,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");
}
@@ -244,72 +212,71 @@
String[] httpURLs = super.getHttpURLs();
String serverA = httpURLs[0];
+ String serverB = httpURLs[1];
log.info(System.getProperties());
log.info("serverA: "+serverA);
+ log.info("serverB: "+serverB);
- // Start by accessing the secured index.html of war1
+ String warA3 = serverA + "/war3/";
+ String warB3 = serverB + "/war3/";
+
+ // First create an SSO that we won't use again -- we later test that it
+ // gets cleaned up from the cache
+ HttpClient httpConn1 = new HttpClient();
+ SSOBaseCase.checkAccessDenied(httpConn1, warA3 + "index.jsp");
+ SSOBaseCase.executeFormLogin(httpConn1, warA3);
+
+ // Now the standard SSO tests
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();
+ String sessionID = SSOBaseCase.getSessionIdFromState(state);
+ log.debug("Saw JSESSIONID="+sessionID);
+ SSOBaseCase.executeFormLogin(httpConn, warA3);
+ String ssoID = SSOBaseCase.processSSOCookie(state, serverA, serverB);
+ log.debug("Saw JSESSIONIDSSO="+ssoID);
- HttpState state = httpConn.getState();
- Cookie[] cookies = state.getCookies();
- String sessionID = null;
- for(int c = 0; c < cookies.length; c ++)
+ // Wait more than 15 secs to let session time out
+ // It's life is 5 secs and the processor runs every 10
+ try {
+ Thread.sleep(15500);
+ }
+ catch (InterruptedException ie)
{
- Cookie k = cookies[c];
- if( k.getName().equalsIgnoreCase("JSESSIONID") )
- sessionID = k.getValue();
+ log.debug("Interrupted while waiting for session expiration");
}
- log.debug("Saw JSESSIONID="+sessionID);
+
+ // Try accessing war3 again on both nodes -- should succeed
+ SSOBaseCase.checkAccessAllowed(httpConn, warA3 + "index.jsp");
+ SSOBaseCase.checkAccessAllowed(httpConn, warB3 + "index.jsp");
- // 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);
-
- // 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 ???
- // (not an sso issue -- a tomcat issue)
+ // Wait more than 30 secs to let SSO time out -- 15 for the sessions
+ // (as above) and 15 for the SSOs maxEmptyLife
try {
- Thread.sleep(65500);
+ Thread.sleep(30500);
}
catch (InterruptedException ie)
{
- log.debug("Interrupted while waiting for session expiration");
+ log.debug("Interrupted while waiting for SSO expiration");
}
- // 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");
+ // Try accessing war3 again on both nodes -- should fail
+ SSOBaseCase.checkAccessDenied(httpConn, warA3 + "index.jsp");
+ SSOBaseCase.checkAccessDenied(httpConn, warB3 + "index.jsp");
+ // Confirm that the SSO we created at the start was removed from
+ // the cache
+ Set ssoIds = getSSOIds(adaptors[0]);
+ log.info("node0 sso ids are " + ssoIds);
+ assertEquals("node0 cache has no SSOs", 0, ssoIds.size());
+ ssoIds = getSSOIds(adaptors[1]);
+ log.info("node1 sso ids are " + ssoIds);
+ assertEquals("node1 cache has no SSOs", 0, ssoIds.size());
}
+
+ private Set getSSOIds(RMIAdaptor adaptor) throws Exception
+ {
+ return (Set) adaptor.invoke(CacheHelper.OBJECT_NAME, "getChildrenNames",
+ new Object[0], new String[0]);
+ }
}
More information about the jboss-cvs-commits
mailing list