use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.
the class KnotxServerCsrfTest method whenDoPostSecureWithCSRF_expectOK.
@Test
@KnotxConfiguration("test-server-csrf.json")
public void whenDoPostSecureWithCSRF_expectOK(TestContext context) {
Async async = context.async();
createPassThroughKnot("test-splitter");
createPassThroughKnot("test-assembler");
createSimpleKnot("some-knot", "test", null);
MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
WebClient client = WebClient.create(Vertx.newInstance(vertx.vertx()));
client.get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html").send(ar -> {
if (ar.succeeded()) {
String token = getToken(ar.result().cookies());
client.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html").putHeader(CSRFHandler.DEFAULT_HEADER_NAME, token).sendForm(body, res -> {
if (res.succeeded()) {
context.assertEquals(HttpResponseStatus.OK.code(), res.result().statusCode());
async.complete();
} else {
context.fail(ar.cause());
async.complete();
}
});
} else {
context.fail(ar.cause());
async.complete();
}
});
}
use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.
the class KnotxServerCsrfTest method whenDoPostSecureWithoutCSRF_expectForbidden.
@Test
@KnotxConfiguration("test-server-csrf.json")
public void whenDoPostSecureWithoutCSRF_expectForbidden(TestContext context) {
Async async = context.async();
createPassThroughKnot("test-splitter");
createPassThroughKnot("test-assembler");
createSimpleKnot("some-knot", "test", null);
MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
WebClient client = WebClient.create(Vertx.newInstance(vertx.vertx()));
client.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html").sendForm(body, ar -> {
if (ar.succeeded()) {
context.assertEquals(HttpResponseStatus.FORBIDDEN.code(), ar.result().statusCode());
async.complete();
} else {
context.fail(ar.cause());
async.complete();
}
});
}
use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.
the class KnotxServerCsrfTest method whenDoPostPublicWithoutCSRF_expectOk.
@Test
@KnotxConfiguration("test-server-csrf.json")
public void whenDoPostPublicWithoutCSRF_expectOk(TestContext context) {
Async async = context.async();
createPassThroughKnot("test-splitter");
createPassThroughKnot("test-assembler");
createSimpleKnot("some-knot", "test", null);
MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
WebClient client = WebClient.create(Vertx.newInstance(vertx.vertx()));
client.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/public.html").sendForm(body, ar -> {
if (ar.succeeded()) {
context.assertEquals(HttpResponseStatus.OK.code(), ar.result().statusCode());
async.complete();
} else {
context.fail(ar.cause());
async.complete();
}
});
}
use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.
the class ActionKnotProxyImpl method redirectKnotResponse.
private KnotContext redirectKnotResponse(KnotContext knotContext, FormEntity form, ClientResponse clientResponse, String redirectLocation) {
LOGGER.debug("Request redirected to [{}]", redirectLocation);
knotContext.getClientResponse().setStatusCode(HttpResponseStatus.MOVED_PERMANENTLY.code());
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
headers.addAll(getFilteredHeaders(clientResponse.getHeaders(), form.adapter().getAllowedResponseHeaders()));
headers.add(HttpHeaders.LOCATION.toString(), redirectLocation);
knotContext.getClientResponse().setHeaders(headers);
knotContext.clearFragments();
return knotContext;
}
use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.
the class FragmentAssemblerKnotProxyImpl method createSuccessResponse.
private KnotContext createSuccessResponse(KnotContext inputContext, String renderedContent) {
ClientResponse clientResponse = inputContext.getClientResponse();
if (StringUtils.isBlank(renderedContent)) {
clientResponse.setStatusCode(HttpResponseStatus.NO_CONTENT.code());
} else {
MultiMap headers = clientResponse.getHeaders();
headers.add(HttpHeaders.CONTENT_LENGTH.toString().toLowerCase(), Integer.toString(renderedContent.length()));
clientResponse.setBody(Buffer.buffer(renderedContent)).setHeaders(headers);
clientResponse.setStatusCode(HttpResponseStatus.OK.code());
}
return new KnotContext().setClientRequest(inputContext.getClientRequest()).setClientResponse(clientResponse);
}
Aggregations