andreea...@googlemail.com
unread,May 5, 2014, 8:50:03 AM5/5/14You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I am using HTTP Unit for testing my authorization framework.
I have problems when I try to test the cases after the Log-in, because the tests always check the first returned status codes. When someone who is not authenticated tries to access a protected resource, the first status code is 401, he has the chance to provide his credentials and after log-in the status code is 200.
How can I program the test to perform the authentication and wait for the last status code?
This is how I did it until now. It failes, because the first status code is 401 and not 200. Is there a keep alive option?
@Test
public void testReqRestrictedResourceWithValidRole() throws Exception
{
// Request a protected page with valid credentials and valid role
// protectedUrl requires role ADMIN
// user has role ADMIN
String username = "user";
String password = "password";
String decUserPass = username + ":" + password;
String base64encUserPass =
DatatypeConverter.printBase64Binary(decUserPass.getBytes());
webClient.addRequestHeader("Authorization", "Basic " + base64encUserPass);
Page page = webClient.getPage(protectedUrl);
int statuscode = page.getWebResponse().getStatusCode();
assertEquals(statuscode, 200, "Wrong statuscode.");
}
Thanks!