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();
}
});
}
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();
}
});
}
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();
}
});
}
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();
});
});
}
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();
});
}
Aggregations