Search in sources :

Example 41 with HttpFullResponse

use of org.webpieces.httpclient11.api.HttpFullResponse in project webpieces by deanhiller.

the class TestHttps method testSecureAndLoggedInAlready.

@Test
public void testSecureAndLoggedInAlready() {
    Header cookie = simulateLogin();
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/secure/internal");
    req.addHeader(cookie);
    XFuture<HttpFullResponse> respFuture = https11Socket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    // before we can show you the page, you need to be logged in, redirect to login page...
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("This is some home page");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) Header(org.webpieces.httpparser.api.common.Header) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Example 42 with HttpFullResponse

use of org.webpieces.httpclient11.api.HttpFullResponse in project webpieces by deanhiller.

the class TestHttps method testSameRouteHttpAndHttpsCorrectOrder.

@Test
public void testSameRouteHttpAndHttpsCorrectOrder() {
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/same2");
    XFuture<HttpFullResponse> respFuture1 = https11Socket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture1);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("Https Route");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("Http Route");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Example 43 with HttpFullResponse

use of org.webpieces.httpclient11.api.HttpFullResponse in project webpieces by deanhiller.

the class TestGetCorsRouting method testOptionsDomain2.

@Test
public void testOptionsDomain2() {
    List<String> accessHeaders = List.of("Authorization", "qwerewr");
    HttpFullRequest req = Requests.createCorsRequest(CorsForTwoDomains.DOMAIN_WITH_PORT, "/content", accessHeaders, KnownHttpMethod.PUT);
    XFuture<HttpFullResponse> respFuture = httpsSocket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    Header respDomain = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_ALLOW_ORIGIN);
    Assert.assertEquals(CorsForTwoDomains.DOMAIN_WITH_PORT, respDomain.getValue());
    // must tell client since there are two domains, the respond of Origin header may vary(ie. don't cache it)
    Header vary = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.VARY);
    Assert.assertNull(vary);
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) Header(org.webpieces.httpparser.api.common.Header) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Example 44 with HttpFullResponse

use of org.webpieces.httpclient11.api.HttpFullResponse in project webpieces by deanhiller.

the class TestGetCorsRouting method testPassingCookieAllHeadersAllowedIs403IfCredsDisallowed.

@Test
public void testPassingCookieAllHeadersAllowedIs403IfCredsDisallowed() {
    String cookieValue = "key1=value1;key2=value2";
    List<String> accessHeaders = List.of("Authorization", "asfsf");
    HttpFullRequest req = Requests.createCorsRequestCookie(CorsForTwoDomains.DOMAIN1, "/cookie", accessHeaders, KnownHttpMethod.GET, cookieValue);
    XFuture<HttpFullResponse> respFuture = httpsSocket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_403_FORBIDDEN);
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Example 45 with HttpFullResponse

use of org.webpieces.httpclient11.api.HttpFullResponse in project webpieces by deanhiller.

the class TestBootstrapTag method testBootstrap.

@Test
public void testBootstrap() {
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/bootstrap");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("$(`#editLink_2`).click(function(e){".replaceAll("`", "\""));
    response.assertContains("$('#addEditModal').load('/user/2', function(response, status, xhr){");
    response.assertContains("$(`#editLink_4`).click(function(e){".replaceAll("`", "\""));
    response.assertContains("$('#addEditModal').load('/user/2', function(response, status, xhr){");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Aggregations

HttpFullResponse (org.webpieces.httpclient11.api.HttpFullResponse)208 HttpFullRequest (org.webpieces.httpclient11.api.HttpFullRequest)204 ResponseWrapper (org.webpieces.webserver.test.ResponseWrapper)200 Test (org.junit.Test)192 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)192 PrivateWebserverForTest (org.webpieces.webserver.PrivateWebserverForTest)178 Header (org.webpieces.httpparser.api.common.Header)39 XFuture (org.webpieces.util.futures.XFuture)12 WebserverForTest (org.webpieces.plugins.fortesting.WebserverForTest)8 URL (java.net.URL)3 UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)3 UserDto (org.webpieces.webserver.basic.app.biz.UserDto)3 URI (java.net.URI)2 DataWrapper (org.webpieces.data.api.DataWrapper)2 NotFoundException (org.webpieces.http.exception.NotFoundException)2 HttpData (org.webpieces.httpparser.api.dto.HttpData)2 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)2 AcmeInfo (org.webpieces.plugin.secure.sslcert.acme.AcmeInfo)2 SearchRequest (org.webpieces.webserver.json.app.SearchRequest)2 FetchValueResponse (webpiecesxxxxxpackage.service.FetchValueResponse)2