Search in sources :

Example 1 with WebForm

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

the class AbstractBasicFederationTestCase method testFederationWithLocalLogout.

@Test
public void testFederationWithLocalLogout() throws Exception {
    WebConversation conversation = new WebConversation();
    HttpUnitOptions.setLoggingHttpHeaders(true);
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider1));
    WebRequest request = new GetMethodWebRequest(formatUrl(this.serviceProvider1));
    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)));
    // local logout from serviceProvider2
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider2) + LOCAL_LOGOUT_URL_PARAM);
    response = conversation.getResponse(formatUrl(this.serviceProvider2) + LOCAL_LOGOUT_URL_PARAM);
    LOGGER.trace("LLO response(" + this.serviceProvider2 + "):" + response.getText());
    assertTrue("cannot reach locally logged out page", response.getText().contains("Logout"));
    // check if it was really LLO
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider1));
    request = new GetMethodWebRequest(formatUrl(this.serviceProvider1));
    response = conversation.getResponse(request);
    LOGGER.trace("RESPONSE: " + response.getText());
    assertTrue("cannot reach protected content at " + formatUrl(this.serviceProvider1), response.getText().contains("Welcome to " + formatContextPath(this.serviceProvider1)));
    // LLO from serviceProvider1
    LOGGER.trace("REQEST: " + formatUrl(this.serviceProvider1) + LOCAL_LOGOUT_URL_PARAM);
    response = conversation.getResponse(formatUrl(this.serviceProvider1) + LOCAL_LOGOUT_URL_PARAM);
    LOGGER.trace("LLO response(" + this.serviceProvider1 + "):" + response.getText());
    assertTrue("cannot reach locally logged out page", response.getText().contains("Logout"));
}
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 2 with WebForm

use of com.meterware.httpunit.WebForm 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 3 with WebForm

use of com.meterware.httpunit.WebForm 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 4 with WebForm

use of com.meterware.httpunit.WebForm 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 5 with WebForm

use of com.meterware.httpunit.WebForm 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)

Aggregations

GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)7 WebConversation (com.meterware.httpunit.WebConversation)7 WebForm (com.meterware.httpunit.WebForm)7 WebRequest (com.meterware.httpunit.WebRequest)7 WebResponse (com.meterware.httpunit.WebResponse)7 Test (org.junit.Test)7 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5 WebLink (com.meterware.httpunit.WebLink)1 Ignore (org.junit.Ignore)1