Re: How to test protected url
Mritunjay Kumar <[email protected]> Sat, 14 Feb 2009 18:05:40 +0530
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,Now i changed code according to your suggestion, But still getting the
same exception.
My code is:
String urlToTest = "
http://localhost:9083/ApacheDS/pages/apacheDSHomePage.jsp"<http://localhost:9083/ApacheDS/pages/apacheDSHomePage.jsp>
;
WebConversation webConversation = new WebConversation();
WebRequest request = new PostMethodWebRequest(urlToTest);
WebResponse response = webConversation.getResponse(request);
String loginUrl =
"http://localhost:9083/ApacheDS/pages/loginPage.jsp"<http://localhost:9083/ApacheDS/pages/apacheDSHomePage.jsp>
request = new PostMethodWebRequest(loginUrl);
response = webConversation.getResponse(request);
assertTrue(response.getResponseCode() < 400 && response.getResponseCode()>
0);
String contextRoot = "ApacheDS";
String errorDisplayURL = "/" + contextRoot + "/pages/loginPage.jsp";
assertFalse(errorDisplayURL.equals(response.getURL().getPath()));
Still it is giving assesrtionFailed error.
Can you please elaborate or send me sample code to test a protected servlet
or url through HTTPUnit.
Regards,
Mritunjay
On Tue, Feb 10, 2009 at 7:09 PM, Russell Gold <[email protected]> wrote:
> URLs can be protected in a number of different ways. For servlets, the most
> common approach - and the one you seem to be using - causes the browser to
> be redirected to a login servlet rather than getting an authentication
> challenge. This is the expected behavior, and your test needs to fill in the
> login form and submit it in order to get to the protected url. Subsequent
> accesses should then reach the protected url without further logins.
>
>
> On Feb 10, 2009, at 6:30 AM, Mritunjay Kumar wrote:
>
> Hi,I want to test a url'
> http://localhost:9083/ApacheDS/pages/apacheDSHomePage.jsp' <http://localhost:9083/ApacheDS/pages/apacheDSHomePage.jsp> which
> is protected. Users having a role 'admin' can access this url.
>
> My testing code is something like
> String urlToTest = "
> http://localhost:9083/ApacheDS/pages/apacheDSHomePage.jsp";<http://localhost:9083/ApacheDS/pages/apacheDSHomePage.jsp>
> WebConversation webConversation = new WebConversation();
> webConversation.setAuthorization("encore1", "encore1");
> WebRequest request = new PostMethodWebRequest(urlToTest);
> WebResponse response =
> webConversation.getResponse(request);
> assertTrue(response.getResponseCode() < 400 &&
> response.getResponseCode()> 0);
> String contextRoot =
> testUtilPropertyFileReader.getPropertyValue("app.deployment.contextRoot");
> String errorDisplayURL = "/" + contextRoot + "/pages/loginPage.jsp";
> assertFalse(errorDisplayURL.equals(response.getURL().getPath()));
>
> When i execute this test assertion is failing because it is redirecting to
> '/pages/loginPage.jsp'. So my requirement is how can can test a protected
> servlet using httpunit.
>
>
> --
> Regards,
> Mritunjay
>
>
>
--
Regards,
Mritunjay
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop