Search in sources :

Example 21 with WebConversation

use of com.meterware.httpunit.WebConversation in project wildfly by wildfly.

the class AbstractBasicFederationTestCase method testFederationWithGlobalLogout.

@Test
public void testFederationWithGlobalLogout() throws Exception {
    WebConversation conversation = new WebConversation();
    HttpUnitOptions.setLoggingHttpHeaders(true);
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider1) + "/index.jsp");
    WebRequest request = new GetMethodWebRequest(formatUrl(this.serviceProvider1) + "/index.jsp");
    WebResponse response = conversation.getResponse(request);
    LOGGER.trace("RESPONSE: " + response.getText());
    assertTrue(response.getURL().getPath().startsWith("/idp"));
    assertEquals(1, response.getForms().length);
    WebForm webForm = response.getForms()[0];
    webForm.setParameter("j_username", "tomcat");
    webForm.setParameter("j_password", "tomcat");
    webForm.getSubmitButtons()[0].click();
    response = conversation.getCurrentPage();
    assertTrue("cannot reach protected content at " + formatUrl(this.serviceProvider1), response.getText().contains("Welcome to " + formatContextPath(this.serviceProvider1)));
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider2));
    request = new GetMethodWebRequest(formatUrl(this.serviceProvider2));
    response = conversation.getResponse(request);
    LOGGER.trace("RESPONSE: " + response.getText());
    assertTrue("cannot reach protected content at " + formatUrl(this.serviceProvider2), response.getText().contains("Welcome to " + formatContextPath(this.serviceProvider2)));
    if (performGlobalLogout()) {
        // global logout from serviceProvider2
        LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider2) + GLOBAL_LOGOUT_URL_PARAM);
        response = conversation.getResponse(formatUrl(this.serviceProvider2) + GLOBAL_LOGOUT_URL_PARAM);
        LOGGER.trace("GLO response(" + this.serviceProvider2 + "):" + response.getText());
        assertTrue("cannot reach logged out page", response.getText().contains("Logout"));
        // check if GLO was successful, so serviceProvider1 is requesting IDP login form
        LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider1));
        request = new GetMethodWebRequest(formatUrl(this.serviceProvider1));
        response = conversation.getResponse(request);
        LOGGER.trace("RESPONSE: " + response.getText());
        assertTrue("cannot reach IDP", response.getURL().getPath().startsWith("/idp"));
        assertEquals("no form present on supposed IDP login page", 1, response.getForms().length);
    }
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebForm(com.meterware.httpunit.WebForm) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 22 with WebConversation

use of com.meterware.httpunit.WebConversation in project wildfly by wildfly.

the class RestoreOriginalRequestTestCase method testPostOriginalRequest.

@Test
@OperateOnDeployment("service-provider-2")
public void testPostOriginalRequest(@ArquillianResource URL serviceProvider2) throws Exception {
    WebRequest request = new GetMethodWebRequest(formatUrl(serviceProvider2) + "/savedRequest/savedRequest.html");
    WebConversation conversation = new WebConversation();
    WebResponse response = conversation.getResponse(request);
    WebForm webForm = response.getForms()[0];
    webForm.setParameter("j_username", "tomcat");
    webForm.setParameter("j_password", "tomcat");
    webForm.getSubmitButtons()[0].click();
    response = conversation.getCurrentPage();
    assertTrue(response.getText().contains("Back to the original requested resource."));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebConversation(com.meterware.httpunit.WebConversation) WebForm(com.meterware.httpunit.WebForm) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 23 with WebConversation

use of com.meterware.httpunit.WebConversation in project wildfly by wildfly.

the class SAMLIDPInitiatedTestCase method testAuthentication.

@Ignore("wait for PL > 2.6.0.CR2")
@Test
@OperateOnDeployment("identity-provider")
public void testAuthentication(@ArquillianResource URL url) throws Exception {
    WebConversation conversation = new WebConversation();
    HttpUnitOptions.setLoggingHttpHeaders(true);
    WebRequest request = new GetMethodWebRequest(url.toString());
    WebResponse response = conversation.getResponse(request);
    assertEquals(1, response.getForms().length);
    WebForm webForm = response.getForms()[0];
    webForm.setParameter("j_username", "tomcat");
    webForm.setParameter("j_password", "tomcat");
    webForm.getSubmitButtons()[0].click();
    response = conversation.getCurrentPage();
    LOGGER.debug("Response from IDP: " + response.getText());
    LOGGER.debug("SP1-URL: " + serviceProviderPostURL);
    LOGGER.debug("webURI: " + webURI);
    WebLink link = response.getLinkWithID("service-provider-1-id");
    assertNotNull("Cannot reach link with id: service-provider-1-id", link);
    response = link.click();
    assertTrue("Not properly redirected to sp-post1.war", response.getText().contains("Welcome to sp-post1.war"));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebForm(com.meterware.httpunit.WebForm) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebLink(com.meterware.httpunit.WebLink) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with WebConversation

use of com.meterware.httpunit.WebConversation in project wildfly by wildfly.

the class SAMLIDPInitiatedTestCase method testPostOriginalRequest.

@Test
@OperateOnDeployment("identity-provider")
public void testPostOriginalRequest(@ArquillianResource URL url) throws Exception {
    WebRequest request = new GetMethodWebRequest(url.toString());
    WebConversation conversation = new WebConversation();
    WebResponse response = conversation.getResponse(request);
    WebForm webForm = response.getForms()[0];
    webForm.setParameter("j_username", "tomcat");
    webForm.setParameter("j_password", "tomcat");
    webForm.getSubmitButtons()[0].click();
    request = new GetMethodWebRequest(url + "?SAML_VERSION=2.0&TARGET=" + this.serviceProviderPostURL + "/savedRequest/savedRequest.jsp");
    response = conversation.getResponse(request);
    assertTrue(response.getText().contains("Back to the original requested resource."));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebConversation(com.meterware.httpunit.WebConversation) WebForm(com.meterware.httpunit.WebForm) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 25 with WebConversation

use of com.meterware.httpunit.WebConversation in project javaee7-samples by javaee-samples.

the class ScopedBeanTest method checkRenderedPage.

@Test
public void checkRenderedPage() throws Exception {
    WebConversation conv = new WebConversation();
    GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/faces/index.xhtml");
    String responseText = conv.getResponse(getRequest).getText();
    assert (responseText.contains("Hello there!"));
}
Also used : WebConversation(com.meterware.httpunit.WebConversation) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Aggregations

WebConversation (com.meterware.httpunit.WebConversation)44 Test (org.junit.Test)44 WebResponse (com.meterware.httpunit.WebResponse)43 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)42 WebRequest (com.meterware.httpunit.WebRequest)38 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 HttpSession (javax.servlet.http.HttpSession)9 WebForm (com.meterware.httpunit.WebForm)7 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5 AuthorizationRequiredException (com.meterware.httpunit.AuthorizationRequiredException)3 PrintWriter (java.io.PrintWriter)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 HttpException (com.meterware.httpunit.HttpException)2 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)2 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)1 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)1 WebLink (com.meterware.httpunit.WebLink)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Cookie (javax.servlet.http.Cookie)1