@SuppressWarnings("unchecked") @Test public void testCredentialsValidationErrorPropagation() throws Exception { Handler<RoutingContext> handler = rc -> { fail("should not get here"); rc.response().end("Welcome to the protected resource!"); }; Throwable rootCause = new IllegalArgumentException("validation of credentials failed"); AuthProvider authProvider = mock(AuthProvider.class); doAnswer(invocation -> { final Handler<AsyncResult<User>> resultHandler = invocation.getArgument(1); resultHandler.handle(Future.failedFuture(rootCause)); return null; }).when(authProvider).authenticate(any(JsonObject.class), any(Handler.class)); router.route("/protected/*").handler(newAuthHandler(authProvider, exception -> { assertTrue(exception instanceof HttpStatusException); assertEquals(rootCause, ((HttpStatusException) exception).getCause()); })); router.route("/protected/somepage").handler(handler); testRequest(HttpMethod.GET, "/protected/somepage", 401, "Unauthorized"); } }
@SuppressWarnings("unchecked") @Test public void testCredentialsValidationErrorPropagation() throws Exception { Handler<RoutingContext> handler = rc -> { fail("should not get here"); rc.response().end("Welcome to the protected resource!"); }; Throwable rootCause = new IllegalArgumentException("validation of credentials failed"); AuthProvider authProvider = mock(AuthProvider.class); doAnswer(invocation -> { final Handler<AsyncResult<User>> resultHandler = invocation.getArgument(1); resultHandler.handle(Future.failedFuture(rootCause)); return null; }).when(authProvider).authenticate(any(JsonObject.class), any(Handler.class)); router.route("/protected/*").handler(newAuthHandler(authProvider, exception -> { assertTrue(exception instanceof HttpStatusException); assertEquals(rootCause, ((HttpStatusException) exception).getCause()); })); router.route("/protected/somepage").handler(handler); testRequest(HttpMethod.GET, "/protected/somepage", 401, "Unauthorized"); } }