Skip to content

Commit

Permalink
Change test to not rely on text in the error pages
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored and kabir committed Apr 4, 2013
1 parent b0a19b7 commit 1fbf1ef
Showing 1 changed file with 21 additions and 18 deletions.
Expand Up @@ -62,7 +62,7 @@ public static Archive<?> deployment() {
.addAsResource(EJBEndpointSecuredWSDLAccessTestCase.class.getPackage(), "users.properties", "users.properties")
.addAsResource(EJBEndpointSecuredWSDLAccessTestCase.class.getPackage(), "roles.properties", "roles.properties")
.addClasses(EJBEndpointIface.class, EJBEndpointSecuredWSDLAccess.class);

return jar;
}

Expand All @@ -80,63 +80,66 @@ public void createService() throws Exception {
// failure is expected
}
}


@Test
public void accessWSDLWithValidUsernameAndPassord() throws Exception {
URL wsdlURL = new URL(baseUrl, "/jaxws-authentication-ejb3-for-wsdl/EJB3ServiceForWSDL?wsdl");
String encoding = Base64Encoder.encode("user1:password1");

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(wsdlURL.toString());
httpget.setHeader("Authorization", "Basic " + encoding);
HttpResponse response = httpclient.execute(httpget);

String text = Utils.getContent(response);
Assert.assertTrue("Response doesn't contain wsdl file", text.contains("wsdl:binding"));

}

@Test
public void accessWSDLWithValidUsernameAndPassordButInvalidRole() throws Exception {
URL wsdlURL = new URL(baseUrl, "/jaxws-authentication-ejb3-for-wsdl/EJB3ServiceForWSDL?wsdl");
String encoding = Base64Encoder.encode("user2:password2");

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(wsdlURL.toString());
httpget.setHeader("Authorization", "Basic " + encoding);
HttpResponse response = httpclient.execute(httpget);
Assert.assertEquals(403, response.getStatusLine().getStatusCode());

Utils.getContent(response);
//Assert.assertTrue("Response doesn't contain access denied message", text.contains("Access to the requested resource has been denied"));

String text = Utils.getContent(response);
Assert.assertTrue("Response doesn't contain access denied message", text.contains("Access to the requested resource has been denied"));

}

@Test
public void accessWSDLWithInvalidUsernameAndPassord() throws Exception {
URL wsdlURL = new URL(baseUrl, "/jaxws-authentication-ejb3-for-wsdl/EJB3ServiceForWSDL?wsdl");
String encoding = Base64Encoder.encode("user1:password-XZY");

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(wsdlURL.toString());
httpget.setHeader("Authorization", "Basic " + encoding);
HttpResponse response = httpclient.execute(httpget);
Assert.assertEquals(401, response.getStatusLine().getStatusCode());

String text = Utils.getContent(response);
Assert.assertTrue("Response doesn't contain expected message.", text.contains("This request requires HTTP authentication"));
Utils.getContent(response);
//Assert.assertTrue("Response doesn't contain expected message.", text.contains("This request requires HTTP authentication"));
}

@Test
public void accessWSDLWithoutUsernameAndPassord() throws Exception {
URL wsdlURL = new URL(baseUrl, "/jaxws-authentication-ejb3-for-wsdl/EJB3ServiceForWSDL?wsdl");

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(wsdlURL.toString());
HttpResponse response = httpclient.execute(httpget);
Assert.assertEquals(401, response.getStatusLine().getStatusCode());

String text = Utils.getContent(response);
Assert.assertTrue("Response doesn't contain expected message.", text.contains("This request requires HTTP authentication"));
Utils.getContent(response);
//Assert.assertTrue("Response doesn't contain expected message.", text.contains("This request requires HTTP authentication"));
}


}

0 comments on commit 1fbf1ef

Please sign in to comment.