use of org.webpieces.httpclient11.api.HttpFullRequest 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);
}
use of org.webpieces.httpclient11.api.HttpFullRequest 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());
}
use of org.webpieces.httpclient11.api.HttpFullRequest 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());
}
use of org.webpieces.httpclient11.api.HttpFullRequest 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);
}
use of org.webpieces.httpclient11.api.HttpFullRequest 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");
}
Aggregations