You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Thorsten Frank <tf...@logicline.de> on 2004/03/11 17:06:27 UTC

missing cookie name

hi all,

we're trying to test Struts actions with the StrutsTestCase package 
integrated into Cactus. All actions depend on a login, or more specific, 
parameters loaded after a successful login. our idea was to use a base 
class which stores a FormAuthentication object for all the test cases. We 
are using Websphere 5.0, struts 1.1, J2EE spec 1.3

Our problems seem to be similar to the one described in a previous mail of 
this list (no 04940):

when trying the tests depicted further below, we get the following error 
messages:

org.apache.cactus.util.ChainedRuntimeException: Failed to authenticate the 
principal
at 
org.apache.cactus.client.authentication.FormAuthentication.authenticate_aroundBody6(FormAuthentication.java:314)
at 
org.apache.cactus.client.authentication.FormAuthentication.authenticate_aroundBody7$advice(FormAuthentication.java:151)
at 
org.apache.cactus.client.authentication.FormAuthentication.authenticate(FormAuthentication.java)
at 
org.apache.cactus.client.authentication.FormAuthentication.configure_aroundBody0(FormAuthentication.java:155)
at 
org.apache.cactus.client.authentication.FormAuthentication.configure_aroundBody1$advice(FormAuthentication.java:151)
at 
org.apache.cactus.client.authentication.FormAuthentication.configure(FormAuthentication.java)

--- snip ---

java.lang.NullPointerException: missing cookie name
at org.apache.cactus.Cookie.<init>(Cookie.java:132)
at 
org.apache.cactus.BaseWebRequest.addCookie_aroundBody20(BaseWebRequest.java:421)
at 
org.apache.cactus.BaseWebRequest.addCookie_aroundBody21$advice(BaseWebRequest.java:151)
at org.apache.cactus.BaseWebRequest.addCookie(BaseWebRequest.java)
at 
org.apache.cactus.BaseWebRequest.addCookie_aroundBody18(BaseWebRequest.java:403)
at 
org.apache.cactus.BaseWebRequest.addCookie_aroundBody19$advice(BaseWebRequest.java:151)
at org.apache.cactus.BaseWebRequest.addCookie(BaseWebRequest.java)
at 
org.apache.cactus.client.authentication.FormAuthentication.authenticate_aroundBody6(FormAuthentication.java:292)
---

we are using a base test case, which is a subclass of 
servletunit.struts.CactusStrutsTestCase, which doesn't do much:

public class BaseStrutsTestCase extends CactusStrutsTestCase {

     private FormAuthentication formAuthentication;

     public void begin(WebRequest request) {
         if(formAuthentication == null) {
             formAuthentication = new FormAuthentication("ue05515", "nwm");
         }
         request.setRedirectorName("ServletRedirectorSecure");
         request.setAuthentication(formAuthentication);
     }
}

The actual test case looks like this:

public class RevisionenVerwaltenInitTest extends BaseStrutsTestCase {

     public void testSomeAction() {
         setRequestPathInfo("/test/testAction");
         actionPerform();
         verifyForward("success");
         ....
     }
}

All entries in the web.xml file are identical to the ones described in the 
cactus documentation.

Thanks in advance for any help...

kind regards,

thorsten frank



Re: missing cookie name

Posted by Kazuhito SUGURI <su...@lab.ntt.co.jp>.
Hi Thorsten,

In article <6....@mail.logicline.de>,
Fri, 12 Mar 2004 09:44:18 +0100,
Thorsten Frank <tf...@logicline.de> wrote: 
tfrank> but i discovered something else. a little more background: we are using the 
tfrank> JUnitEE servlet to run the tests within the container. The site is entirely 
tfrank> tunneled through SSL, although IMO that shouldn't be the problem, since we 
tfrank> trigger them through a browser. Also, there are no complaints from cactus 
tfrank> about not being able to connect, etc.

Could you try followings?
1. provide a simple Servlet to test and its test-case as subclass
   of ServletTestCase (not CactusStrutsTestCase)
2. run a test by using Cactus's ServletTestRunner

   Above two are to make the situation simple.
   I think its better for you to find out a working situation, first.

