HonoBasicAuthHandler extends BasicAuthHandlerImpl implements HonoHttpAuthHandler { @Override public void parseCredentials(final RoutingContext context, final Handler<AsyncResult<JsonObject>> handler) { final RoutingContextDecorator routingContextDecorator = new RoutingContextDecorator(context.currentRoute(), context) { @Override public void fail(final Throwable throwable) { HttpUtils.badRequest(context, "Malformed authorization header"); } }; super.parseCredentials(routingContextDecorator, ar -> processParseCredentialsResult(authProvider, context, tracer, ar, handler)); } HonoBasicAuthHandler(final AuthProvider authProvider, final String realm, final Tracer tracer);  HonoBasicAuthHandler(final DeviceCredentialsAuthProvider<?> authProvider, final String realm);  HonoBasicAuthHandler(
            final DeviceCredentialsAuthProvider<?> authProvider,
            final String realm,
            final PreCredentialsValidationHandler<HttpContext> preCredentialsValidationHandler); @Override PreCredentialsValidationHandler<HttpContext> getPreCredentialsValidationHandler(); @Override void parseCredentials(final RoutingContext context, final Handler<AsyncResult<JsonObject>> handler);  }
@SuppressWarnings({ "unchecked" }) @Test public void testHandleFailsForMalformedAuthorizationHeader() { final AuthProvider authProvider = mock(AuthProvider.class); final HonoBasicAuthHandler authHandler = new HonoBasicAuthHandler(authProvider, "test", NoopTracerFactory.create()); final ArgumentCaptor<Throwable> exceptionCaptor = ArgumentCaptor.forClass(Throwable.class); final String authorization = "BASIC test test"; final MultiMap headers = mock(MultiMap.class); when(headers.get(eq(HttpHeaders.AUTHORIZATION))).thenReturn(authorization); final HttpServerRequest req = mock(HttpServerRequest.class); when(req.headers()).thenReturn(headers); final HttpServerResponse resp = mock(HttpServerResponse.class); final RoutingContext ctx = mock(RoutingContext.class); when(ctx.request()).thenReturn(req); when(ctx.response()).thenReturn(resp); when(ctx.currentRoute()).thenReturn(mock(Route.class)); authHandler.parseCredentials(ctx, mock(Handler.class)); verify(ctx).fail(exceptionCaptor.capture()); assertThat(exceptionCaptor.getValue()).isInstanceOf(ClientErrorException.class); assertThat(((ClientErrorException) exceptionCaptor.getValue()).getErrorCode()) .isEqualTo(HttpURLConnection.HTTP_BAD_REQUEST); }