use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderSecurityTest method mountOrAndMixed.
@Test
public void mountOrAndMixed(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
loadBuilderAndStartServer(vertx, SECURITY_TESTS, testContext, routerBuilder -> {
routerBuilder.setOptions(FACTORY_OPTIONS);
routerBuilder.operation("listPetsOrAndSecurity").handler(routingContext -> routingContext.response().setStatusCode(200).setStatusMessage(concatenateRoutingContextEntries(routingContext, "api_key", "second_api_key", "sibling_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("sibling_second_api_key", mockSuccessfulAuthHandler(routingContext -> routingContext.put("sibling_second_api_key", "3")));
routerBuilder.securityHandler("third_api_key", mockFailingAuthHandler(routingContext -> routingContext.put("third_api_key", "4")));
}).onComplete(h -> testRequest(client, HttpMethod.GET, "/pets_or_and_security").expect(statusCode(200), statusMessage("1-2-3-null")).send(testContext, checkpoint));
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouterBuilderSecurityTest 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 RouteToEBServiceHandlerTest method authorizedUserTest.
@Test
public void authorizedUserTest(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
TestService service = new TestServiceImpl(vertx);
final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress");
consumer = serviceBinder.register(TestService.class, service);
router.get("/test").handler(ValidationHandler.builder(parser).build()).handler(rc -> {
// Put user mock into context
rc.setUser(User.fromName("slinkydeveloper"));
rc.next();
}).handler(RouteToEBServiceHandler.build(vertx.eventBus(), "someAddress", "testUser"));
testRequest(client, HttpMethod.GET, "/test").expect(statusCode(200), statusMessage("OK")).expect(jsonBodyResponse(new JsonObject().put("result", "Hello slinkydeveloper!"))).send(testContext, checkpoint);
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouteToEBServiceHandlerTest method authorizationPropagationTest.
@Test
public void authorizationPropagationTest(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
TestService service = new TestServiceImpl(vertx);
final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress");
consumer = serviceBinder.register(TestService.class, service);
router.get("/test").handler(ValidationHandler.builder(parser).build()).handler(rc -> {
// patch the request to include authorization header
rc.request().headers().add(HttpHeaders.AUTHORIZATION, "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
rc.next();
}).handler(RouteToEBServiceHandler.build(vertx.eventBus(), "someAddress", "testAuthorization"));
testRequest(client, HttpMethod.GET, "/test").expect(statusCode(200), statusMessage("OK")).expect(jsonBodyResponse(new JsonObject().put("result", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="))).send(testContext, checkpoint);
}
use of io.vertx.ext.web.validation.testutils.TestRequest in project vertx-web by vert-x3.
the class RouteToEBServiceHandlerTest method extraPayloadTest.
@Test
public void extraPayloadTest(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint();
TestService service = new TestServiceImpl(vertx);
final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress");
consumer = serviceBinder.register(TestService.class, service);
router.get("/test").handler(ValidationHandler.builder(parser).build()).handler(RouteToEBServiceHandler.build(vertx.eventBus(), "someAddress", "extraPayload").extraPayloadMapper(rc -> new JsonObject().put("username", "slinkydeveloper")));
testRequest(client, HttpMethod.GET, "/test").expect(statusCode(200), statusMessage("OK")).expect(jsonBodyResponse(new JsonObject().put("result", "Hello slinkydeveloper!"))).send(testContext, checkpoint);
}
Aggregations