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 Jo...@ubs.com on 2004/10/08 16:47:29 UTC

Test a Servlet With Authentication

I am trying setup testcases with for an application that has a security-constraint on the front controller (struts ActionServlet), running on Tomcat 4.1.27. We are using FormAuthentication with a JOB realm.

I am using StrutsTestCase, and I saw the documentation located at http://strutstestcase.sourceforge.net/. Since we cannot predetermine which testcase will run first, and the documented technique cannot run in the setup, this means that every testcase is going have to be coded to do the the login action, prior to doing the testing the action that is the subject of the testcase.

My first solution was to create a mock or stub of the principle and credential objects and put them into session. However, the setPrincipal method is not exposed in the standard HttpSession api, and the implemented sessionObject is not visible.

Does anyone have any suggestions?


John 

Visit our website at http://www.ubs.com

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.


Re: Test a Servlet With Authentication

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

In article <5C...@NSTMC007PEX1.ubsgs.ubsgroup.net>,
Fri, 8 Oct 2004 10:47:29 -0400,
John.Cotter@ubs.com wrote: 
John> I am trying setup testcases with for an application that has
John> a security-constraint on the front controller (struts ActionServlet),
John> running on Tomcat 4.1.27. We are using FormAuthentication with a JOB realm.
John>
John> I am using StrutsTestCase, and I saw the documentation located at
John> http://strutstestcase.sourceforge.net/. Since we cannot predetermine
John> which testcase will run first, and the documented technique cannot run
John> in the setup, this means that every testcase is going have to be coded
John> to do the the login action, prior to doing the testing the action
John> that is the subject of the testcase.
John> 
John> My first solution was to create a mock or stub of the principle and
John> credential objects and put them into session. However,
John> the setPrincipal method is not exposed in the standard HttpSession api,
John> and the implemented sessionObject is not visible.

I'm not sure how StrutsTestCase work with Cactus, however,
you might try use CactusStrutsTestCase instead of MockStrutsTestCase
as described at URL you mentioned.

The authentication mechanism provided by Cactus may helps you.
See also: http://jakarta.apache.org/cactus/writing/howto_security.html

Regards,
----
Kazuhito SUGURI
mailto:suguri.kazuhito@lab.ntt.co.jp