Search in sources :

Example 26 with TestRequest

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));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Arrays(java.util.Arrays) AuthenticationHandlerImpl(io.vertx.ext.web.handler.impl.AuthenticationHandlerImpl) AuthenticationHandler(io.vertx.ext.web.handler.AuthenticationHandler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OAuth2Options(io.vertx.ext.auth.oauth2.OAuth2Options) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) Timeout(io.vertx.junit5.Timeout) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) HttpException(io.vertx.ext.web.handler.HttpException) Credentials(io.vertx.ext.auth.authentication.Credentials) Route(io.vertx.ext.web.Route) SimpleAuthenticationHandler(io.vertx.ext.web.handler.SimpleAuthenticationHandler) Vertx(io.vertx.core.Vertx) TestRequest(io.vertx.ext.web.validation.testutils.TestRequest) OAuth2AuthHandler(io.vertx.ext.web.handler.OAuth2AuthHandler) AuthenticationProvider(io.vertx.ext.auth.authentication.AuthenticationProvider) OAuth2FlowType(io.vertx.ext.auth.oauth2.OAuth2FlowType) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) AbstractMap(java.util.AbstractMap) User(io.vertx.ext.auth.User) HttpMethod(io.vertx.core.http.HttpMethod) Condition(org.assertj.core.api.Condition) Checkpoint(io.vertx.junit5.Checkpoint) OAuth2Auth(io.vertx.ext.auth.oauth2.OAuth2Auth) Handler(io.vertx.core.Handler) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

Example 27 with TestRequest

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));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Arrays(java.util.Arrays) AuthenticationHandlerImpl(io.vertx.ext.web.handler.impl.AuthenticationHandlerImpl) AuthenticationHandler(io.vertx.ext.web.handler.AuthenticationHandler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OAuth2Options(io.vertx.ext.auth.oauth2.OAuth2Options) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) Timeout(io.vertx.junit5.Timeout) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) HttpException(io.vertx.ext.web.handler.HttpException) Credentials(io.vertx.ext.auth.authentication.Credentials) Route(io.vertx.ext.web.Route) SimpleAuthenticationHandler(io.vertx.ext.web.handler.SimpleAuthenticationHandler) Vertx(io.vertx.core.Vertx) TestRequest(io.vertx.ext.web.validation.testutils.TestRequest) OAuth2AuthHandler(io.vertx.ext.web.handler.OAuth2AuthHandler) AuthenticationProvider(io.vertx.ext.auth.authentication.AuthenticationProvider) OAuth2FlowType(io.vertx.ext.auth.oauth2.OAuth2FlowType) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) AbstractMap(java.util.AbstractMap) User(io.vertx.ext.auth.User) HttpMethod(io.vertx.core.http.HttpMethod) Condition(org.assertj.core.api.Condition) Checkpoint(io.vertx.junit5.Checkpoint) OAuth2Auth(io.vertx.ext.auth.oauth2.OAuth2Auth) Handler(io.vertx.core.Handler) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

Example 28 with TestRequest

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);
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Arrays(java.util.Arrays) AuthenticationHandlerImpl(io.vertx.ext.web.handler.impl.AuthenticationHandlerImpl) AuthenticationHandler(io.vertx.ext.web.handler.AuthenticationHandler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OAuth2Options(io.vertx.ext.auth.oauth2.OAuth2Options) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) Timeout(io.vertx.junit5.Timeout) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) HttpException(io.vertx.ext.web.handler.HttpException) Credentials(io.vertx.ext.auth.authentication.Credentials) Route(io.vertx.ext.web.Route) SimpleAuthenticationHandler(io.vertx.ext.web.handler.SimpleAuthenticationHandler) Vertx(io.vertx.core.Vertx) TestRequest(io.vertx.ext.web.validation.testutils.TestRequest) OAuth2AuthHandler(io.vertx.ext.web.handler.OAuth2AuthHandler) AuthenticationProvider(io.vertx.ext.auth.authentication.AuthenticationProvider) OAuth2FlowType(io.vertx.ext.auth.oauth2.OAuth2FlowType) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) AbstractMap(java.util.AbstractMap) User(io.vertx.ext.auth.User) HttpMethod(io.vertx.core.http.HttpMethod) Condition(org.assertj.core.api.Condition) Checkpoint(io.vertx.junit5.Checkpoint) OAuth2Auth(io.vertx.ext.auth.oauth2.OAuth2Auth) Handler(io.vertx.core.Handler) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) RoutingContext(io.vertx.ext.web.RoutingContext) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

Example 29 with TestRequest

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));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Arrays(java.util.Arrays) AuthenticationHandlerImpl(io.vertx.ext.web.handler.impl.AuthenticationHandlerImpl) AuthenticationHandler(io.vertx.ext.web.handler.AuthenticationHandler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OAuth2Options(io.vertx.ext.auth.oauth2.OAuth2Options) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) Timeout(io.vertx.junit5.Timeout) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) HttpException(io.vertx.ext.web.handler.HttpException) Credentials(io.vertx.ext.auth.authentication.Credentials) Route(io.vertx.ext.web.Route) SimpleAuthenticationHandler(io.vertx.ext.web.handler.SimpleAuthenticationHandler) Vertx(io.vertx.core.Vertx) TestRequest(io.vertx.ext.web.validation.testutils.TestRequest) OAuth2AuthHandler(io.vertx.ext.web.handler.OAuth2AuthHandler) AuthenticationProvider(io.vertx.ext.auth.authentication.AuthenticationProvider) OAuth2FlowType(io.vertx.ext.auth.oauth2.OAuth2FlowType) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) AbstractMap(java.util.AbstractMap) User(io.vertx.ext.auth.User) HttpMethod(io.vertx.core.http.HttpMethod) Condition(org.assertj.core.api.Condition) Checkpoint(io.vertx.junit5.Checkpoint) OAuth2Auth(io.vertx.ext.auth.oauth2.OAuth2Auth) Handler(io.vertx.core.Handler) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

Example 30 with TestRequest

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));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Arrays(java.util.Arrays) AuthenticationHandlerImpl(io.vertx.ext.web.handler.impl.AuthenticationHandlerImpl) AuthenticationHandler(io.vertx.ext.web.handler.AuthenticationHandler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OAuth2Options(io.vertx.ext.auth.oauth2.OAuth2Options) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) Timeout(io.vertx.junit5.Timeout) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) HttpException(io.vertx.ext.web.handler.HttpException) Credentials(io.vertx.ext.auth.authentication.Credentials) Route(io.vertx.ext.web.Route) SimpleAuthenticationHandler(io.vertx.ext.web.handler.SimpleAuthenticationHandler) Vertx(io.vertx.core.Vertx) TestRequest(io.vertx.ext.web.validation.testutils.TestRequest) OAuth2AuthHandler(io.vertx.ext.web.handler.OAuth2AuthHandler) AuthenticationProvider(io.vertx.ext.auth.authentication.AuthenticationProvider) OAuth2FlowType(io.vertx.ext.auth.oauth2.OAuth2FlowType) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) AbstractMap(java.util.AbstractMap) User(io.vertx.ext.auth.User) HttpMethod(io.vertx.core.http.HttpMethod) Condition(org.assertj.core.api.Condition) Checkpoint(io.vertx.junit5.Checkpoint) OAuth2Auth(io.vertx.ext.auth.oauth2.OAuth2Auth) Handler(io.vertx.core.Handler) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

Aggregations

Vertx (io.vertx.core.Vertx)56 HttpMethod (io.vertx.core.http.HttpMethod)56 TestRequest (io.vertx.ext.web.validation.testutils.TestRequest)56 Checkpoint (io.vertx.junit5.Checkpoint)56 VertxTestContext (io.vertx.junit5.VertxTestContext)56 Test (org.junit.jupiter.api.Test)56 JsonObject (io.vertx.core.json.JsonObject)55 VertxExtension (io.vertx.junit5.VertxExtension)50 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)50 Future (io.vertx.core.Future)47 Timeout (io.vertx.junit5.Timeout)47 Handler (io.vertx.core.Handler)46 Route (io.vertx.ext.web.Route)46 Router (io.vertx.ext.web.Router)46 RoutingContext (io.vertx.ext.web.RoutingContext)46 Arrays (java.util.Arrays)46 Collectors (java.util.stream.Collectors)46 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)46 Condition (org.assertj.core.api.Condition)46 ArrayList (java.util.ArrayList)36