use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderSecurityTest method mountOrWithAllFailing.
@Test
public void mountOrWithAllFailing(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", mockFailingAuthHandler(routingContext -> routingContext.put("api_key", "1")));
routerBuilder.securityHandler("second_api_key", mockFailingAuthHandler(routingContext -> routingContext.put("second_api_key", "2")));
routerBuilder.securityHandler("third_api_key", mockFailingAuthHandler(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_or_security").expect(statusCode(401), 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 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 RouterBuilderSecurityTest 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 RouterBuilderSecurityTest method mountOrWithLastSuccessful.
@Test
public void mountOrWithLastSuccessful(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", mockFailingAuthHandler(routingContext -> routingContext.put("api_key", "1")));
routerBuilder.securityHandler("second_api_key", mockFailingAuthHandler(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-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 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));
}
Aggregations