use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderSecurityWithFactoryTest method mountAndFirstOneFailing.
@Test
public void mountAndFirstOneFailing(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, SECURITY_TESTS, testContext, routerBuilder -> {
routerBuilder.setOptions(FACTORY_OPTIONS);
routerBuilder.operation("listPetsAndSecurity").handler(routingContext -> routingContext.response().setStatusCode(200).setStatusMessage(concatenateRoutingContextEntries(routingContext, "api_key", "second_api_key", "third_api_key")).end());
routerBuilder.securityHandler("api_key", mockFailingAuthHandler(routingContext -> routingContext.put("api_key", "1")));
routerBuilder.securityHandler("second_api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("second_api_key", "2")));
routerBuilder.securityHandler("third_api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("third_api_key", "3")));
}, new AbstractMap.SimpleImmutableEntry<>(401, routingContext -> routingContext.response().setStatusCode(401).setStatusMessage(concatenateRoutingContextEntries(routingContext, "api_key", "second_api_key", "third_api_key")).end())).onComplete(h -> testRequest(client, HttpMethod.GET, "/pets_and_security").expect(statusCode(401), statusMessage("1-null-null")).send(testContext, checkpoint));
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderSecurityWithFactoryTest method mountGlobalSecurityHandler.
@Test
public void mountGlobalSecurityHandler(Vertx vertx, VertxTestContext testContext) {
final Handler<RoutingContext> handler = routingContext -> {
routingContext.response().setStatusCode(200).setStatusMessage((routingContext.get("message") != null) ? routingContext.get("message") + "-OK" : "OK").end();
};
Checkpoint checkpoint = testContext.checkpoint(3);
loadBuilderAndStartServer(vertx, GLOBAL_SECURITY_TESTS, testContext, routerBuilder -> {
routerBuilder.setOptions(FACTORY_OPTIONS);
routerBuilder.operation("listPetsWithoutSecurity").handler(handler);
routerBuilder.operation("listPetsWithOverride").handler(handler);
routerBuilder.operation("listPetsWithoutOverride").handler(handler);
testContext.verify(() -> assertThatCode(routerBuilder::createRouter).isInstanceOfSatisfying(RouterBuilderException.class, rfe -> assertThat(rfe.type()).isEqualTo(ErrorType.MISSING_SECURITY_HANDLER)));
routerBuilder.securityHandler("global_api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("message", "Global")));
routerBuilder.securityHandler("api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("message", "Local")));
}).onComplete(h -> {
testRequest(client, HttpMethod.GET, "/petsWithoutSecurity").expect(statusCode(200), statusMessage("OK")).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/petsWithOverride").expect(statusCode(200), statusMessage("Local-OK")).send(testContext, checkpoint);
testRequest(client, HttpMethod.GET, "/petsWithoutOverride").expect(statusCode(200), statusMessage("Global-OK")).send(testContext, checkpoint);
});
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderSecurityWithFactoryTest method mountOrWithFirstSuccessful.
@Test
public void mountOrWithFirstSuccessful(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, SECURITY_TESTS, testContext, routerBuilder -> {
routerBuilder.setOptions(FACTORY_OPTIONS);
routerBuilder.operation("listPetsOrSecurity").handler(routingContext -> routingContext.response().setStatusCode(200).setStatusMessage(concatenateRoutingContextEntries(routingContext, "api_key", "second_api_key", "third_api_key")).end());
routerBuilder.securityHandler("api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("api_key", "1")));
routerBuilder.securityHandler("second_api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("second_api_key", "2")));
routerBuilder.securityHandler("third_api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("third_api_key", "3")));
}).onComplete(h -> testRequest(client, HttpMethod.GET, "/pets_or_security").expect(statusCode(200), statusMessage("1-null-null")).send(testContext, checkpoint));
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderSecurityWithFactoryTest method mountAnd.
@Test
public void mountAnd(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, SECURITY_TESTS, testContext, routerBuilder -> {
routerBuilder.setOptions(FACTORY_OPTIONS);
routerBuilder.operation("listPetsAndSecurity").handler(routingContext -> routingContext.response().setStatusCode(200).setStatusMessage(concatenateRoutingContextEntries(routingContext, "api_key", "second_api_key", "third_api_key")).end());
routerBuilder.securityHandler("api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("api_key", "1")));
routerBuilder.securityHandler("second_api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("second_api_key", "2")));
routerBuilder.securityHandler("third_api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("third_api_key", "3")));
}).onComplete(h -> testRequest(client, HttpMethod.GET, "/pets_and_security").expect(statusCode(200), statusMessage("1-2-3")).send(testContext, checkpoint));
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderSecurityTest method mountSingle.
@Test
public void mountSingle(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, SECURITY_TESTS, testContext, routerBuilder -> {
routerBuilder.setOptions(FACTORY_OPTIONS);
routerBuilder.operation("listPetsSingleSecurity").handler(routingContext -> routingContext.response().setStatusCode(200).setStatusMessage(concatenateRoutingContextEntries(routingContext, "api_key")).end());
routerBuilder.securityHandler("api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("api_key", "1")));
}).onComplete(h -> testRequest(client, HttpMethod.GET, "/pets_single_security").expect(statusCode(200), statusMessage("1")).send(testContext, checkpoint));
}
Aggregations