Search in sources :

Example 6 with KnotxConfiguration

use of io.knotx.junit.rule.KnotxConfiguration 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 KnotxConfiguration

use of io.knotx.junit.rule.KnotxConfiguration 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 KnotxConfiguration

use of io.knotx.junit.rule.KnotxConfiguration 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 KnotxConfiguration

use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.

the class KnotxServerRoutingTest method whenRequestingPostLocalPathWithAlternateTransition_expectLocalApostC.

@Test
@KnotxConfiguration("test-server.json")
public void whenRequestingPostLocalPathWithAlternateTransition_expectLocalApostC(TestContext context) {
    Async async = context.async();
    createPassThroughKnot("test-splitter");
    createPassThroughKnot("test-assembler");
    createSimpleKnot("A-post-engine", "+Apost", "go-c");
    createSimpleKnot("C-engine", "+C", null);
    testPostRequest("/content/local/simple.html", resp -> {
        context.assertEquals(resp.statusCode(), HttpResponseStatus.OK.code());
        context.assertTrue(resp.getHeader(EXPECTED_RESPONSE_HEADER) != null);
        context.assertEquals(EXPECTED_XSERVER_HEADER_VALUE, resp.getHeader(EXPECTED_RESPONSE_HEADER));
        resp.bodyHandler(body -> {
            try {
                context.assertEquals(body.toString(), "local+Apost+C", "Wrong engines processed request, expected " + "local+Apost+C");
            } catch (Exception e) {
                context.fail(e);
            }
            async.complete();
        });
    });
}
Also used : Async(io.vertx.ext.unit.Async) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 10 with KnotxConfiguration

use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.

the class KnotxServerRoutingTest method whenRequestingPostGlobalPathAndActionDoRedirect_expectRedirectResponse.

@Test
@KnotxConfiguration("test-server.json")
public void whenRequestingPostGlobalPathAndActionDoRedirect_expectRedirectResponse(TestContext context) {
    Async async = context.async();
    createPassThroughKnot("test-splitter");
    createPassThroughKnot("test-assembler");
    createSimpleFailingKnot("A-post-engine", HttpResponseStatus.MOVED_PERMANENTLY.code(), MultiMap.caseInsensitiveMultiMap().add("location", "/content/failed.html"));
    testPostRequest("/content/local/simple.html", resp -> {
        context.assertEquals(resp.statusCode(), HttpResponseStatus.MOVED_PERMANENTLY.code());
        context.assertEquals(resp.getHeader("location"), "/content/failed.html");
        context.assertTrue(resp.getHeader(EXPECTED_RESPONSE_HEADER) != null);
        context.assertEquals(EXPECTED_XSERVER_HEADER_VALUE, resp.getHeader(EXPECTED_RESPONSE_HEADER));
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Aggregations

KnotxConfiguration (io.knotx.junit.rule.KnotxConfiguration)22 Test (org.junit.Test)22 Async (io.vertx.ext.unit.Async)14 MultiMap (io.vertx.reactivex.core.MultiMap)9 WebClient (io.vertx.reactivex.ext.web.client.WebClient)9 KnotContext (io.knotx.dataobjects.KnotContext)8 Logback (io.knotx.junit.rule.Logback)6 TestVertxDeployer (io.knotx.junit.rule.TestVertxDeployer)6 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)6 JsonObject (io.vertx.core.json.JsonObject)6 TestContext (io.vertx.ext.unit.TestContext)6 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)6 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)6 Vertx (io.vertx.reactivex.core.Vertx)6 List (java.util.List)6 Rule (org.junit.Rule)6 RuleChain (org.junit.rules.RuleChain)6 RunWith (org.junit.runner.RunWith)6 Lists (com.google.common.collect.Lists)5 UnsupportedServiceException (io.knotx.adapter.common.exception.UnsupportedServiceException)5