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 Gabe <ba...@gmail.com> on 2006/05/16 23:04:14 UTC

negative testing with FormAuthentication

Hi,

I've been setting up a cactus test to test a web application
containers login.  My test succeeds until I try a bad login.  The
FormAuthentication throws a
"org.apache.cactus.util.ChainedRuntimeException: Failed to
authenticate the principal" exception.  This is expected behavior.
The problem I can't wrap my head around is how is my test case
supposed to catch the exception?  I put try catch blocks in the
beginXXX() and in the testXXX() methods and neither catch the
exception.

Right now the exception causes an error and makes the test fail.  But
the login was supposed to fail.

How should one test and assert a failed login using Cactus?

Thanks,

Gabriel

Re: negative testing with FormAuthentication

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

In article <ec...@mail.gmail.com>,
Tue, 16 May 2006 17:04:14 -0400,
Gabe <ba...@gmail.com> wrote: 
gabriel> I've been setting up a cactus test to test a web application
gabriel> containers login.  My test succeeds until I try a bad login.  The
gabriel> FormAuthentication throws a
gabriel> "org.apache.cactus.util.ChainedRuntimeException: Failed to
gabriel> authenticate the principal" exception.  This is expected behavior.
gabriel> The problem I can't wrap my head around is how is my test case
gabriel> supposed to catch the exception?  I put try catch blocks in the
gabriel> beginXXX() and in the testXXX() methods and neither catch the
gabriel> exception.

I can understand what you want to do.
However, you can not do it that way.

The WebRequest instance is a container that maintains instructions
to set the pre-test condition that should be tuned befor
the testXXX() method is executed.
After your begin() and beginXXX() methods provide the WebRequest instance,
the client-side of the Cactus framework uses it to set the server-side
pre-test condition for testXXX(). This means that the authentication
would be performed AFTER the beginXXX() method.
This is why you cannot catch the exception.


gabriel> Right now the exception causes an error and makes the test fail.  But
gabriel> the login was supposed to fail.
gabriel> 
gabriel> How should one test and assert a failed login using Cactus?

HttpUnit or other functional testing frameworks would be appropriated.

To test a failed login situation in Cactus world, you should consider
how the behavior of the container is different between
a request not authenticated and a request that failed to authenticate.
# For unit testing, both may be considered as same, but I'm not sure.
## It may be depending on the container implementation.


Regards,
----
Kazuhito SUGURI

Re: negative testing with FormAuthentication

Posted by Gabe <ba...@gmail.com>.
Sorry, don't user cobertura.  Wish I could be of help.

On 5/24/06, Ryan <gi...@strose.edu> wrote:
> Gabe,
>
> I am sorry I can't answer your question.  I don't understand why a Try/Catch
> wouldn't cath the exception.  However, I have a question for you...
>
> Are you using any code coverage tools with your test? If so, are you using
> Cobertura?  If not, need not to respond.
>
> Thanks and sorry,
>
> Ryan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>
>

Re: negative testing with FormAuthentication

Posted by Ryan <gi...@strose.edu>.
Gabe, 

I am sorry I can't answer your question.  I don't understand why a Try/Catch
wouldn't cath the exception.  However, I have a question for you...

Are you using any code coverage tools with your test? If so, are you using
Cobertura?  If not, need not to respond.

Thanks and sorry,

Ryan