Search in sources :

Example 16 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class FormAuthUnitTestCase method testPostDataFormAuth.

/**
     * Test that a post from an unsecured form to a secured servlet does not
     * loose its data during the redirect to the form login.
     */
@Test
@OperateOnDeployment("form-auth.war")
public void testPostDataFormAuth() throws Exception {
    log.trace("+++ testPostDataFormAuth");
    URL url = new URL(baseURLNoAuth + "unsecure_form.html");
    HttpGet httpget = new HttpGet(url.toURI());
    log.trace("Executing request " + httpget.getRequestLine());
    HttpResponse response = httpclient.execute(httpget);
    int statusCode = response.getStatusLine().getStatusCode();
    Header[] errorHeaders = response.getHeaders("X-NoJException");
    assertTrue("Wrong response code: " + statusCode, statusCode == HttpURLConnection.HTTP_OK);
    assertTrue("X-NoJException(" + Arrays.toString(errorHeaders) + ") is null", errorHeaders.length == 0);
    EntityUtils.consume(response.getEntity());
    // Submit the form to /restricted/SecuredPostServlet
    HttpPost restrictedPost = new HttpPost(baseURLNoAuth + "restricted/SecuredPostServlet");
    List<NameValuePair> restrictedParams = new ArrayList<NameValuePair>();
    restrictedParams.add(new BasicNameValuePair("checkParam", "123456"));
    restrictedPost.setEntity(new UrlEncodedFormEntity(restrictedParams, "UTF-8"));
    log.trace("Executing request " + restrictedPost.getRequestLine());
    HttpResponse restrictedResponse = httpclient.execute(restrictedPost);
    statusCode = restrictedResponse.getStatusLine().getStatusCode();
    errorHeaders = restrictedResponse.getHeaders("X-NoJException");
    assertTrue("Wrong response code: " + statusCode, statusCode == HttpURLConnection.HTTP_OK);
    assertTrue("X-NoJException(" + Arrays.toString(errorHeaders) + ") is null", errorHeaders.length == 0);
    HttpEntity entity = restrictedResponse.getEntity();
    if ((entity != null) && (entity.getContentLength() > 0)) {
        String body = EntityUtils.toString(entity);
        assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0);
    } else {
        fail("Empty body in response");
    }
    String sessionID = null;
    for (Cookie k : httpclient.getCookieStore().getCookies()) {
        if (k.getName().equalsIgnoreCase("JSESSIONID"))
            sessionID = k.getValue();
    }
    log.trace("Saw JSESSIONID=" + sessionID);
    // Submit the login form
    HttpPost formPost = new HttpPost(baseURLNoAuth + "j_security_check");
    formPost.addHeader("Referer", baseURLNoAuth + "restricted/login.html");
    List<NameValuePair> formparams = new ArrayList<NameValuePair>();
    formparams.add(new BasicNameValuePair("j_username", "user1"));
    formparams.add(new BasicNameValuePair("j_password", "password1"));
    formPost.setEntity(new UrlEncodedFormEntity(formparams, "UTF-8"));
    log.trace("Executing request " + formPost.getRequestLine());
    HttpResponse postResponse = httpclient.execute(formPost);
    statusCode = postResponse.getStatusLine().getStatusCode();
    errorHeaders = postResponse.getHeaders("X-NoJException");
    assertTrue("Should see HTTP_MOVED_TEMP. Got " + statusCode, statusCode == HttpURLConnection.HTTP_MOVED_TEMP);
    assertTrue("X-NoJException(" + Arrays.toString(errorHeaders) + ") is null", errorHeaders.length == 0);
    EntityUtils.consume(postResponse.getEntity());
    // Follow the redirect to the SecureServlet
    Header location = postResponse.getFirstHeader("Location");
    URL indexURI = new URL(location.getValue());
    HttpGet war1Index = new HttpGet(indexURI.toURI());
    log.trace("Executing request " + war1Index.getRequestLine());
    HttpResponse war1Response = httpclient.execute(war1Index);
    statusCode = war1Response.getStatusLine().getStatusCode();
    errorHeaders = war1Response.getHeaders("X-NoJException");
    assertTrue("Wrong response code: " + statusCode, statusCode == HttpURLConnection.HTTP_OK);
    assertTrue("X-NoJException(" + Arrays.toString(errorHeaders) + ") is null", errorHeaders.length == 0);
    HttpEntity war1Entity = war1Response.getEntity();
    if ((war1Entity != null) && (entity.getContentLength() > 0)) {
        String body = EntityUtils.toString(war1Entity);
        if (body.indexOf("j_security_check") > 0)
            fail("Get of " + indexURI + " redirected to login page");
    } else {
        fail("Empty body in response");
    }
}
Also used : Cookie(org.apache.http.cookie.Cookie) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) URL(java.net.URL) Header(org.apache.http.Header) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 17 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class RequestDumpingHandlerTestCase method testReqDumpHandlerOnWebsockets.

