Search in sources :

Example 11 with ResponseWrapper

use of org.webpieces.webserver.test.ResponseWrapper 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 ResponseWrapper

use of org.webpieces.webserver.test.ResponseWrapper 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 ResponseWrapper

use of org.webpieces.webserver.test.ResponseWrapper 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 ResponseWrapper

use of org.webpieces.webserver.test.ResponseWrapper 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 ResponseWrapper

use of org.webpieces.webserver.test.ResponseWrapper 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

ResponseWrapper (org.webpieces.webserver.test.ResponseWrapper)209 HttpFullRequest (org.webpieces.httpclient11.api.HttpFullRequest)204 HttpFullResponse (org.webpieces.httpclient11.api.HttpFullResponse)200 Test (org.junit.Test)189 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)189 PrivateWebserverForTest (org.webpieces.webserver.PrivateWebserverForTest)174 Header (org.webpieces.httpparser.api.common.Header)39 XFuture (org.webpieces.util.futures.XFuture)11 WebserverForTest (org.webpieces.plugins.fortesting.WebserverForTest)8 UserDto (org.webpieces.webserver.basic.app.biz.UserDto)4 URL (java.net.URL)3 UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)3 URI (java.net.URI)2 DataWrapper (org.webpieces.data.api.DataWrapper)2 NotFoundException (org.webpieces.http.exception.NotFoundException)2 AcmeInfo (org.webpieces.plugin.secure.sslcert.acme.AcmeInfo)2 SearchRequest (org.webpieces.webserver.json.app.SearchRequest)2 FetchValueResponse (webpiecesxxxxxpackage.service.FetchValueResponse)2 Counter (io.micrometer.core.instrument.Counter)1 RequiredSearch (io.micrometer.core.instrument.search.RequiredSearch)1