3. use plain HTTP and monitor NW traffics
   Cactus's form-based authentication is expectiong following sequence:
   Step 1: C->S connect to secured ServletRedirector to start authentication
	GET /target-app/ServletRedirectorSecure HTTP/1.1
   Step 2: S->C redirect to (or return) the login form page
	HTT/1.1 302 Moved Temporarily
	set-cookie: ....
	Location: http://localhost:8080/target-app/login.jsp
   Step 3: C->S send credentials to server
	POST /target-app/j_session_check HTTP/1.1
	Cookie: ....
   Step 4: S->C redirect to the protected resource
	HTTP/1.1 302 Moved Temporarily
   Step 5: C->S start to test as normal ServletRedirector does
	GET /target-app/ServletRedirectorSecure?Cactus_Service=... HTTP/1.1
	Cookie: ....

   The set-cookie header field in the Step 2 is important.
   If the one to set JSESSIONID is not exists,
   that may causes "missing cookie name".



tfrank> in our cactus.properties file, we have the following:
tfrank> cactus.contextURL = https:///localhost:9443/test
tfrank> 
tfrank> When setting logging output for cactus to debug though, i get the following 
tfrank> statement:
tfrank> 
tfrank> ...(AbstractWebConfiguration.java:236) - > getRedirectorURL = 
tfrank> [http://localhost:9080/test/ServletRedirectorSecure]
tfrank> 
tfrank> why???
tfrank> how should cactus now to NOT use the context url supplied in the properties 
tfrank> file?

If one uses ServletTestRunner, cactus.contextURL of cactus.properties
will not be used, but the servlet set the property by following code:
	"http://" + theRequest.getServerName() + ":"
	+ theRequest.getServerPort()
	+ theRequest.getContextPath()

This is a case I know, but it maybe not yours, since you are using
JUnitEE servlet. I feel strange....
----
Kazuhito SUGURI
E-mail: suguri.kazuhito@lab.ntt.co.jp

Re: missing cookie name

Posted by Thorsten Frank <tf...@logicline.de>.
hi suguri,

thx for your suggestions, but i don't think those are the cause. i secured 
the redirector according to the howto in the cactus docs.
but i discovered something else. a little more background: we are using the 
JUnitEE servlet to run the tests within the container. The site is entirely 
tunneled through SSL, although IMO that shouldn't be the problem, since we 
trigger them through a browser. Also, there are no complaints from cactus 
about not being able to connect, etc.
also, the name of our session cookie is in fact JSESSIONID, so that's not 
it either

BUT:
in our cactus.properties file, we have the following:
cactus.contextURL = https:///localhost:9443/test

When setting logging output for cactus to debug though, i get the following 
statement:

...(AbstractWebConfiguration.java:236) - > getRedirectorURL = 
[http://localhost:9080/test/ServletRedirectorSecure]

why???
how should cactus now to NOT use the context url supplied in the properties 
file?


kind regards / mit freundlichen GrĂ¼ssen
  --
  *  Thorsten Frank 



Re: missing cookie name

Posted by Kazuhito SUGURI <su...@lab.ntt.co.jp>.
Hi Frank,

In article <6....@mail.logicline.de>,
Thu, 11 Mar 2004 17:06:27 +0100,
Thorsten Frank <tf...@logicline.de> wrote: 
tfrank> we're trying to test Struts actions with the StrutsTestCase package 
tfrank> integrated into Cactus. All actions depend on a login, or more specific, 
tfrank> parameters loaded after a successful login. our idea was to use a base 
tfrank> class which stores a FormAuthentication object for all the test cases. We 
tfrank> are using Websphere 5.0, struts 1.1, J2EE spec 1.3
tfrank> 
tfrank> Our problems seem to be similar to the one described in a previous mail of 
tfrank> this list (no 04940):
tfrank> 
tfrank> when trying the tests depicted further below, we get the following error 
tfrank> messages:
[snip]
tfrank> java.lang.NullPointerException: missing cookie name
tfrank> at org.apache.cactus.Cookie.<init>(Cookie.java:132)

Possible causes:
1. your ServletRedirector is not configured to be secure
   You might check your web.xml.
   Redirectors your are using should be secured to testing secure codes.
   See also http://jakarta.apache.org/cactus/writing/howto_security.html

2. name of the session cookie is not JSESSIONID
   I think, this is not your case.
   But if so, and you are using Cactus-1.5, please try nightly build version
   of Cactus. It have FormAuthentication#setSessionCookieName(String)
   to change the cookie name.


I hope this helps,
----
Kazuhito SUGURI
mailto:suguri.kazuhito@lab.ntt.co.jp