/**
     * Testing app has request dumper handler registered. This test checks that request dump over the Websockets is generated
     * correctly.
     */
@Test
@OperateOnDeployment(DEPLOYMENT_WS)
public void testReqDumpHandlerOnWebsockets(@ArquillianResource URL url) throws Exception {
    URI wsUri = new URI("ws", "", TestSuiteEnvironment.getServerAddress(), TestSuiteEnvironment.getHttpPort(), "/" + DEPLOYMENT_WS + "/websocket/Stuart", "", "");
    new RequestDumpingHandlerTestImpl.WsRequestDumpingHandlerTestImpl(wsUri, logFilePath, true);
}
Also used : URI(java.net.URI) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 18 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class RequestDumpingHandlerTestCase method testReqDumpHandlerOnHttps.

/**
     * Testing app has request dumper handler registered. This test checks that request dump over the HTTPS is generated
     * correctly.
     */
@Test
@OperateOnDeployment(DEPLOYMENT_DUMP)
public void testReqDumpHandlerOnHttps(@ArquillianResource URL url) throws Exception {
    URL httpsUrl = new URL("https://" + url.getHost() + ":" + HTTPS_PORT + url.getPath() + "file.txt");
    new RequestDumpingHandlerTestImpl.HttpsRequestDumpingHandlerTestImpl(httpsUrl.toURI(), logFilePath, true);
}
Also used : URL(java.net.URL) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 19 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class CustomErrorsUnitTestCase method testExceptionError.

/**
     * Test that the custom 500 error page is seen for an exception
     *
     * @throws Exception
     */
@Test
@OperateOnDeployment("error-producer.war")
public void testExceptionError(@ArquillianResource(ErrorGeneratorServlet.class) URL baseURL) throws Exception {
    URL url = new URL(baseURL + "/ErrorGeneratorServlet");
    testURL(url, HttpURLConnection.HTTP_INTERNAL_ERROR, "500.jsp", "java.lang.IllegalStateException");
}
Also used : URL(java.net.URL) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 20 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class CustomErrorsUnitTestCase method test500Error.

/**
     * Test that the custom 500 error page is seen
     *
     * @throws Exception
     */
@Test
@OperateOnDeployment("error-producer.war")
public void test500Error(@ArquillianResource(ErrorGeneratorServlet.class) URL baseURL) throws Exception {
    int errorCode = HttpURLConnection.HTTP_INTERNAL_ERROR;
    URL url = new URL(baseURL + "/ErrorGeneratorServlet?errorCode=" + errorCode);
    testURL(url, errorCode, "500.jsp", null);
}
Also used : URL(java.net.URL) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Aggregations

OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)94 Test (org.junit.Test)93 URL (java.net.URL)31 URI (java.net.URI)22 HttpGet (org.apache.http.client.methods.HttpGet)20 HttpResponse (org.apache.http.HttpResponse)17 InitialContext (javax.naming.InitialContext)15 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)13 QName (javax.xml.namespace.QName)11 Service (javax.xml.ws.Service)11 HttpEntity (org.apache.http.HttpEntity)10 Bus (org.apache.cxf.Bus)9 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)9 WrapThreadContextClassLoader (org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)9 ActAsServiceIface (org.jboss.as.test.integration.ws.wsse.trust.actas.ActAsServiceIface)6 OnBehalfOfServiceIface (org.jboss.as.test.integration.ws.wsse.trust.onbehalfof.OnBehalfOfServiceIface)6 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)5 WebConversation (com.meterware.httpunit.WebConversation)5 WebForm (com.meterware.httpunit.WebForm)5 WebRequest (com.meterware.httpunit.WebRequest)5