Search in sources :

Example 6 with MultiMap

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();
        }
    });
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap) Async(io.vertx.ext.unit.Async) WebClient(io.vertx.reactivex.ext.web.client.WebClient) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 7 with MultiMap

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();
        }
    });
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap) Async(io.vertx.ext.unit.Async) WebClient(io.vertx.reactivex.ext.web.client.WebClient) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 8 with MultiMap

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();
        }
    });
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap) Async(io.vertx.ext.unit.Async) WebClient(io.vertx.reactivex.ext.web.client.WebClient) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 9 with MultiMap

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;
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap)

Example 10 with MultiMap

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);
}
Also used : ClientResponse(io.knotx.dataobjects.ClientResponse) MultiMap(io.vertx.reactivex.core.MultiMap) KnotContext(io.knotx.dataobjects.KnotContext)

Aggregations

MultiMap (io.vertx.reactivex.core.MultiMap)19 Async (io.vertx.ext.unit.Async)5 WebClient (io.vertx.reactivex.ext.web.client.WebClient)5 KnotxConfiguration (io.knotx.junit.rule.KnotxConfiguration)4 JsonObject (io.vertx.core.json.JsonObject)4 ClientResponse (io.knotx.dataobjects.ClientResponse)3 List (java.util.List)3 Test (org.junit.Test)3 UnsupportedServiceException (io.knotx.adapter.common.exception.UnsupportedServiceException)2 AdapterRequest (io.knotx.dataobjects.AdapterRequest)2 ClientRequest (io.knotx.dataobjects.ClientRequest)2 Single (io.reactivex.Single)2 HttpMethod (io.vertx.core.http.HttpMethod)2 Pattern (java.util.regex.Pattern)2 Lists (com.google.common.collect.Lists)1 Coercion (com.googlecode.zohhak.api.Coercion)1 TestWith (com.googlecode.zohhak.api.TestWith)1 AdapterServiceContractException (io.knotx.adapter.common.exception.AdapterServiceContractException)1 HttpAdapterConfiguration (io.knotx.adapter.common.http.HttpAdapterConfiguration)1 HttpClientFacade (io.knotx.adapter.common.http.HttpClientFacade)1