Search in sources :

Example 11 with HttpFullResponse

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

the class TestDomainMatching method testStaticFileFromDomain1NotFoundInDomain2.

@Test
public void testStaticFileFromDomain1NotFoundInDomain2() {
    HttpFullRequest req = Requests.createGetRequest("domain2.com", "/public1/myfile");
    XFuture<HttpFullResponse> respFuture = httpsSocket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
}
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 12 with HttpFullResponse

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

the class TestOptionsCorsRouting method testPostNotInCorsMethodsResult403.

@Test
public void testPostNotInCorsMethodsResult403() {
    String accessHeaders = "Content-Type";
    HttpFullRequest req = Requests.createOptionsPreflightRequest(CorsForTwoDomains.DOMAIN1, "/content", accessHeaders, "POST");
    XFuture<HttpFullResponse> respFuture = httpsSocket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_403_FORBIDDEN);
    Header cors = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_ALLOW_METHODS);
    Assert.assertEquals("GET, PUT", cors.getValue());
    Header header = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_ALLOW_HEADERS);
    Assert.assertEquals("*", header.getValue());
    Header respDomain = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_ALLOW_ORIGIN);
    Assert.assertEquals(CorsForTwoDomains.DOMAIN1, respDomain.getValue());
    Header varyHeader = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.VARY);
    Assert.assertNull(varyHeader);
    Header allowCredsHeader = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_ALLOW_CREDENTIALS);
    Assert.assertEquals("true", allowCredsHeader.getValue());
    String expected = String.join(", ", CorsForTwoDomains.EXPOSED_RESPONSE_HEADERS);
    Header exposeHeaders = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_EXPOSE_HEADERS);
    Assert.assertEquals(expected, exposeHeaders.getValue());
}
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 13 with HttpFullResponse

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

the class TestOptionsCorsRouting method testOptionsDomain2.

@Test
public void testOptionsDomain2() {
    String accessHeaders = "Authorization, Content-Type";
    HttpFullRequest req = Requests.createOptionsPreflightRequest(CorsForTwoDomains.DOMAIN_WITH_PORT, "/content", accessHeaders, "PUT");
    XFuture<HttpFullResponse> respFuture = httpsSocket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_204_NO_CONTENT);
    Header respDomain = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_ALLOW_ORIGIN);
    Assert.assertEquals(CorsForTwoDomains.DOMAIN_WITH_PORT, respDomain.getValue());
}
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 14 with HttpFullResponse

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

the class TestOptionsCorsRouting method testBadHeadersResult403.

@Test
public void testBadHeadersResult403() {
    String fromDomain = "http://from.this.domain.com";
    String accessHeaders = "Authorization, Content-Type, NotAllowedHeader";
    HttpFullRequest req = Requests.createOptionsPreflightRequest(fromDomain, "/allDomains", accessHeaders, "POST");
    XFuture<HttpFullResponse> respFuture = httpsSocket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_403_FORBIDDEN);
    Header cors = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_ALLOW_METHODS);
    Assert.assertEquals("GET, POST", cors.getValue());
    String expected = String.join(", ", CorsForAllDomains.ALLOWED_REQUEST_HEADERS);
    Header header = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_ALLOW_HEADERS);
    Assert.assertEquals(expected.toLowerCase(), header.getValue());
    Header respDomain = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_ALLOW_ORIGIN);
    Assert.assertEquals(fromDomain, respDomain.getValue());
    Header varyHeader = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.VARY);
    Assert.assertEquals("Origin", varyHeader.getValue());
    Header allowCredsHeader = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_ALLOW_CREDENTIALS);
    Assert.assertNull(allowCredsHeader);
    Header exposeHeaders = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_EXPOSE_HEADERS);
    Assert.assertNull(exposeHeaders);
}
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 15 with HttpFullResponse

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

the class TestJsonStdFilter method testAsyncJsonPostContstraintViolation.

@Test
public void testAsyncJsonPostContstraintViolation() {
    String json = "{ `query`: null, `meta`: { `numResults`: 4 } }".replace("`", "\"");
    HttpFullRequest req = Requests.createJsonRequest(KnownHttpMethod.POST, "/json/async/45", json);
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_400_BADREQUEST);
    response.assertContains("{`error`:`Your request is bad. Violation #1:'must not be blank' path=request.testValidation`,`code`:400}".replace("`", "\""));
    response.assertContentType("application/json");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

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